How can I authenticate as an App? #5081
-
I have an app and I've created a private key: How can I use this private key to authenticate and use the cli? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 10 replies
-
No, GitHub CLI only accepts access tokens as means of authentication. You can use your App to generate an access token on behalf of a user, but you will have to do so manually, as GitHub CLI can't help with that. #5095 (comment) Alternatively, if you use |
Beta Was this translation helpful? Give feedback.
-
Here's an example of how to generate a
|
Beta Was this translation helpful? Give feedback.
-
See also https://github.com/Link-/gh-token |
Beta Was this translation helpful? Give feedback.
-
@dobesv thanks for your contribution. It got me kickstarted with authenticating against github. I made slight modifications to make it work the code around the yq commands is especially interesting: (I'm using the latest version of yq) setup-gh-app-auth() {
if [[ "${GITHUB_APP_ID}" != "" ]] && [[ -e "${GITHUB_APP_SECRET_PATH}" ]] ; then
# Create a temporary JWT for API access
GITHUB_JWT=$( jwt encode --secret "@${GITHUB_APP_SECRET_PATH}" -i "${GITHUB_APP_ID}" -e "10 minutes" --alg RS256 )
# Request installation information; note that this assumes there's just one installation (this is a private GitHub app);
# if you have multiple installations you'll have to customize this to pick out the installation you are interested in
APP_TOKEN_URL=$( curl -s -H "Authorization: Bearer ${GITHUB_JWT}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/app/installations | yq -r '.[0].access_tokens_url' )
# Now POST to the installation token URL to generate a new access token we can use to with with the gh and hub command lines
export GITHUB_TOKEN=$( curl -s -X POST -H "Authorization: Bearer ${GITHUB_JWT}" -H "Accept: application/vnd.github.v3+json" ${APP_TOKEN_URL} | yq -r '.token' )
# Configure gh as an auth provider for git so we can use git push / pull / fetch with github.com URLs
gh auth setup-git
fi
} |
Beta Was this translation helpful? Give feedback.
No, GitHub CLI only accepts access tokens as means of authentication. You can use your App to generate an access token on behalf of a user, but you will have to do so manually, as GitHub CLI can't help with that. #5095 (comment)
Alternatively, if you use
gh auth login
to authenticate GitHub CLI, it will use our own OAuth app for that. However, that will completely side-step your own App.