|
| 1 | +## Step 1: Create a GitHub App \{#step-1-create-a-github-app} |
| 2 | + |
| 3 | +Before you can use GitHub as an authentication provider, you must create a GitHub App on GitHub to obtain OAuth 2.0 credentials. |
| 4 | + |
| 5 | +1. Go to [GitHub](https://github.com/) and sign in with your account, or create a new account if needed. |
| 6 | +2. Navigate to [Settings > Developer settings > GitHub Apps](https://github.com/settings/apps). |
| 7 | +3. Click **New GitHub App** to register a new application: |
| 8 | + - **GitHub App name**: Enter a unique name for your app. The name cannot be longer than 34 characters and must be unique across GitHub. |
| 9 | + - **Homepage URL**: Enter your application's homepage URL. |
| 10 | + - **Callback URL**: Copy the **Callback URI** from your Logto GitHub connector and paste it here. You can add multiple callback URLs if needed. After users sign in with GitHub, they'll be redirected here with an authorization code that Logto uses to complete authentication. |
| 11 | + - **Expire user authorization tokens**: Keep this **checked** (recommended). This enables token expiration and refresh tokens for enhanced security. |
| 12 | + - **Request user authorization (OAuth) during installation**: Optionally check this to prompt users to authorize your app during installation. |
| 13 | + - **Webhook**: Uncheck **Active** if you don't need webhook events. For authentication-only use cases, webhooks are typically not required. |
| 14 | +4. Under **Permissions**, configure the permissions your app needs (see Step 2 below for details). |
| 15 | +5. Under **Where can this GitHub App be installed?**, select **Any account** if you want users from any GitHub account to use your app for authentication. |
| 16 | +6. Click **Create GitHub App** to create the GitHub App. |
| 17 | + |
| 18 | +:::note |
| 19 | +Unlike OAuth Apps, GitHub Apps use fine-grained permissions instead of broad scopes. You configure permissions in the GitHub dashboard during app creation, and users grant access to specific repositories during authorization. |
| 20 | + |
| 21 | +For more details on setting up GitHub Apps, see [Registering a GitHub App](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app). |
| 22 | +::: |
| 23 | + |
| 24 | +## Step 2: Configure permissions in GitHub \{#step-2-configure-permissions-in-github} |
| 25 | + |
| 26 | +GitHub Apps use fine-grained permissions instead of OAuth scopes. You must configure permissions **in the GitHub dashboard** when creating or editing your GitHub App. These permissions determine what data your app can access. |
| 27 | + |
| 28 | +### Understanding GitHub App permissions \{#understanding-github-app-permissions} |
| 29 | + |
| 30 | +Permissions are categorized into three types: |
| 31 | + |
| 32 | +- **Repository permissions**: Access to repository-level resources (code, issues, pull requests, etc.) |
| 33 | +- **Organization permissions**: Access to organization-level resources (members, teams, projects, etc.) |
| 34 | +- **Account permissions**: Access to user account data (email, profile, followers, etc.) |
| 35 | + |
| 36 | +For each permission, you can select: |
| 37 | + |
| 38 | +- **No access**: The app cannot access this resource |
| 39 | +- **Read-only**: The app can read but not modify this resource |
| 40 | +- **Read & write**: The app can read and modify this resource |
| 41 | + |
| 42 | +### Recommended permissions for authentication \{#recommended-permissions-for-authentication} |
| 43 | + |
| 44 | +For basic "Sign in with GitHub" functionality, configure these minimum **Account permissions**: |
| 45 | + |
| 46 | +| Permission | Access level | Purpose | |
| 47 | +| ------------------- | ------------ | --------------------------------------------- | |
| 48 | +| **Email addresses** | Read-only | Get user's email address for account creation | |
| 49 | + |
| 50 | +:::tip |
| 51 | +GitHub Apps have implicit access to read public profile information when acting on behalf of a user. You don't need to explicitly request permission for basic profile data like username, avatar, and public profile URL. |
| 52 | +::: |
| 53 | + |
| 54 | +### Additional permissions for API access |
| 55 | + |
| 56 | +If your application needs to access GitHub APIs beyond authentication, add the corresponding permissions in the GitHub dashboard. Here are some common examples: |
| 57 | + |
| 58 | +| Permission type | Permission | Access level | Use case | |
| 59 | +| ---------------- | ------------- | ------------------------ | --------------------------------------------------------- | |
| 60 | +| **Repository** | Contents | Read-only / Read & write | Access repository files and code | |
| 61 | +| **Repository** | Issues | Read & write | Create and manage issues | |
| 62 | +| **Repository** | Pull requests | Read & write | Create and manage pull requests | |
| 63 | +| **Repository** | Metadata | Read-only | Access repository metadata (required for many operations) | |
| 64 | +| **Organization** | Members | Read-only | List organization members | |
| 65 | +| **Account** | Followers | Read-only | Access user's followers and following | |
| 66 | + |
| 67 | +This is not an exhaustive list — GitHub Apps support many more fine-grained permissions. See [Permissions required for GitHub Apps](https://docs.github.com/en/rest/overview/permissions-required-for-github-apps) for the complete list. |
| 68 | + |
| 69 | +:::tip[Key difference from OAuth Apps] |
| 70 | +Unlike OAuth Apps where you configure scopes in the Logto connector, GitHub App permissions are managed entirely in the GitHub dashboard. You can leave the `Scope` field empty in your Logto GitHub connector — it's not needed because GitHub Apps don't use traditional OAuth scopes. |
| 71 | + |
| 72 | +Simply configure the permissions you need in GitHub, and users will be prompted to grant access during authorization. |
| 73 | +::: |
| 74 | + |
| 75 | +## Step 3: Configure your Logto connector \{#step-3-configure-your-logto-connector} |
| 76 | + |
| 77 | +After creating the GitHub App, you'll be redirected to its settings page where you can obtain the credentials. |
| 78 | + |
| 79 | +1. On your GitHub App's settings page, copy the **Client ID** and paste it into the `clientId` field in Logto. |
| 80 | +2. Under **Client secrets**, click **Generate a new client secret**. Copy the generated secret and paste it into the `clientSecret` field in Logto. |
| 81 | +3. Click **Save and Done** in Logto to connect your identity system with GitHub. |
| 82 | + |
| 83 | +:::warning |
| 84 | +Keep your Client secret secure and never expose it in client-side code. GitHub client secrets cannot be recovered if lost - you'll need to generate a new one. |
| 85 | +::: |
| 86 | + |
| 87 | +:::note |
| 88 | +The Client ID for a GitHub App is different from the App ID. Make sure to use the Client ID (shown as "Client ID" on the settings page), not the App ID. |
| 89 | +::: |
| 90 | + |
| 91 | +## Step 4: General settings \{#step-4-general-settings} |
| 92 | + |
| 93 | +Here are some general settings that won't block the connection to GitHub but may affect the end-user authentication experience. |
| 94 | + |
| 95 | +### Sync profile information \{#sync-profile-information} |
| 96 | + |
| 97 | +In the GitHub connector, you can configure how profile information is synced from GitHub user info to the Logto user profile, including `name`, `avatar`, and `email`. Choose from the following options: |
| 98 | + |
| 99 | +- **Only sync at sign-up**: Profile info is fetched once when the user first signs in. |
| 100 | +- **Always sync at sign-in**: Profile info is updated every time the user signs in. |
| 101 | + |
| 102 | +### Store tokens to access GitHub APIs (Optional) \{#store-tokens-to-access-github-apis-optional} |
| 103 | + |
| 104 | +If you want to access GitHub APIs and perform actions with user authorization (whether via social sign-in or account linking), enable token storage in Logto: |
| 105 | + |
| 106 | +1. Configure the required permissions in your GitHub App settings (Step 2). |
| 107 | +2. Enable **Store tokens for persistent API access** in the Logto GitHub connector. Logto will securely store both the access token and refresh token in the Secret Vault. |
| 108 | + |
| 109 | +:::note |
| 110 | +Since GitHub Apps always issue refresh tokens, Logto stores both tokens automatically. The access token expires after 8 hours, but Logto can use the refresh token to obtain new access tokens, ensuring uninterrupted API access for up to 6 months. |
| 111 | +::: |
| 112 | + |
| 113 | +## Step 5: Test your integration (Optional) \{#step-5-test-your-integration-optional} |
| 114 | + |
| 115 | +Before going live, test your GitHub App integration: |
| 116 | + |
| 117 | +1. Use the connector in a Logto development tenant. |
| 118 | +2. Verify that users can sign in with GitHub. |
| 119 | +3. Check that users are prompted for the correct permissions during authorization. |
| 120 | +4. If you enabled token storage, verify that access tokens (and refresh tokens) are stored correctly. |
| 121 | +5. Test API calls using the stored tokens to ensure permissions are working as expected. |
| 122 | + |
| 123 | +GitHub Apps work with any GitHub user account immediately - there's no need for test users or app approval like some other platforms. However, if your app is installed on an organization, organization owners may need to approve the installation. |
0 commit comments