Skip to content

brentrealbt/krakerjak.io

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cloudflare-worker-github-oauth-login

A Cloudflare Worker + GitHub Pages Login Example

The github-oauth-login.js file is a Cloudflare Worker which is continuously deployed using GitHub Actions (see .github/workflows/deploy.yml).

The worker does 3 things

  1. When you open the worker URL, it will redirect to the OAuth App's login URL on github.com (example).
  2. It accepts a POST request with the OAuth code retrieved from the OAuth callback redirect and returns an OAuth access token in return
  3. It enables CORS.

The index.html file is a demo of a "Login with GitHub", you can see the demo at gr2m.github.io/cloudflare-worker-github-oauth-login/index.html. Look at its source code. If something is unclear, please feel free to open an issue or ping me on twitter.

Step-by-step instructions to create your own

Note that you require access to the new GitHub Actions for the automated deployment to work.

  1. Create a GitHub App or GitHub OAuth App
  2. Fork this repository
  3. Create a Cloudflare account (it's free!) if you don't have one yet.
  4. Add the following secrets in your fork's repository settings:
    • CLIENT_ID, CLIENT_SECRET: In your GitHub (OAuth) App's settings page, find Client ID and Client SECRET
    • CLOUDFLARE_AUTH_EMAIL: Find your account's email on your profile page
    • CLOUDFLARE_AUTH_KEY: On your profile page, open the API Tokens tab, find Global API Key.
    • CLOUDFLARE_ACCOUNT_ID: Open dash.cloudflare.com, select your account, then select your website. Find Zone ID and Account ID
  5. Enable GitHub Pages in your repository settings, select Source to be the master branch.
  6. In index.html, replace the gr2m workers subdomain with your own, in WORKERS_URL and the login <a href="..."> tag.

That should be it. The github-oauth-login.js file is now continously deployed to Cloudflare each time there is a commit to master.

Credits

The OAuth App Avatar and this repository's social preview are using @cameronmcefee's cloud Octodex graphic :octocat:💖

License

ISC

About

Use a Cloudflare worker for GitHub's OAuth login flow

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 52.7%
  • JavaScript 47.3%