# Github Oauth authentication

**URL:** https://discourse.nodered.org/t/github-oauth-authentication/27766
**Category:** Core Development
**Created:** [4 June 2020 13:29 UTC](https://discourse.nodered.org/t/github-oauth-authentication/27766 "2020-06-04T13:29:05Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)
#### Post date: [4 June 2020 13:29 UTC](https://discourse.nodered.org/t/github-oauth-authentication/27766/1 "2020-06-04T13:29:05Z")

</div>

I am trying to use GitHub to authenticate users in node-red, I tried following the [documentation](https://nodered.org/docs/user-guide/runtime/securing-node-red#oauthopenid-based-authentication), but there is not a lot of info.

I created a file named user-authentication.js, copied the OAuth strategy, and in setings.js I added `adminAuth: require("./user-authentication"), `  
After trying to start node-red I get an error:

```auto
$ node-red
Error loading settings file: /home/nemanja/.node-red/settings.js
/home/nemanja/.node-red/user-authentication.js:3
    strategy: {
            ^

SyntaxError: Unexpected token ':'
    at Object.compileFunction (vm.js:344:18)
    at wrapSafe (internal/modules/cjs/loader.js:1106:15)
    at Module._compile (internal/modules/cjs/loader.js:1140:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
    at Function.Module._load (internal/modules/cjs/loader.js:929:14)
    at Module.require (internal/modules/cjs/loader.js:1080:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/home/nemanja/.node-red/settings.js:123:16)
    at Module._compile (internal/modules/cjs/loader.js:1176:30)

```

Am I doing something wrong ? I can`t find any good info on how it should be implemented...

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [4 June 2020 13:36 UTC](https://discourse.nodered.org/t/github-oauth-authentication/27766/2 "2020-06-04T13:36:42Z")

</div>

If you want to move some settings out to another file and then include them with a `require` statement, then that other file needs to be a node module. In other words it needs to look something like:

```auto

module.exports = {
   type:"strategy",
   strategy: {
    ...
   }
}

```

My guess is you haven't got the `module.exports=` bit at the start of your file.

---

<div class="post-metadata">

### Author: ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)
#### Post date: [4 June 2020 13:43 UTC](https://discourse.nodered.org/t/github-oauth-authentication/27766/3 "2020-06-04T13:43:36Z")

</div>

Node-Red started, but I am stuck at the login page seeing nothing, take a look...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/9012c6dd380e33dde14436b5268271c914d16de1.png)  
The console doesn't show any error...  
Should I edit something in settings file?

Here is my user-authentication file...

```auto
module.exports = {
adminAuth: {
    type:"strategy",
    strategy: {
        name: "twitter",
        label: 'Sign in with Twitter',
        icon:"fa-twitter",
        strategy: require("passport-twitter").Strategy,
        options: {
            consumerKey: 'Iv1.2XXXXXXXb5f',
            consumerSecret: 'bfceXXXXXXXXXXXXXXXXXa31604ff',
            callbackURL: "http://127.0.0.1:1880/auth/strategy/callback",
            verify: function(token, tokenSecret, profile, done) {
                done(null, profile);
            }
        },
    },
    users: [
       { username: "knolleary",permissions: ["*"]}
    ]
}
};

```

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [4 June 2020 13:48 UTC](https://discourse.nodered.org/t/github-oauth-authentication/27766/4 "2020-06-04T13:48:58Z")

</div>

If you have got:

```auto
adminAuth: require("./user-authentication")

```

in your main settings file, then you don't want to repeat the `adminAuth` bit in your user auth file. It should be:

```auto
module.exports = {
   type: "strategy",
   ...
}

```

---

<div class="post-metadata">

### Author: ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)
#### Post date: [4 June 2020 14:10 UTC](https://discourse.nodered.org/t/github-oauth-authentication/27766/5 "2020-06-04T14:10:25Z")

</div>

After removing the **adminAuth** node-red trows a different error

```auto
Failed to start server:
TypeError: OAuth2Strategy requires a clientID option
    at Strategy.OAuth2Strategy (/home/nemanja/.node-red/node_modules/passport-oauth2/lib/strategy.js:86:34)
    at new Strategy (/home/nemanja/.node-red/node_modules/passport-github/lib/strategy.js:62:18)
    at Object.genericStrategy (/usr/lib/node_modules/node-red/node_modules/@node-red/editor-api/lib/auth/index.js:175:18)
    at Object.init (/usr/lib/node_modules/node-red/node_modules/@node-red/editor-api/lib/index.js:71:22)
    at Object.init (/usr/lib/node_modules/node-red/lib/red.js:72:17)
    at Object.<anonymous> (/usr/lib/node_modules/node-red/red.js:202:9)
    at Module._compile (internal/modules/cjs/loader.js:1176:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
    at Function.Module._load (internal/modules/cjs/loader.js:929:14)

```

I am sorry to bother you with this stupid question, but I want to learn how to do it properly.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [3 August 2020 14:10 UTC](https://discourse.nodered.org/t/github-oauth-authentication/27766/6 "2020-08-03T14:10:28Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
