Search code examples
oauth-2.0google-oauth

How to use Google OAuth2.0 without out-of-band (OOB)


I have created new OAuth 2.0 Client IDs (application type = Desktop app). Then downloaded the OAuth client JSON file. Put the file into the folder where my code is looking. When I run the code locally on my PC it`s try to open following URL:

https://accounts.google.com/o/oauth2/auth?client_id={my_client_id}&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope={my_scope}&access_type=offline&response_type=code

and that is what I expect. Since the downloaded OAuth client has the parameter "redirect_uris":["http://localhost"]. So I expected the same thing when I ran this same code on the ubuntu server, but nope. The URL it proposes me visit is

https://accounts.google.com/o/oauth2/auth?client_id={my_client_id}&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope={my_scope}&access_type=offline&response_type=code

And here is the problem, I don't understand what I have to do to make my server pass this authorization. I already tried to manually change this parameter of redirect_uris before visiting the destination to the same one I had on my local computer - to http%3A%2F%2Flocalhost%3A8080%2F, but I got this error in the browser:enter image description here

Who can help me? What should I do?


Solution

  • Developers using installed applications need to stitch to using IP flow.

    Loopback IP address (macOS, Linux, Windows desktop)

    A key point on that page is

    To receive the authorization code using this URL, your application must be listening on the local web server.

    So as directed you would use http://127.0.0.1:port or http://[::1]:port The fact that you are getting a page not found is working as intended as you just have not set up the local web server as directed in the documetnation.

    The authorization code needed for authorization can still be found in the URL browser. Currently this is the only information we have from Google and there is no other solution.