GitHub & GitLab Apps
To read and commit to your repositories and allow users to sign in, a self-hosted Sitepins deployment connects to your Git providers through three separate applications:
| Integration | Configuration File | Subsystem | Purpose |
|---|---|---|---|
| GitHub App | app/.env | Web App | Repository Access: Reads directory trees, commits file changes, and manages pull requests. |
| GitHub OAuth App | api/.env | Express API | User Sign-In: Allows users to log in or register via GitHub OAuth. |
| GitLab OAuth App | app/.env | Web App | Combined Sign-In & Repository Access: Handles both authentication and repository commits for GitLab. |
Common Configuration Mistake:
Do not confuse the GitHub App (configured in app/.env) with the GitHub OAuth App (configured in api/.env). They serve completely different purposes and have different credential formats.
1. GitHub App Setup (Repository Access)
Sitepins commits to repositories on behalf of your users using an official GitHub AppΒ .
Step 1: Create the App
- Navigate to GitHub Settings β Developer settings β GitHub Apps β New GitHub App.
- GitHub App name: Choose a unique name (e.g.
acme-cms-sitepins). Note this down; it must matchNEXT_PUBLIC_GITHUB_APP_NAMEexactly. - Homepage URL: Your public web app URL (e.g.
https://cms.example.comorhttp://localhost:3000). - Callback URL:
<APP_URL>/github-installed(e.g.https://cms.example.com/github-installed). - Setup URL (optional):
<APP_URL>/github-installedwith βRedirect on updateβ checked. - Request user authorization (OAuth) during installation: MUST BE CHECKED.
[!WARNING]
If βRequest user authorization during installationβ is unchecked, GitHub will not return the authorization code upon installation, causing the connection flow to fail silently.
- Webhook: Uncheck Active (Sitepins does not require incoming webhooks).
- Where can this GitHub App be installed?:
- Select βAny accountβ if team members or clients will install it on their personal or external organization repositories.
- Select βOnly on this accountβ if you are strictly hosting internally for a single organization.
Step 2: Set Repository Permissions
Under the Repository permissions section, grant the following scopes:
| Permission Name | Access Level | Reason Required |
|---|---|---|
| Administration | Read & write | Project setup and repository verification. |
| Contents (Code) | Read & write | Mandatory for reading file content and creating Git commits. |
| Commit statuses | Read-only | Checking build and deployment statuses. |
| Deployments | Read-only | Verifying deployment triggers. |
| Metadata | Read-only | Mandatory GitHub default. |
| Pull requests | Read & write | Creating and merging pull requests directly from Sitepins. |
Step 3: Generate Keys & Configure app/.env
- On the app settings page, locate the numeric App ID and the alphanumeric Client ID.
- Under Client secrets, click Generate a new client secret and copy the resulting string immediately.
- Under Private keys, click Generate a private key. A
.pemfile will be downloaded to your computer. - Open the downloaded
.pemfile in a text editor and copy its entire contents (including-----BEGIN RSA PRIVATE KEY-----and-----END RSA PRIVATE KEY-----). - Populate
app/.env:
GITHUB_APP_ID="123456"
GITHUB_APP_CLIENT_ID="Iv1.abc123def456"
GITHUB_APP_CLIENT_SECRET="ghs_secret123456789"
GITHUB_APP_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA...
...
-----END RSA PRIVATE KEY-----"
NEXT_PUBLIC_GITHUB_APP_NAME="acme-cms-sitepins"Wrap GITHUB_APP_PRIVATE_KEY in double quotes so your environment parser preserves all embedded newlines.
Step 4: Install the App
Visit your appβs public installation page at https://github.com/apps/<NEXT_PUBLIC_GITHUB_APP_NAME> and click Install on your user account or target organization.
2. GitHub OAuth App Setup (User Login)
This enables the βContinue with GitHubβ button on the sign-in and registration pages.
- Navigate to GitHub Developer Settings β OAuth AppsΒ β New OAuth App.
- Application name: A descriptive name (e.g.
Sitepins Login). - Homepage URL: Your API or Web URL (e.g.
https://cms.example.com). - Authorization callback URL: Must point to the Express APIβs callback route:
Example:
<BASE_URL>/api/v1/auth/callback/githubhttps://api.example.com/api/v1/auth/callback/github(orhttp://localhost:4000/api/v1/auth/callback/githubfor local development). - Copy the Client ID and generate a Client Secret.
- Populate
api/.env:
GITHUB_CLIENT_ID="Ov23li..."
GITHUB_CLIENT_SECRET="987654..."3. GitLab OAuth App Setup
GitLab uses a single OAuth application to handle both user sign-in and repository operations.
- In GitLab, navigate to your user profile Preferences β Applications (or organization Group Settings β Applications to scope to a group).
- Name: e.g.
Sitepins GitLab. - Redirect URI: Exactly
<APP_URL>/gitlab-installed(e.g.https://cms.example.com/gitlab-installedorhttp://localhost:3000/gitlab-installed). - Confidential: Ensure this is checked.
- Scopes: Select exactly two scopes:
api(Read/write access to repository files and merge requests)read_user(Read user profile and email)
- Click Save application and copy the Application ID and Secret.
- Populate
app/.env:
NEXT_PUBLIC_GITLAB_APP_NAME="GitLab"
NEXT_PUBLIC_GITLAB_CLIENT_ID="gloas-12345..."
GITLAB_CLIENT_SECRET="gloas-secret-67890..."Troubleshooting Git Provider Connections
| Problem | Root Cause | Solution |
|---|---|---|
| Installation popup 404s | NEXT_PUBLIC_GITHUB_APP_NAME differs from your real GitHub App name slug. | Verify the URL at https://github.com/apps/<NEXT_PUBLIC_GITHUB_APP_NAME>. |
| Popup completes but nothing connects | βRequest user authorization (OAuth) during installationβ was not checked. | Edit your GitHub App settings, check the box, and reinstall. |
403 Forbidden reading trees or committing | Repository permissions are narrower than required. | Verify all required scopes (Contents: Read & write, PRs: Read & write) and accept permission updates on the GitHub installation. |
| GitHub App authentication error (signing failed) | GITHUB_APP_PRIVATE_KEY lost line breaks during copy-paste. | Quote the variable in app/.env with double quotes and ensure \n characters are preserved. |
| No repositories appear in picker | The GitHub App installation was restricted to βOnly select repositoriesβ and the desired repository was omitted. | Open https://github.com/settings/installations, find your app, and add the repository. |
GitLab callback error: The redirect URI provided is missing or does not match | Redirect URI mismatch. | Ensure the URI in GitLab is character-for-character identical to <APP_URL>/gitlab-installed (including port and protocol). |