Code Monkey home page Code Monkey logo

netlify-cms-github-oauth-provider's Introduction

Netlify-cms-github-oauth-provider

External authentication providers were enabled in netlify-cms version 0.4.3. Check your web console to see your netlify-cms version.

netlify-cms has its own github OAuth client. This implementation was created by reverse engineering the results of that client, so it's not necessary to reimplement client part of netlify-cms.

Github, Github Enterprise and Gitlab are currently supported, but as this is a general Oauth client, feel free to submit a PR to add other git hosting providers.

Other implementations in: Go lang.

1) Install Locally

Install Repo Locally

git clone https://github.com/vencax/netlify-cms-github-oauth-provider
cd netlify-cms-github-oauth-provider
npm install

Create Oauth App Information is available on the Github Developer Documentation or Gitlab Docs. Fill out the fields however you like, except for authorization callback URL. This is where Github or Gitlab will send your callback after a user has authenticated, and should be https://your.server.com/callback for use with this repo.

2) Config

Auth Provider Config

Configuration is done with environment variables, which can be supplied as command line arguments, added in your app hosting interface, or loaded from a .env (dotenv) file.

Example .env file:

NODE_ENV=production
ORIGINS=www.my_organisation.com,www.my_organisation_second.com
OAUTH_CLIENT_ID=f432a9casdff1e4b79c57
OAUTH_CLIENT_SECRET=pampadympapampadympapampadympa
REDIRECT_URL=https://your.server.com/callback
GIT_HOSTNAME=https://github.website.com
PORT=3000

NOTE: ORIGINS is mandatory and can contain regex (e.g. .*.my_organisation.com)

For Gitlab you also have to provide this environment variables:

OAUTH_PROVIDER=gitlab
SCOPES=api
OAUTH_AUTHORIZE_PATH=/oauth/authorize
OAUTH_TOKEN_PATH=/oauth/token

You can also setup an environment variable to configure "_blank" target when auth window is opened. Default is "_self".

AUTH_TARGET=_blank

Client ID & Client Secret: After registering your Oauth app, you will be able to get your client id and client secret on the next page.

Redirect URL (optional in github, mandatory in gitlab): Include this if you need your callback to be different from what is supplied in your Oauth app configuration.

Git Hostname (Default github.com): This is only necessary for use with Github Enterprise or Gitlab.

Port number (Default 3000) If you do not want to run the app on 3000.

CMS Config

You also need to add base_url to the backend section of your netlify-cms's config file. base_url is the live URL of this repo with no trailing slashes.

backend:
  name: [github | gitlab]
  repo: user/repo   # Path to your Github/Gitlab repository
  branch: master    # Branch to update
  base_url: https://your.server.com # Path to ext auth provider

3) Deploy

Heroku

Basic instructions for pushing to heroku are available in the original blog post.

Locally

You can run the instance like so:

npm start

Or with commandline provided variables like so:

PORT=3111 NODE_ENV=production ORIGINS=www.my_organisation.com OAUTH_CLIENT_ID=... OAUTH_CLIENT_SECRET=... npm start

If running behind reverse-proxy (e.g. nginx), the /auth and /callback paths need to be proxied, e.g. like so:

 location /auth {
    proxy_pass http://127.0.0.1:3111;
    proxy_pass_request_headers      on;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_set_header Early-Data $ssl_early_data;
}

location /callback {
    proxy_pass http://127.0.0.1:3111;
    proxy_pass_request_headers      on;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_set_header Early-Data $ssl_early_data;
}

You may want to run this as a systemd service like so:

$ cat /etc/systemd/system/oauth-github.service
[Unit]
Description=OAuth provider for Netlify CMS and Github
After=network.target

[Service]
Type=simple
User=user
WorkingDirectory=/opt/netlify-cms-github-oauth-provider
ExecStart=/usr/bin/npm run start
Restart=always
Environment=PORT=3111
Environment=ORIGINS=www.my_organisation.com
Environment=OAUTH_CLIENT_ID=...
Environment=OAUTH_CLIENT_SECRET=...

[Install]
WantedBy=multi-user.target

netlify-cms-github-oauth-provider's People

Contributors

devcustrom avatar fiatjaf avatar itsmejoeeey avatar jakubklimek avatar marians avatar ramank775 avatar vencax 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  avatar  avatar  avatar

netlify-cms-github-oauth-provider's Issues

Authenticating Github in backend instead of redirecting to Github login page

I am using this project for doing Github Authentication through my own server. I have integrated the Netflify-CMS to my React-App. Once auser is logged into the React-App, he/she needs to do a separate login into Github Account again to access Netlify-CMS. I am looking for solution that moves the Github login process to backend API/ netlify-cms-github-oauth-provider code where we can store username/password of github account and there itself we perform the login and upon success, it redirects to Netlify-CMS UI directly.

This what happens currently

  1. When user login in the react app and move to Netlify-CMS option, below screen appears that prompts the user to login with github again.
    image

  2. After clicking on "login with Github" , it redirects to github login page with the help of netlify-cms-github-oauth-provider project running on Ec2 server
    image

  3. After successful login , I can see the netflify-CMS UI
    image

I am looking to move the 2nd step in background ,so that users of my app doesn't need to login into github separately. Is this possible with "netlify-cms-github-oauth-provider" project ??

Need Help setting up the authentication

Hi. I followed all the steps.

  1. I set up the Oauth app
  2. I created a heroku app and hosted the instance
  3. I added the env variables to heroku
  4. I added the callback URL to the Oauth app
  5. I go back to my main website where the config.yml is
  6. I added the backend stuff
  7. I open the website and I see this

image

Including and serving netlify itself

If netlify isn't going this route by default then it seems everything could all be packaged up with netlify, meaning a single repo gives you everything required, while side-stepping the default api.netlify.com lock-in.

Throwing everything into a directory then adding a route to look for it in this directory isn't too bad an approach. config.yml could be made to live outside this directory, while index.html too could live in the root as it requires customisation.

Then you can clone this repo, run a task, be up and running with your own front and backend.

Security Risk

I would just like to know whether there are any security risks involved, since my oauthprovider server can still be accessed with any browser and get a oath token? Wouldn't it be ideal to check from where the request is coming and then give it access or deny the request? In this case the only allowed it when I get a request from my domain and deny other domains?

Sorry I'm completely new to this.

If this is a concern, I wouldn't mind adding it to the project.

Authentication Error: Invalid state key

I'm trying to set a netlify oauth by running your server.
I've created the oauth in github, and set credential and secret on the server, with localhost:8080 as origin.
I then added the server as the backend of my cms configuration on the frontend app.
I can then login through github from the admin panel, but the callback just show an authentication error due to the following error: invalid state key.
I can't understand exactly what's the error and if i'm missing something

Settings for localhost

Hi all!
Could someone help me to set up this provider to work locally?

Here are my .env settings:

NODE_ENV=production
ORIGINS= // what can I specify here for localhost?
OAUTH_CLIENT_ID=GITHUB_CLIENT_ID
OAUTH_CLIENT_SECRET=GITHUB_SECRET
PORT=3001
AUTH_TARGET=_blank

Invalid state key

Please this is the challenge i am having with netlify, Authentication Error
Authenticating failed due to the following error: Invalid state key.

GitLab support

Have you considered supporting other Oauth providers/backends like GitLab?

Can i use this to change the Authentication service in Netlify CMS?

I am looking for something that will let me change the Login service in my Netlify-CMS admin panel.
For now, it is connected to self-hosted GitLab repo (no Netlify service integration, just Netlify CMS) and by default - it requires GitLab account to log in to admin.

Can I change it to Azure accounts (that would be given permissions to this gitlab repo, somehow?)

Too much rights for the app

I understand that this gives this app too much rights, with the scope "user,repo": write access on all the user information and all its repositories.

Is there a way to limit to write access on a specific repository?

Not working on sub page

I forked your app and replaced app.listen with module.exports = app and in my main app, I used app.use to mount it. that all works.

When I do app.use("/netlify",varReferingToNetlifyAuthProv)
(and set backend.base_url and oath Authorization callback URL acordingly)
it gets stuck at /netlify/callback?code=&state= but when I do app.use without a mount path (and set backend.base_url and oath Authorization callback URL acordingly) it goes to /callback?code=&state= and the window closes and netlify sucessfully loges in.

Github fork: https://github.com/tumblenet/netlify-cms-github-oauth-provider
API Server code: https://github.com/tumblenet/api.tumblenet.ga
static website with the cms: https://github.com/tumblenet/go.tumblenet.cu.cc

I have a question about setup

I am trying to use this code, I have successfully set up an app at Github and deployed this provider, I see login with GitHub, I have signed in using Github, but I could not log in to Netlify CMS, every time I click on login with Github it's just opening a blank page for me.

popup window stays open and blank

Hi there. I have managed to make everything works (window popups, you are able to authorise github, the OAuth app in github "gets" the new user) BUT eventually the popup window doesn't close and it's just blank...
Well, actually it contains just

<script>
(function() {
    function receiveMessage(e) {
    console.log("receiveMessage %o", e)
    // send message to main window with da app
    window.opener.postMessage(
        'authorization:github:success:{"token":"5b95156e2667db763606e3647d48968054716001","provider":"github"}',
        e.origin
    )
    }
    window.addEventListener("message", receiveMessage, false)
    // Start handshare with parent
console.log(window.opener)
    console.log("Sending message: %o", "github")
    window.opener.postMessage("authorizing:github", "*")
    })()
</script>

I believe that for a reason the popup cannot postmessage to the parent window (where netlifycms /admin/#/ is) and vice versa...

Any ideas will be more than welcome. Thanks in advance!

License?

Hi vencax can you add a license when you get a chance?

Insecure ORIGIN pattern used?

My heroku logs show this:

Insecure ORIGIN pattern used. This can give unauthorized users access to your repository.
Will not run without a safe ORIGIN pattern in production.
Process exited with status 0
tate changed from starting to crashed

What's the fix?

window.opener is null

Having the same problem. I still get the error, that the window.opener is null. It makes sense that it is null, after the redirect to github and back over the callback url. So how is that supposed to work?

Originally posted by @Tobilo in #14 (comment)

Using dotenv means secrets in repo

For this kind of secret I usually create a setup_env.sh and setup_env.example.sh then .gitignore the non-example version. This way secrets don't end up committed to repositories.

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.