# Google OAuth2 issues

**URL:** https://discourse.nodered.org/t/google-oauth2-issues/3489
**Category:** General
**Created:** [27 September 2018 12:31 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489 "2018-09-27T12:31:51Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![cgallPekham](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cgallpekham/32/2831_2.png) [@cgallPekham](https://discourse.nodered.org/u/cgallPekham)
#### Post date: [27 September 2018 12:31 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/1 "2018-09-27T12:31:51Z")

</div>

I'm trying to setup Google OAuth and well, just can't seem to get it to work - I get:

**Error: invalid\_request**

Invalid parameter value for redirect\_uri: Missing authority: Localhost:1880/auth/strategy/callback

My section looks like

```auto
  adminAuth: {
       type:"strategy",
        strategy: {
            name: "google",
            label: 'Sign in with Google',
            icon:"fa-Google",
            strategy: require("passport-google-oauth20").Strategy,
            options: {
                response_type: "code",
               
                project_id: "MyProjectID",
                auth_uri: "https://accounts.google.com/o/oauth2/auth",
                token_uri: "https://www.googleapis.com/oauth2/v3/token",
                auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
         
                redirect_uris: "http://localhost:1880/auth/strategy/callback",
                javascript_origins: "http://localhost:1880",
                
                client_secret: "TheClientSecret",
                callbackURL: "Localhost:1880/auth/strategy/callback",
                clientID: "ClientIDProvidedByGoogle.apps.googleusercontent.com",
                scope: "https://www.googleapis.com/auth/userinfo.email",
                
                
            },
            verify: function(token, tokenSecret, profile, done) {
                return client_secret, clientID, token, tokenSecret, tokenuri
                done(null, profile);
            }
        },
        users: [{
            username: "MyEmail@work",
            permissions: "*"
        }]
    },

```

and the google OAuth - is Public  
ApplcationName = NodeRedTest  
Scope for APIs = email, Profile, openid  
Authorized Domains MyWorkDomain (could THIS be the issue?)

---

<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: [27 September 2018 12:56 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/2 "2018-09-27T12:56:59Z")

</div>

I can't claim to have tried this particular auth strategy, but at a glance your `verify` function doesn't look right to me - it has a bad `return` statement which shouldn't be there:

```auto
verify: function(token, tokenSecret, profile, done) {
   return client_secret, clientID, token, tokenSecret, tokenuri
   done(null, profile);
}

```

By the way, when you share code on the forum, please format it by adding three back-ticks (```) one a new line before _and_ after your code block. That makes it much easier to read and prevents any special characters (eg `<`, `>`) from being treated as html.

---

<div class="post-metadata">

### Author: ![cgallPekham](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cgallpekham/32/2831_2.png) [@cgallPekham](https://discourse.nodered.org/u/cgallPekham)
#### Post date: [27 September 2018 13:26 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/3 "2018-09-27T13:26:15Z")

</div>

The Verify is from the Twitter example. BTW, works there, and with Github, just can't get it with Google

---

<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: [27 September 2018 13:53 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/4 "2018-09-27T13:53:33Z")

</div>

Where does the twitter example have a return statement in the middle of the verify function?

> <https://github.com/node-red/node-red-auth-twitter/blob/8fb5580aeeb066a6e0c458ca6fc278f94949cb3e/lib/index.js#L50-L52>

---

<div class="post-metadata">

### Author: ![cgallPekham](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cgallpekham/32/2831_2.png) [@cgallPekham](https://discourse.nodered.org/u/cgallPekham)
#### Post date: [27 September 2018 14:19 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/5 "2018-09-27T14:19:35Z")

</div>

You are right, I missed that my co-worker added it  
Removed that return - but I still get the same error

I'm not sure where co-worker got the Google URLs, so I'm looking that up too

Is there an example oAuth2 with google around that I can look at, as I can't find one!

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [27 September 2018 14:37 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/6 "2018-09-27T14:37:16Z")

</div>

Have you tried googling “ Oauth2 Google nodejs”?

---

<div class="post-metadata">

### Author: ![cgallPekham](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cgallpekham/32/2831_2.png) [@cgallPekham](https://discourse.nodered.org/u/cgallPekham)
#### Post date: [27 September 2018 14:55 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/7 "2018-09-27T14:55:42Z")

</div>

Yes, but I must not understand how to take the examples, and change them to what we need in the Settings.js file. See lots of examples that show code, and heck, I can do it in .NET, and have done so (Hey, I'm normally a .NET guy who has gotten sucked into 'Secure our Node-red site, oh, and use OAuth2 from Google"

I'm just at the "Am I doing something wrong in the Settings.js, or in the API config side on Google, or both"

---

<div class="post-metadata">

### Author: ![cgallPekham](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cgallpekham/32/2831_2.png) [@cgallPekham](https://discourse.nodered.org/u/cgallPekham)
#### Post date: [27 September 2018 16:26 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/8 "2018-09-27T16:26:05Z")

</div>

> [@ukmoose](#):
>
> Oauth2 Google nodejs

OK - I must be REALLY doing something wrong - decided to go back to the basics - went into Postman, and decided to try and post to:

```auto
Localhost:1880/auth/strategy/callback

```

(with no token and with the token in the body as JSON)  
and either way I'm getting

```auto
Cannot POST /auth/strategy/callback

```

Any clues?

---

<div class="post-metadata">

### Author: ![bryan-ninjamoba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bryan-ninjamoba/32/21973_2.png) [@bryan-ninjamoba](https://discourse.nodered.org/u/bryan-ninjamoba)
#### Post date: [13 May 2019 08:03 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/9 "2019-05-13T08:03:38Z")

</div>

Did you get this working? - love to see it!

---

<div class="post-metadata">

### Author: ![pakerfeldt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pakerfeldt/32/3101_2.png) [@pakerfeldt](https://discourse.nodered.org/u/pakerfeldt)
#### Post date: [29 July 2019 18:44 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/10 "2019-07-29T18:44:03Z")

</div>

I managed to get something that seems to be working.

```auto
adminAuth: {
    type:"strategy",
    strategy: {
        name: "google",
        label: 'Sign in with Google',
        icon:"fa-google",
        strategy: require("passport-google-oauth20").Strategy,
        options: {
            clientID: "myId",
            clientSecret: "mySecret",
            scope: "email",
            callbackURL: "http://my-node-url.com/auth/strategy/callback",
            verify: function(token, tokenSecret, profile, done) {
                profile.username = profile.emails.constructor === Array ? profile.emails[0].value : null;
                return done(null, profile);
            }
        },
    },
    users: [
       { username: "my_email@gmail.com",permissions: ["*"]},
       { username: "some_other_user@gmail.com",permissions: ["read"]}
   ]
},

```

---

<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: [3 February 2022 15:18 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/11 "2022-02-03T15:18:24Z")

</div>

Hi All!

Did anyone tried out the Google Auth and get it working?.

Thanks a lot!

---

<div class="post-metadata">

### Author: ![umtksa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/umtksa/32/38322_2.png) [@umtksa](https://discourse.nodered.org/u/umtksa)
#### Post date: [12 February 2022 19:26 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/12 "2022-02-12T19:26:00Z")

</div>

yes I get it working  
my instance is not exposed to internet  
so I'm authorizing my google account at [google playground](https://developers.google.com/oauthplayground/)

then manually copy and paste the client secret to my inject node  
you need to do this manual process every 3 months  
it's ok for me I dont want to expose my instance to public internet.  
 ![edit](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1e92a58ec18654fbe90951f0def0c8f9dd513cce.jpeg)

Here is a screenshot of my flow, first piece authorizing me and the second piece getting data from google analytics (my web pages live user data) and throws it in a template node.

 ![google](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1bf057971f997cd98e019f08634077710003b4cb.jpeg)

And here is the rendered template node on my dashboard  
 ![Screen Shot 2022-02-12 at 22.22.20](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/a/4a304009b65c7afa54750928025b7b67ee675bbb.png)

---

<div class="post-metadata">

### Author: ![intmech](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/intmech/32/18283_2.png) [@intmech](https://discourse.nodered.org/u/intmech)
#### Post date: [13 July 2022 13:10 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/13 "2022-07-13T13:10:29Z")

</div>

would love to have a look at your flow.json if you are able to share. Thank you.

---

<div class="post-metadata">

### Author: ![umtksa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/umtksa/32/38322_2.png) [@umtksa](https://discourse.nodered.org/u/umtksa)
#### Post date: [25 July 2022 13:07 UTC](https://discourse.nodered.org/t/google-oauth2-issues/3489/14 "2022-07-25T13:07:24Z")

</div>

hi there here is the flow  
I just clean the api key from first node you need your own client secret to use it

````auto
[{"id":"a3e4e204.7aa95","type":"inject","z":"818b9061.accc5","name":"","props":[{"p":"tokengoogle","v":"9876876rvbmnöm0uAQSNwF-L9IrZeiR1REsNfmuwwLXylNJs_2RP1-sJ1Ahfgp1dDxBO_Sgdfggfdsfghjkl_ouOPLuBmDzRY&645646554356client_id=78543525656532-6aeecrdib2gdfg78hbcp3un659tgertegdfs656s0gdf3.apps.googleusercontent.com","vt":"str"}],"repeat":"1800","crontab":"","once":true,"onceDelay":"5","topic":"","payloadType":"str","x":310,"y":180,"wires":[["b83b157.44082e8"]]},{"id":"340c6f1.d5a6a9","type":"http request","z":"818b9061.accc5","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"https://oauth2.googleapis.com/token","tls":"","persist":false,"proxy":"","authType":"","x":330,"y":260,"wires":[["7f2a2a29.a8aea4"]]},{"id":"b83b157.44082e8","type":"function","z":"818b9061.accc5","name":"set payload and headers","func":"var tokenguncel = msg.tokengoogle;\n\nmsg.payload = tokenguncel;\nmsg.headers = {};\nmsg.headers['content-type'] = 'application/x-www-form-urlencoded';\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":220,"wires":[["340c6f1.d5a6a9"]]},{"id":"603a42d2.9227dc","type":"change","z":"818b9061.accc5","name":"token","rules":[{"t":"set","p":"token","pt":"msg","to":"payload.access_token","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":340,"wires":[["50a164a0.11667c"]]},{"id":"7f2a2a29.a8aea4","type":"json","z":"818b9061.accc5","name":"","property":"payload","action":"","pretty":false,"x":350,"y":300,"wires":[["603a42d2.9227dc"]]},{"id":"50a164a0.11667c","type":"change","z":"818b9061.accc5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.access_token","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":380,"wires":[["e0a7c39e.788e3"]]},{"id":"e0a7c39e.788e3","type":"change","z":"818b9061.accc5","name":"","rules":[{"t":"set","p":"token","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":420,"wires":[[]]},{"id":"dd9550db.49ca7","type":"http request","z":"818b9061.accc5","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://analytics.googleapis.com/analytics/v3/data/realtime?ids=ga%3A189270063&metrics=rt%3AactiveUsers&dimensions=rt%3Asource&access_type=offline&prompt=consent&key=7jfj87SyBl9jgk67rYaJT-zPIjf3QKIU546hfghfg4l-Jq1787Ec656","tls":"","persist":false,"proxy":"","authType":"","x":650,"y":340,"wires":[["fed0d603.7851d8"]]},{"id":"22fe6840.76cd38","type":"inject","z":"818b9061.accc5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"10","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":650,"y":220,"wires":[["5fc9c7e2.fec0d8"]]},{"id":"fed0d603.7851d8","type":"json","z":"818b9061.accc5","name":"","property":"payload","action":"obj","pretty":false,"x":670,"y":380,"wires":[["7752fb57.810384"]]},{"id":"7752fb57.810384","type":"change","z":"818b9061.accc5","name":"","rules":[{"t":"set","p":"online","pt":"msg","to":"payload.totalsForAllResults[\"rt:activeUsers\"]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":420,"wires":[["93080a2b.583878"]]},{"id":"d9b42ea0.92da2","type":"function","z":"818b9061.accc5","name":"set payload and headers","func":"var tokengelen = msg.payload;\nvar bear2 = 'Bearer, ' + tokengelen;\n\nmsg.payload = \"\";\n\nmsg.headers = {\n 'Authorization': \"Bearer \" + tokengelen,\n 'Content-Type': 'application/json'\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":300,"wires":[["dd9550db.49ca7"]]},{"id":"5fc9c7e2.fec0d8","type":"change","z":"818b9061.accc5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"token","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":260,"wires":[["d9b42ea0.92da2"]]},{"id":"93080a2b.583878","type":"ui_template","z":"818b9061.accc5","group":"d8c86af7.92aeb8","name":"analytics","order":2,"width":4,"height":4,"format":"<style>\n@import url('https://fonts.googleapis.com/css2?family=Xanh+Mono&display=swap');\n.open22{\n background-color:rgb(143, 49, 157);\n background-repeat: no-repeat;\n background-position: center;\n width: 100%;\n height:225px;\n padding-top:0px;\n \n \n}\n\np.online{\n font-family: 'Xanh Mono', monospace;\n color: #FFFFFF;\n padding-top:23px;\n font-size: 50px;\n text-align:center;\n}\n</style>\n\n\n<div class=\"open22\">\n<div><p class=\"online\">{{msg.online}}</p></div>\n</div>\n\n","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","x":840,"y":420,"wires":[[]]},{"id":"d8c86af7.92aeb8","type":"ui_group","name":"genel","tab":"c1dcfb03.ffed9","order":1,"disp":false,"width":20,"collapse":false},{"id":"c1dcfb03.ffed9","type":"ui_tab","name":"dash","icon":"dashboard","order":1}]
]```
````
