# Authenticating into Node-RED using Google OAuth - Working Solution

**URL:** https://discourse.nodered.org/t/authenticating-into-node-red-using-google-oauth-working-solution/10047
**Category:** General
**Created:** [12 April 2019 04:16 UTC](https://discourse.nodered.org/t/authenticating-into-node-red-using-google-oauth-working-solution/10047 "2019-04-12T04:16:53Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![cowchimp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cowchimp/32/26_2.png) [@cowchimp](https://discourse.nodered.org/u/cowchimp)
#### Post date: [12 April 2019 04:16 UTC](https://discourse.nodered.org/t/authenticating-into-node-red-using-google-oauth-working-solution/10047/1 "2019-04-12T04:16:53Z")

</div>

Saw some questions in the forum about authenticating into Node-RED using Google OAuth, but couldn't find a working example.  
So here is the code after I got it working with `passport-google-oauth`.

Please let me know if this works for you or not.

```auto
adminAuth: {
  type: "strategy",
  strategy: {
    name: "google",
    label: 'Sign in with Google',
    icon: "fa-google",
    strategy: require('passport-google-oauth').OAuth2Strategy,
    options: {
      clientID: 'some client id',
      clientSecret: 'some client secret',
      scope: 'email',
      callbackURL: "https://your-node-red-instance.com/auth/strategy/callback",
      verify: function (token, tokenSecret, profile, done) {
        profile.username = profile.emails.find(x => x.verified).value;
        done(null, profile);
      }
    }
  },
  users: function (username) {
    return Promise.resolve({
      username: username,
      permissions: "*"
    });
  }
}

```

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [12 April 2019 16:43 UTC](https://discourse.nodered.org/t/authenticating-into-node-red-using-google-oauth-working-solution/10047/2 "2019-04-12T16:43:25Z")

</div>

Does this need any settings in Google API's? Also, does it need a callback URL that is actually accessible by Google? (quite a lot of these API's don't).

---

<div class="post-metadata">

### Author: ![cowchimp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cowchimp/32/26_2.png) [@cowchimp](https://discourse.nodered.org/u/cowchimp)
#### Post date: [14 April 2019 07:01 UTC](https://discourse.nodered.org/t/authenticating-into-node-red-using-google-oauth-working-solution/10047/3 "2019-04-14T07:01:09Z")

</div>

Yes, this required generating a ClientId and ClientSecret at  
[https://console.developers.google.com/apis/credentials](https://console.developers.google.com/apis/credentials).  
The "Authorized redirect URIs" I entered there must match the callbackURL that I set in the strategy options in Node-RED.

Adding screenshots of the admin settings below.

Regarding whether the callback really needs to be accessible by Google, I'm afraid I don't know.  
My Node-RED instance is publicly available but I don't know if this is a must.

 ![Google Credentials](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c04aced1b36679681e73e5a1f017637fb4cfa19a.png)

 ![Google Consent](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/5b144e3e35d92098f74eb25b987dc63eed9a3b26.png)

---

<div class="post-metadata">

### Author: ![sorjef](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sorjef/32/17613_2.png) [@sorjef](https://discourse.nodered.org/u/sorjef)
#### Post date: [28 February 2020 01:50 UTC](https://discourse.nodered.org/t/authenticating-into-node-red-using-google-oauth-working-solution/10047/4 "2020-02-28T01:50:46Z")

</div>

That really helped. Thanks a lot!

---

<div class="post-metadata">

### Author: ![Marty1982](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marty1982/32/20162_2.png) [@Marty1982](https://discourse.nodered.org/u/Marty1982)
#### Post date: [1 February 2022 13:24 UTC](https://discourse.nodered.org/t/authenticating-into-node-red-using-google-oauth-working-solution/10047/5 "2022-02-01T13:24:40Z")

</div>

Hi all!, i want to try this out.

Is there any update about it or is it fine with the initial code if @cowchimp ?

Regards!

---

<div class="post-metadata">

### Author: ![fixjunk](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@fixjunk](https://discourse.nodered.org/u/fixjunk)
#### Post date: [23 September 2022 20:39 UTC](https://discourse.nodered.org/t/authenticating-into-node-red-using-google-oauth-working-solution/10047/6 "2022-09-23T20:39:30Z")

</div>

I just implemented this and it works great. A couple of things I noticed:

1. you need to install passport-google-oauth with npm or you'll get a settings error: `npm install passport-google-oauth`
2. I believe a comma is missing after the last close bracket, e.g. `},`
3. In the google credentials settings, you have to add the redirect url as `https://your-node-red-instance.com/auth/strategy/callback`
4. MOST IMPORTANT: This allows ANYONE with a google account to sign in. I'm able to restrict it to my organization / workspace account by leaving it as "internal", but just please be aware!

You can address #4 by changing out the section here:

```auto
  users: function (username) {
    return Promise.resolve({
      username: username,
      permissions: "*"
    });

```

with

```auto
  users: {[username: "youremail@domain.com" , permissions: "*"]} 

```

like you would with the standard "credentials" login type.

One last thing: once you're logged in, your google profile picture show up in the upper right hand corner next to the hamburger menu. 🙂

---

<div class="post-metadata">

### Author: ![rsingh888](https://avatars.discourse-cdn.com/v4/letter/r/e0b2c6/32.png) [@rsingh888](https://discourse.nodered.org/u/rsingh888)
#### Post date: [27 October 2023 05:49 UTC](https://discourse.nodered.org/t/authenticating-into-node-red-using-google-oauth-working-solution/10047/7 "2023-10-27T05:49:53Z")

</div>

Have tried the same configuration but its unable to load settings file  
Error loading settings file:

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [27 October 2023 07:47 UTC](https://discourse.nodered.org/t/authenticating-into-node-red-using-google-oauth-working-solution/10047/8 "2023-10-27T07:47:35Z")

</div>

> [@rsingh888](#):
>
> unable to load settings file

Did you read the post I immediately above yours?

> [@fixjunk](#):
>
> you need to install passport-google-oauth with npm or you'll get a settings error:

> [@fixjunk](#):
>
> a comma is missing after the last close bracket, e.g. `},`

---

<div class="post-metadata">

### Author: ![rsingh888](https://avatars.discourse-cdn.com/v4/letter/r/e0b2c6/32.png) [@rsingh888](https://discourse.nodered.org/u/rsingh888)
#### Post date: [27 October 2023 08:31 UTC](https://discourse.nodered.org/t/authenticating-into-node-red-using-google-oauth-working-solution/10047/9 "2023-10-27T08:31:27Z")

</div>

Managed to get it sorted, I guess I did not install passport-google-oauth from .node-red dir. Its working now. thanks

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [27 October 2023 08:57 UTC](https://discourse.nodered.org/t/authenticating-into-node-red-using-google-oauth-working-solution/10047/10 "2023-10-27T08:57:04Z")

</div>


