CodeScan GitHub Apps Integration for GitHub Enterprise
This page provides a customer-facing overview of CodeScan GitHub Apps Integration for GitHub Enterprise and explains how to set up and configure the integration.
Prerequisites:
Creating the github app:
GitHub Apps overview - GitHub Docs
While creating the github app, make sure the check box (Request user authorization during installation) is checked under callback URL:

This allows the user to install the github app and authorize using the github app at the same time.
Set callback url as
/_codescan/oauth2/authorizeSet Repository permissions:
Content: read only
Metadata(mandatory) : read only
webhooks: Read and write
After creating the Github app, the client id, client secret and github app name env variables must be set in the task definition with the following keys:
GITHUB_APP_KEY
GITHUB_APP_SECRET
GITHUB_APP_NAME These are used to fetch the app installation token/access token that’ll be used to make github API requests and refresh the token.
User Flow:
User clicks on the github icon.
User is redirected to
/_codescan/github/authorizeBackend generates GitHub App installation URL with extra state parameter “accessType”= “github_app”
Browser redirects to Github Apps Installation page
GitHub redirects to callback URL:
/_codescan/oauth2/authorizecodeis received in paramsCall is made to
/_codescan/integrations/authorizewithcode. This code is used to fetch installation access token for the first time.
Fetching installation access token
If accessType in parameter == “github_app”, backend makes request to
https://github.com/login/oauth/access_tokenwithcode, GITHUB_APP_KEY and GITHUB_APP_SECRET to get installation access token and refresh token. This access token expires in 8 hours.If accessType is not github_app, the flow continues the same and they GITHUB_KEY and GITHUB_SECRET env variables are used.
The installation access token is stored in projectEncConfig as usual.

API call is made to get repo list with the access token.
User selects repository
Create and update project api is called with accessType=github_app
Store accessType=github_app in ProjectConfig
Connection complete - CodeScan works normally
Refresh token logic:
If projectConfig.accessType==github_app use the refresh token logic in all other cases use the existing flow.
The refresh token API can be called whenever the token is close to expiry(follow bitbucketHandler.java logic). At every API call to githubApps it can be checked if token is expired/close to expiry.
Questions:
How are multiple projects and concurrent analysis runs handled across same or different CodeScan orgs?
Since, to run an analysis and to make Github API requests, we require:
Active Installation Access token(project level)
Client ID(instance level)
Client Secret(instance level)
Hence, concurrent analysis of different projects will run without any issues.
How is authentication type (GitHub App) represented and differentiated?
By Storing accessType=oauth/github_app in ProjectConfig
Github Enterprise integration:
The Github Apps enterprise flow remains the same as the Github apps Cloud except for a few key changes.
If for an existing Github Enterprise connection, the accessType is not github_app, then continue with the older Github Oauth flow else use the new Github Apps flow.
Store accessType=github_app
GitHub App for Enterprise Setup (CodeScan)
Step 1: Copy & Paste This URL
While being logged in as the admin in the GitHub Enterprise Server, use this link to create a GitHub app:
What You Need to Change
Before pressing Enter, replace only these two values:
YOUR_GHES_HOSTNAME→ Your GitHub Enterprise Server URL (Example: github.company.com)YOUR_PUBLIC_BASE→ URL of the CodeScan instance (Example: app.codescan.io)
Important
App name must remain exactly: codescan-enterprise-app (do not modify)
Step 2: Create the App
Open the updated URL
Keep the app Public by enabling “Any account”:

Click Create GitHub App
Step 3: Copy Credentials
After creation, copy:
App ID
Client ID
Client Secret Paste these details in the ALM connections page in CodeScan and create a new ALM connection
Done
Your GitHub App is ready for CodeScan integration.
Last updated
Was this helpful?

