Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

▲🔐 Protect a static website hosted on Vercel behind GitHub authentication.

License

NotificationsYou must be signed in to change notification settings

n4bb12/vercel-github-oauth-proxy

Repository files navigation

Protect a static website hosted on Vercel behind GitHub authentication.

VersionLicenseIssues

Setup

Step 1 — Add the library

yarn add vercel-github-oauth-proxy

Step 2 — Create an API endpoint at/api/index.ts

import{createLambdaProxyAuthHandler}from"vercel-github-oauth-proxy"exportdefaultcreateLambdaProxyAuthHandler(config)

config.cryptoSecret

This is used to sign cookies.

config.staticDir

The output directory of the static website.

config.githubOrgName

The GitHub organization users need to be part of in order to be able to sign in.

You cannot use your personal GitHub account for this, you need an organization.

config.githubClientIdconfig.githubClientSecret

The id/secret pair of your GitHub OAuth app.

Create a new OAuth app athttps://github.com/organizations/{config.githubOrgName}/settings/applications/new

config.githubOrgAdminToken

Create a token withread:org permission athttps://github.com/settings/tokens.

The reason you need a token is that private org memberships can only bedetermined by making an authenticated API request.

We could requestread:org scope during the OAuth flow and then use each user'saccess token to determine org membership, but using this method means the useradditionally needs to request org access during or after the login flow andrequires an org admin to confirm. This makes this approach inconvenient for boththe users and the admin.

Therefore we're using a separate org admin token to verify membership duringlogin (org admins can see all users).

Step 3 — Create avercel.json

{"version":2,"routes": [{"src":"/(.*)","dest":"/api/index.ts" }],"functions": {"api/index.ts": {"includeFiles":"static/**"    }  }}

This routes all traffic through the lambda endpoint.

AdaptincludeFiles to your public output folder. Including these files isrequired because the static website needs to be deployed as part of the lambdafunction, not the default build. See also these docs:

Step 4 — Build

If you have an existingbuild script, rename it tovercel-build to buildyour website as part of the lambda build instead of the normal build.

Make sure to not keep thebuild script as it would result in duplicate work ormay break deployment entirely. For more information seecustom-build-step-for-node-js.

{"scripts": {"vercel-build":"your website build command"  }}

Local development

To develop locally, run

yarn vercel dev

When developing locally, you'll need to update your GitHub OAuth app's redirectURL tohttp://localhost:3000.

About

▲🔐 Protect a static website hosted on Vercel behind GitHub authentication.

Topics

Resources

License

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp