|
1 | 1 | # github-access-using-githubapp
|
2 |
| -github-access-using-githubapp |
3 | 2 |
|
4 | 3 | Once your GitHub App is installed on an account, you can make it authenticate as an app installation for API requests.
|
5 | 4 | This allows the app to access resources owned by that installation, as long as the app was granted the necessary repository access and permissions.
|
6 | 5 | API requests made by an app installation are attributed to the app.
|
7 | 6 |
|
8 |
| -:pushpin: This action will help in creating github app installation token for both **user accounts** and **Github organizations** |
| 7 | +:pushpin: This action will help in creating GitHub app installation token for both **user accounts** and **Github organizations** |
| 8 | + |
| 9 | +> [!IMPORTANT] |
| 10 | +> An installation access token expires after 1 hour. Please find suitable alternative approaches if you have long-running processes.. |
9 | 11 |
|
10 | 12 | # Parameters of action
|
11 |
| -| Parameter name | Description | Required | |
12 |
| -|----------------|-------------|--------------------| |
13 |
| -| github_app_private_key | Github App Private key | :heavy_check_mark: | |
14 |
| -| github_app_id | Your GitHub App ID | :heavy_check_mark: | |
15 |
| -| github_account_type | Github account whether `user` account or `organization` | :heavy_check_mark: | |
| 13 | +| Parameter name | Description | Required | |
| 14 | +|----------------|----------------------------------------------------------------------------------------------------------------|-------------------| |
| 15 | +| github_app_private_key | Github App Private key | :heavy_check_mark: | |
| 16 | +| github_app_id | Your GitHub App ID | :heavy_check_mark: | |
| 17 | +| owner | Github account owner name. if not specified takes owner of current repository where action is ran | ❌ | |
| 18 | +| repositories | List of github repositores to generte token for. if not specified takes current repository where action is ran. | ❌ | |
| 19 | + |
| 20 | +* Store your `Github App Id` and `Github App Private key` as github secret and pass the secret names as inputs for action. |
16 | 21 |
|
17 |
| -* Store your `Github App Id` and `Github App Private key` as github secret and pass the secret names as inuts for action. |
| 22 | +* ❌ 👉 Means optional values |
| 23 | + |
| 24 | +> [!NOTE] |
| 25 | +> If the owner is set but repositories are empty, access will include all repositories for that owner. |
| 26 | +> If both the owner and repositories are empty, access will be limited to the current repository. |
18 | 27 |
|
19 | 28 | # What's New
|
20 | 29 |
|
21 | 30 | Please refer to the [release](https://github.com/githubofkrishnadhas/github-access-using-githubapp/releases) page for the latest release notes.
|
22 | 31 |
|
23 |
| -# Usage |
| 32 | +# Usage |
24 | 33 | ```commandline
|
25 |
| -- uses: githubofkrishnadhas/github-access-using-githubapp@v1 |
| 34 | +- uses: githubofkrishnadhas/github-access-using-githubapp@v2 |
| 35 | + id: token-generation |
26 | 36 | with:
|
27 | 37 | # Your GitHub App ID - interger value
|
28 | 38 | github_app_id: 1234567
|
29 | 39 |
|
30 |
| - # Github App Private key |
| 40 | + # GitHub App Private key |
31 | 41 | github_app_private_key : ''
|
32 | 42 |
|
33 |
| - # Gituhb account type `user` or `organization` only |
34 |
| - github_account_type: '' |
| 43 | + # GitHub account Owner name - Optional |
| 44 | + owner: '' |
| 45 | + |
| 46 | + # GitHub repositories names seperated by comma if more than 1 - optional |
| 47 | + repositories: '' |
35 | 48 | ```
|
36 | 49 |
|
37 | 50 | # output
|
38 | 51 |
|
39 |
| -The token generated will be available as a Environment variable `GH_APP_TOKEN` which can be used while running api calls |
| 52 | +* The token generated will be available as a ${{ steps.token-generation.outputs.token }} which can be used in later stages as required |
| 53 | + |
| 54 | +# Example usages |
| 55 | + |
| 56 | +## Create a token for the current repository |
| 57 | + |
| 58 | +```commandline |
| 59 | +uses: githubofkrishnadhas/github-access-using-githubapp@v2 |
| 60 | + id: token-generation |
| 61 | + with: |
| 62 | + github_app_id: ${{ secrets.APP_ID }} |
| 63 | + github_app_private_key : ${{ secrets.PRIVATE_KEY }} |
| 64 | +``` |
| 65 | +* To create a Token in the scope of current repository where action is run, you do not need to specify `owner` or `repositores` |
| 66 | +* Assuming both GitHub App ID and Private key are present as github secrets with names `APP_ID` and `PRIVATE_KEY` |
| 67 | +* You can substitute your secrets names with above |
| 68 | +* The token generated will be available as a ${{ steps.token-generation.outputs.token }} which can be used in later stages as required |
| 69 | + |
| 70 | + |
| 71 | +## Create a token for the current user or organization level |
| 72 | + |
| 73 | +```commandline |
| 74 | +uses: githubofkrishnadhas/github-access-using-githubapp@v2 |
| 75 | + id: token-generation |
| 76 | + with: |
| 77 | + github_app_id: ${{ secrets.APP_ID }} |
| 78 | + github_app_private_key : ${{ secrets.PRIVATE_KEY }} |
| 79 | + owner: 'github' |
| 80 | +``` |
| 81 | +* To create a Token in the scope of current user or organization where your Github app has access, you need only to specify `owner` |
| 82 | +* Assuming both GitHub App ID and Private key are present as github secrets with names `APP_ID` and `PRIVATE_KEY` |
| 83 | +* You can substitute your secrets names with above |
| 84 | +* The token generated will be available as a ${{ steps.token-generation.outputs.token }} which can be used in later stages as required |
| 85 | + |
| 86 | + |
| 87 | +## Create a token for a differnt user or organization scoped to specific repos |
| 88 | + |
| 89 | +```commandline |
| 90 | +uses: githubofkrishnadhas/github-access-using-githubapp@v2 |
| 91 | + id: token-generation |
| 92 | + with: |
| 93 | + github_app_id: ${{ secrets.APP_ID }} |
| 94 | + github_app_private_key : ${{ secrets.PRIVATE_KEY }} |
| 95 | + owner: 'github' |
| 96 | + repositories: 'test1,test2,test3' |
| 97 | +``` |
| 98 | +* To create a Token in the scope of provided repositories and owner where your Github app has access you need only to specify `owner` and `repositories` |
| 99 | +* The above will generate token which are scoped to repositores named `test1, test2, test3` on `github` org |
| 100 | +* Assuming both GitHub App ID and Private key are present as github secrets with names `APP_ID` and `PRIVATE_KEY` |
| 101 | +* You can substitute your secrets names with above |
| 102 | +* The token generated will be available as a ${{ steps.token-generation.outputs.token }} which can be used in later stages as required |
| 103 | + |
| 104 | + |
| 105 | +## Using the token generated with other actions |
| 106 | + |
| 107 | +```commandline |
| 108 | +name: Clone Repository |
| 109 | +
|
| 110 | +on: |
| 111 | + workflow_dispatch: |
| 112 | +
|
| 113 | +jobs: |
| 114 | + clone: |
| 115 | + runs-on: ubuntu-latest |
| 116 | +
|
| 117 | + steps: |
| 118 | +
|
| 119 | + - name: Token generator |
| 120 | + uses: githubofkrishnadhas/github-access-using-githubapp@v2 |
| 121 | + id: token-generation |
| 122 | + with: |
| 123 | + github_app_id: ${{ secrets.APP_ID }} |
| 124 | + github_app_private_key : ${{ secrets.PRIVATE_KEY }} |
| 125 | +
|
| 126 | + - name: Checkout Repository |
| 127 | + uses: actions/checkout@v4 |
| 128 | + with: |
| 129 | + repository: 'devwithkrishna/azure-terraform-modules' |
| 130 | + token: ${{ steps.token-generation.outputs.token }} |
| 131 | + fetch-depth: 1 |
| 132 | +``` |
| 133 | +* The above workflow generates a github app installation access token using the action - `githubofkrishnadhas/github-access-using-githubapp@v2` |
| 134 | +* The token generated will be available as a ${{ steps.token-generation.outputs.token }} which can be used in later stages as shown above |
| 135 | +* The workflow is to clone a repository named `azure-terraform-modules` inside `devwithkrishna` organization |
| 136 | + |
40 | 137 |
|
41 | 138 | # References
|
42 | 139 |
|
43 |
| -[generating-an-installation-access-token](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app#generating-an-installation-access-token) |
44 |
| -[get-a-user-installation-for-the-authenticated-app](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-a-user-installation-for-the-authenticated-app) |
45 |
| -[get-a-repository-installation-for-the-authenticated-app](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-a-repository-installation-for-the-authenticated-app) |
| 140 | +* [generating-an-installation-access-token](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app#generating-an-installation-access-token) |
| 141 | +* [get-a-user-installation-for-the-authenticated-app](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-a-user-installation-for-the-authenticated-app) |
| 142 | +* [get-a-repository-installation-for-the-authenticated-app](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-a-repository-installation-for-the-authenticated-app) |
46 | 143 |
|
47 | 144 | All the above API's uses [JWT](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/about-authentication-with-a-github-app#authenticating-as-a-github-app) as access token.
|
0 commit comments