Here is what happens when a user installs the github app. Here is an overview of the process:
- The user clicks the "Install GitHub app" button
- The control panel calls the API to retrieve a github URL
- The control panel redirects to that URL
- The user follows the process on github
- github redirects to the control panel
- The control panel calls the API to confirm the installation
- The API indexes the repositories
Let's dive into what the control panel's needs to do.
To retrieve the github URL that will be used to redirect the user, the control panel calls the
POST /v1/github/installation
API endpoint.
This endpoint accepts a metadata
property, that will be preserved during the whole flow. We can use it to
store the current URL and redirect the user back to the current page once the installation is done.
The endpoint returns an url
property, this is the github URL to redirect to.
When the user has completed the part on github, they get redirected to the control panel's
/api/app/github/callback
page with some query parameters:
installation_id
: a stringsetup_action
: a stringstate
: a json web token
The state
token can be decoded to retrieve it's payload, which contains the metadata
property. It can be
used to redirect the user to the page where the installation started.
To confirm the installation, the control panel needs to call the POST /v1/github/installation/callback
API endpoint with the 3 query parameters (installation_id
, setup_action
and state
) in the request's
body.