Skip to main content

This version of GitHub Enterprise was discontinued on 2023-01-18. No patch releases will be made, even for critical security issues. For better performance, improved security, and new features, upgrade to the latest version of GitHub Enterprise. For help with the upgrade, contact GitHub Enterprise support.

Authenticating with GitHub Apps

You can authenticate as a GitHub App or as an installation.

Generating a private key

After you create a GitHub App, you'll need to generate one or more private keys. You'll use the private key to sign access token requests.

You can create multiple private keys and rotate them to prevent downtime if a key is compromised or lost. To verify that a private key matches a public key, see Verifying private keys.

To generate a private key:

  1. In the upper-right corner of any page, click your profile photo, then click Settings.

    Settings icon in the user bar

  2. In the left sidebar, click Developer settings. Developer settings

  3. In the left sidebar, click GitHub Apps. GitHub Apps section

  4. To the right of the GitHub App you want to modify, click Edit. App selection

  5. In "Private keys", click Generate a private key. Generate private key

  6. You will see a private key in PEM format downloaded to your computer. Make sure to store this file because GitHub only stores the public portion of the key.

Note: If you're using a library that requires a specific file format, the PEM file you download will be in PKCS#1 RSAPrivateKey format.

Verifying private keys

GitHub Enterprise Server generates a fingerprint for each private and public key pair using the SHA-256 hash function. You can verify that your private key matches the public key stored on GitHub Enterprise Server by generating the fingerprint of your private key and comparing it to the fingerprint shown on GitHub Enterprise Server.

To verify a private key:

  1. Find the fingerprint for the private and public key pair you want to verify in the "Private keys" section of your GitHub App's developer settings page. For more information, see Generating a private key. Private key fingerprint
  2. Generate the fingerprint of your private key (PEM) locally by using the following command:
    $ openssl rsa -in PATH_TO_PEM_FILE -pubout -outform DER | openssl sha256 -binary | openssl base64
  3. Compare the results of the locally generated fingerprint to the fingerprint you see in GitHub Enterprise Server.

Deleting private keys

You can remove a lost or compromised private key by deleting it, but you must have at least one private key. When you only have one key, you will need to generate a new one before deleting the old one. Deleting last private key

Authenticating as a GitHub App

Authenticating as a GitHub App lets you do a couple of things:

  • You can retrieve high-level management information about your GitHub App.
  • You can request access tokens for an installation of the app.

To authenticate as a GitHub App, generate a private key in PEM format and download it to your local machine. You'll use this key to sign a JSON Web Token (JWT) and encode it using the RS256 algorithm. GitHub Enterprise Server checks that the request is authenticated by verifying the token with the app's stored public key.

Generating a Json Web Token (JWT)

Using Ruby

Here's a Ruby script you can use to generate a JWT. Note you'll have to run gem install jwt before using it. YOUR_PATH_TO_PEM and YOUR_APP_ID are the values you must replace. Make sure to enclose the values in double quotes.

require 'openssl'
require 'jwt'  #

# Private key contents
private_pem ="YOUR_PATH_TO_PEM")
private_key =

# Generate the JWT
payload = {
  # issued at time, 60 seconds in the past to allow for clock drift
  iat: - 60,
  # JWT expiration time (10 minute maximum)
  exp: + (10 * 60),
  # GitHub App's identifier
  iss: "YOUR_APP_ID"

jwt = JWT.encode(payload, private_key, "RS256")
puts jwt

Using Python

Here is a similar script for generating a JWT in Python. Note you will have to use pip install jwt in order to use this script. This script will prompt you for the location of your PEM file and your app's ID, or you can pass them as inline arguments when you execute the script.

#!/usr/bin/env python3
import jwt
import time 
import sys

# Get PEM file path
if len(sys.argv) > 1:
    pem = sys.argv[1]
    pem = input("Enter path of private PEM file: ")    

# Get the App ID
if len(sys.argv) > 2:
    app_id = sys.argv[2]
    app_id = input("Enter your APP ID: ") 

# Open PEM
with open(pem, 'rb') as pem_file:
    signing_key = jwt.jwk_from_pem(
payload = {
    # Issued at time
    'iat': int(time.time()),
    # JWT expiration time (10 minutes maximum)
    'exp': int(time.time()) + 600, 
    # GitHub App's identifier
    'iss': app_id 
# Create JWT
jwt_instance = jwt.JWT()
encoded_jwt = jwt_instance.encode(payload, signing_key, alg='RS256')
print(f"JWT:  ", encoded_jwt)

Use your GitHub App's identifier (YOUR_APP_ID) as the value for the JWT iss (issuer) claim. You can obtain the GitHub App identifier via the initial webhook ping after creating the app, or at any time from the app settings page in the UI.

After creating the JWT, set it in the Header of the API request:

$ curl -i -H "Authorization: Bearer YOUR_JWT" -H "Accept: application/vnd.github+json" http(s)://HOSTNAME/api/v3/app

YOUR_JWT is the value you must replace.

The examples above uses the maximum expiration time of 10 minutes, after which the API will start returning a 401 error:

  "message": "'Expiration' claim ('exp') must be a numeric value representing the future time at which the assertion expires.",
  "documentation_url": ""

You'll need to create a new JWT after the time expires.

Accessing API endpoints as a GitHub App

For a list of REST API endpoints you can use to get high-level information about a GitHub App, see "GitHub Apps."

Authenticating as an installation

Authenticating as an installation lets you perform actions in the API for that installation. Before authenticating as an installation, you must create an installation access token. Ensure that you have already installed your GitHub App to at least one repository; it is impossible to create an installation token without a single installation. These installation access tokens are used by GitHub Apps to authenticate. For more information, see "Installing GitHub Apps."

By default, installation access tokens are scoped to all the repositories that an installation can access. You can limit the scope of the installation access token to specific repositories by using the repository_ids parameter. See the Create an installation access token for an app endpoint for more details. Installation access tokens have the permissions configured by the GitHub App and expire after one hour.

To list the installations for an authenticated app, include the JWT generated above in the Authorization header in the API request:

$ curl -i -X GET \
-H "Authorization: Bearer YOUR_JWT" \
-H "Accept: application/vnd.github+json" \

The response will include a list of installations where each installation's id can be used for creating an installation access token. For more information about the response format, see "List installations for the authenticated app."

To create an installation access token, include the JWT generated above in the Authorization header in the API request and replace :installation_id with the installation's id:

$ curl -i -X POST \
-H "Authorization: Bearer YOUR_JWT" \
-H "Accept: application/vnd.github+json" \

The response will include your installation access token, the expiration date, the token's permissions, and the repositories that the token can access. For more information about the response format, see the Create an installation access token for an app endpoint.

To authenticate with an installation access token, include it in the Authorization header in the API request:

$ curl -i \
-H "Accept: application/vnd.github+json" \

YOUR_INSTALLATION_ACCESS_TOKEN is the value you must replace.

Note: In most cases, you can use Authorization: Bearer or Authorization: token to pass a token. However, if you are passing a JSON web token (JWT), you must use Authorization: Bearer.

Accessing API endpoints as an installation

For a list of REST API endpoints that are available for use by GitHub Apps using an installation access token, see "Available Endpoints."

For a list of endpoints related to installations, see "Installations."

HTTP-based Git access by an installation

Installations with permissions on contents of a repository, can use their installation access tokens to authenticate for Git access. Use the installation access token as the HTTP password:

git clone https://x-access-token:<token>