https://github.com/googleapis/google-api-nodejs-client/blob/master/samples/drive/list.js doesn't work
root@docker:~/gg# cat oauth2.keys.json
{
"web" : {
"redirect_uris": [
"https://hello.example.net"
],
"client_id": "10xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxontent.com",
"client_secret": "5fS6xxxxxxxxxxxxxxxxxxf0w",
"project_id": "maxxxxxxxxxxxxxx76211"
}
}
root@docker:~/gg# node e.js
Error: The provided keyfile does not define a valid
redirect URI. There must be at least one redirect URI defined, and this sample
assumes it redirects to 'http://localhost:3000/oauth2callback'. Please edit
your keyfile, and add a 'redirect_uris' section. For example:
"redirect_uris": [
"http://localhost:3000/oauth2callback"
]
at authenticate (/root/gg/node_modules/@google-cloud/local-auth/build/src/index.js:56:15)
at runSample (/root/gg/e.js:11:22)
at Object.<anonymous> (/root/gg/e.js:25:3)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
what's wrong?!
@itstheusername the sample expects that your would have http://localhost:3000/oauth2callback as your redirect URI, it looks like you're using https://hello.example.net? Mind trying the recommended URL?
@bcoe i tried http://localhost:3000/oauth2callback
then i opened on browser my-server-ip:3000/oauth2callback
and it returned
Authentication successful! Please return to the console.
after that console shows
TypeError: Cannot read property 'code' of null
at OAuth2Client.getTokenAsync (/root/gg/node_modules/google-auth-library/build/src/auth/oauth2client.js:115:27)
at OAuth2Client.getToken (/root/gg/node_modules/google-auth-library/build/src/auth/oauth2client.js:109:25)
at Server.http.createServer (/root/gg/node_modules/@google-cloud/local-auth/build/src/index.js:78:53)
at Server.emit (events.js:198:13)
at parserOnIncoming (_http_server.js:691:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:111:17)
something tells me that http://localhost:3000/oauth2callback is expecting some kind of code maybe authorization code?
i was thinking to try something like
https://accounts.google.com/signin/oauth/oauthchooseaccount?client_id=10157xxxxxxxxxsercontent.com&redirect_uri=http://localhost:3000/oauth2callback&response_type=code&access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&approval_prompt=auto&o2v=1&flowName=GeneralOAuthFlow
but this fails because as i'm trying to use my server ip it says raw ip not allowed and if i point my server ip to a domain name when i try to add that domain on my google app it says

maybe i'm doing it wrong 馃槙
Taking a few steps back :) The sample you're using is set up to allow showing an easy end to end workflow. In this workflow:
code querystring parameter to set on the OAuth2 client.These are a lot of steps to just see bits flow through the wires :) We use the @google-cloud/local-auth module to abstract some of the messiness around standing up a web server, accepting an HTTP request from the redirect URI, and setting the credentials on the OAuth2 instances that is passed to the client. I think that's what is tripping you up. If you want to use this in production, you really need to read through and understand the 3-legged OAuth2 flow described in the docs.
Hope this helps!
Thanks