Giter Site home page Giter Site logo

gr2m / cloudflare-worker-github-oauth-login Goto Github PK

View Code? Open in Web Editor NEW
141.0 4.0 43.0 30 KB

Use a Cloudflare worker for GitHub's OAuth login flow

Home Page: https://gr2m.github.io/cloudflare-worker-github-oauth-login/index.html

License: ISC License

JavaScript 30.13% HTML 69.87%

cloudflare-worker-github-oauth-login's Introduction

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" app, 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. Install the wrangler CLI and login with your account

    npm install --global wrangler
    wrangler login
    
  5. Edit the wrangler.toml file, change the value for account_id to your own (select your account, then find your Account ID at the bottom of the side bar)

  6. Add the following secrets to your Cloudflare worker:

    • CLIENT_ID, CLIENT_SECRET: In your GitHub (OAuth) App's settings page, find Client ID and Client SECRET

      wrangler secret put CLIENT_ID
      wrangler secret put CLIENT_SECRET
      
  7. Add the following secret in your fork's repository settings:

  8. Enable GitHub Pages in your repository settings, select Source to be the master branch.

  9. In index.html, replace the gr2m workers subdomain with your own, in WORKER_URL and the login <a href="..."> tag.

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

See also

Credits

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

License

ISC

cloudflare-worker-github-oauth-login's People

Contributors

billytrend avatar gr2m avatar octref avatar xtuc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cloudflare-worker-github-oauth-login's Issues

Relicensed fork?

Hello, I really like your project, so so much that I forked it to make it as the base of my application.

I, however found a problem:
I want to eventually merge my derivative of your project to another repo of mine which in turn is also a derivative of two repos, though they are MIT-licensed. Now, this is will cause a license conflict, despite ISC license being closely related to MIT. Can I relicense my fork from ISC license to MIT? I will still properly attribute you, the only thing that will change is the license.

Thank you for your consideration and have a good day!

User-Agent header missing

That probably changed since this template was created. User-Agent seems to be required by the GitHub API now.

Full message

"\r\nRequest forbidden by administrative rules. Please make sure your request has a User-Agent header (http://developer.github.com/v3/#user-agent-required). Check https://developer.github.com for other possible causes.\r\n"

returned by tthe call to https://api.github.com/user

Cloudflare Site Value

When I sign up for a new Cloudflare account, what do I put in as a site domain? This seems to be required to get my zone Id. I didn't think that I needed to host a domain on Cloudflare as it is only used to host a service.

image

Host through a Worker vs. GitHub Pages

Instead of using GitHub Pages, I'd simply like to host through a Worker. Trying to think through the logic (if there is anything that wouldn't work properly?)

Redirect back from github resulted in endless redirect back to github

Hello, Gregor (@gr2m), thank you for the project: I was looking for a walkthrough GitHub auth.
I tried to follow README and deployed the app on my pages, currently authorisation work on GitHub but then trigger endless redirect between GitHub and worker URL.
Is anything specific about worker URL in callback on Github?
I put worker URL in Callback https://github-oauth-login.terraphim.workers.dev/

Some questions for installation

Hi

It is very nice project, but I have several questions for it.

  1. I already uses Cloudflare workers script under maplat.jp domain.
    Are there any concern for existing scripts are overwritten by this code's installation?
  2. What domain/url is this code used?
    Is it possible to run it under subdomain? (E.g. my domain is maplat.jp but I want to run this on s.maplat.jp)
  3. Is it possible to install this manually?
  4. Is it possible to customize this code to work with other identity sources? (Like Google, Twitter...)

Regards,
Kohei

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.