{"id":24988443,"url":"https://github.com/lit-protocol/custom-auth-github-example","last_synced_at":"2026-02-06T13:48:02.615Z","repository":{"id":266604330,"uuid":"898815899","full_name":"LIT-Protocol/custom-auth-github-example","owner":"LIT-Protocol","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-26T09:48:44.000Z","size":267,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-04T12:04:16.204Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LIT-Protocol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-05T04:56:25.000Z","updated_at":"2025-01-21T19:27:56.000Z","dependencies_parsed_at":"2024-12-05T06:31:40.617Z","dependency_job_id":null,"html_url":"https://github.com/LIT-Protocol/custom-auth-github-example","commit_stats":null,"previous_names":["lit-protocol/custom-auth-github-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LIT-Protocol%2Fcustom-auth-github-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LIT-Protocol%2Fcustom-auth-github-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LIT-Protocol%2Fcustom-auth-github-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LIT-Protocol%2Fcustom-auth-github-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LIT-Protocol","download_url":"https://codeload.github.com/LIT-Protocol/custom-auth-github-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246174604,"owners_count":20735417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-04T12:04:19.150Z","updated_at":"2026-02-06T13:47:57.584Z","avatar_url":"https://github.com/LIT-Protocol.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Minting a PKP with Custom GitHub Auth\n\nThis code example demonstrates how to implement custom authentication and authorization using GitHub OAuth. The end result is a PKP that can only be used to sign data if you have valid and recent GitHub OAuth data for a specific GitHub user.\n\n## How it Works\n\nThe following is a brief overview of how it works:\n\n1. User clicks the \"Login with GitHub\" button, which redirects them to GitHub's OAuth flow\n2. After authenticating with GitHub, the user is redirected back to the app with an authorization code\n3. User clicks the `Mint PKP` button and the Web App requests the user to sign a transaction to mint a PKP using their browser wallet extension\n   - As part of the minting PKP transaction, two Auth Methods are permitted for the PKP:\n     1. The IPFS CID of the GitHub OAuth Lit Action\n        - Granted the ability to sign anything using the PKP\n     2. The custom GitHub Auth Method generated by the Web App used to tie the PKP to a specific GitHub user\n        - Not granted any signing abilities\n4. User clicks the `Get Session Sigs` button and a request is made to the Lit `Datil-test` network to execute the GitHub OAuth Lit Action code\n   - The user will be prompted to sign a transaction to mint a Capacity Credit if one wasn't given via an ENV variable\n   - The Lit Action only authorizes Session Signatures to be generated for the PKP if the authenticated GitHub user has been permitted to use the PKP\n5. User enters a message to sign and clicks the `Sign Data with PKP` button and a request is made to the Lit Datil-test network to sign the message with the minted PKP\n6. User clicks the `Verify Signature` button to verify that the signature was created by the minted PKP\n\n## How to Run the Example\n\n### Step 1: Create a GitHub OAuth App\n\n[This](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app) is GitHub's guide for creating an OAuth App, and will be the most up to date guide. The following is a brief overview of the steps:\n\n1. Go to your GitHub Settings \u003e Developer Settings \u003e OAuth Apps\n2. Click \"New OAuth App\"\n3. Fill in the application details:\n   - Application name: Choose any name\n   - Homepage URL: Your application's homepage (e.g., http://localhost:3000)\n   - Authorization callback URL: Your callback URL (e.g., http://localhost:3000/callback)\n4. After creating the app, you'll receive a Client ID and can generate a Client Secret\n   - These will need to be added to the `.env` file you'll create in the `server` directory\n\n### Step 2: Configure Environment Variables\n\nCreate a `.env` file in the `server` directory using the provided `.env.example` template:\n\n```bash\ncp server/.env.example server/.env\n```\n\nAdd your GitHub OAuth App Client ID and Client Secret to the `.env` file:\n\n```\nGITHUB_CLIENT_ID=your_client_id\nGITHUB_CLIENT_SECRET=your_client_secret\nREDIRECT_URI=http://localhost:3000/callback\n```\n\nCreate a `.env` file in the root directory using the provided `.env.example` template:\n\n```bash\ncp .env.example .env\n```\n\nAdd your GitHub OAuth App Client ID to the `.env` file:\n\n```\nVITE_GITHUB_CLIENT_ID=your_client_id\nVITE_GITHUB_OAUTH_SERVER_URL=http://localhost:3001\nVITE_REDIRECT_URI=http://localhost:3000/callback\nVITE_LIT_NETWORK=DatilTest\nVITE_LIT_DEBUG=false\nVITE_LIT_CAPACITY_CREDIT_TOKEN_ID=\n```\n\n### Step 3: Run the Example\n\n1. Install dependencies:\n\nInstall the dependencies for the frontend:\n\n```bash\nyarn\n```\n\nInstall the dependencies for the server:\n\n```bash\ncd server \u0026\u0026 yarn\n```\n\n2. Start the server:\n\nIn the `server` directory, start the server:\n\n```bash\nyarn start\n```\n\n3. Start the frontend:\n\nIn the root directory, start the frontend:\n\n```bash\nyarn dev\n```\n\nThe frontend will be available at http://localhost:3000\n\nThe Ethereum account that you connect to the web app using your browser wallet extension needs to have Lit test tokens. If you don't already have some, you can request some using [the faucet](https://chronicle-yellowstone-faucet.getlit.dev/).\n\n## Exploring the Code\n\nIf you'd like to dive deeper into the code to understand how this example works, below is a brief explanation of some of the files you'll want to look at:\n\n- [App.tsx](./src/App.tsx) is the React frontend code for the app.\n- [server/server.js](./server/server.js) contains the backend server code for handling GitHub OAuth.\n- [GitHubCallback.tsx](./src/GitHubCallback.tsx) handles the OAuth callback from GitHub.\n- [GitHubLoginButton.tsx](./src/GitHubLoginButton.tsx) contains the logic for the \"Login with GitHub\" button.\n- [mintPkp.ts](./src/mintPkp.ts) contains the logic for minting the PKP.\n- [getPkpSessionSigs.ts](./src/getPkpSessionSigs.ts) contains the logic for requesting Session Sigs using the minted PKP.\n- [litAction.ts](./src/litAction.js) contains the Lit Action code\n  - The Lit Action is hardcoded to only communicate with the PKP Permission contract deployed on Chronicle Yellowstone at `0x60C1ddC8b9e38F730F0e7B70A2F84C1A98A69167`.\n  - It's also hardcoded to only use the Auth Method with the type: `keccak256('Lit Developer Guide GitHub Auth Example')`.\n- [pkpSign.ts](./src/pkpSign.ts) contains the logic for signing data with the minted PKP.\n- [utils.ts](./src/utils.ts) contains wrapper functions for the Lit SDK.\n\n## Known Issues\n\nAfter clicking the \"Login with GitHub\" button, you may see the following error in the browser console:\n\n![Github OAuth Errors](githubOAuthErrors.png)\n\nThis can be safely ignored as long as you see `GitHub auth response received:` after the errors. Not sure why it happens, but it doesn't affect the functionality.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flit-protocol%2Fcustom-auth-github-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flit-protocol%2Fcustom-auth-github-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flit-protocol%2Fcustom-auth-github-example/lists"}