|
1 | 1 | # GitHub App Authentication |
2 | 2 |
|
3 | | -Inspired by https://github.com/daspn/private-actions-checkout |
| 3 | +This action allows you to authenticate as an installation of a GitHub App in your workflow. This can |
| 4 | +be a more secure way to authenticate than using a personal access token that is tied to a user |
| 5 | +account. |
| 6 | + |
| 7 | +One use case for this would be cloning a private repository in a GitHub organization outside of the |
| 8 | +repository where the workflow is running. |
| 9 | + |
| 10 | +## Inputs |
| 11 | + |
| 12 | +- `app-id` (Required) - The ID of the GitHub App that you want to authenticate as. This can be found |
| 13 | + in the settings of the GitHub App. |
| 14 | +- `private-key` (Required) - The private key of the GitHub App that you want to authenticate as. |
| 15 | + This can be generated in the settings of the GitHub App. |
| 16 | + [Learn more about private keys](https://docs.github.com/apps/building-github-apps/authentication-options-for-github-apps/#generating-a-private-key). |
| 17 | + It should start with `-----BEGIN RSA PRIVATE KEY-----` and end with |
| 18 | + `-----END RSA PRIVATE KEY-----`. |
| 19 | +- `installation-id` (Optional) - The ID of the installation of the GitHub App that you want to |
| 20 | + authenticate as. Only required if multiple installations of the GitHub App exist. |
| 21 | +- `set-git-credentials` (Optional) - If set to `true`, the action will configure the git credentials |
| 22 | + for GitHub URLs. This allows you to clone private repositories if the installation has access to |
| 23 | + them. |
| 24 | + |
| 25 | +## Outputs |
| 26 | + |
| 27 | +- `access-token` - The access token that was generated for the installation marked as a secret. I |
| 28 | + can be used in subsequent steps to authenticate as the GitHub App installation but will not be |
| 29 | + printed to the logs. The token expires after 10 minutes. |
| 30 | + |
| 31 | +## Configuration |
| 32 | + |
| 33 | +If you want to use this action to clone a private repository, you need to grant the installation read access to the repository. You can manage the access in the settings of the installation in your organization or profile settings. |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```yaml |
| 40 | +name: GitHub Actions Demo |
| 41 | +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 |
| 42 | +on: |
| 43 | + workflow_dispatch: |
| 44 | + push: |
| 45 | + branches: |
| 46 | + - main |
| 47 | +jobs: |
| 48 | + test: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + - uses: timowilhelm/github-app-authentication@v1 |
| 52 | + with: |
| 53 | + app-id: ${{ secrets.APP_ID }} |
| 54 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 55 | + set-git-credentials: true |
| 56 | + - run: | |
| 57 | + git clone https://github.com/<ORG_NAME>/<PRIVATE_REPO_NAME> |
| 58 | +``` |
| 59 | +
|
| 60 | +## Acknowledgements |
| 61 | +
|
| 62 | +Inspired by https://github.com/daspn/private-actions-checkout |
0 commit comments