googleapis / google-oauth-java-client

Google OAuth Client Library for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

newAuthorizationUrl: Missing required parameter: redirect_uri

RiccardoManzan opened this issue · comments

Environment details

OS type and version: Linux / Ubuntu
Java version: 11
google-oauth-client version(s): 1.31.4
App environment: Micronaut + kotlin

Steps to reproduce

Executing code below generates an url without redirect_uri value

Code example

val flow = GoogleAuthorizationCodeFlow.Builder(
            GoogleNetHttpTransport.newTrustedTransport(),
            GsonFactory.getDefaultInstance(),
            env.get("google-oauth2.google.client-id", String::class.java).get(),
            env.get("google-oauth2.google.client-secret", String::class.java).get(),
            listOf(DriveScopes.DRIVE)
).setDataStoreFactory(FileDataStoreFactory("datastore"))
            .setAccessType("offline")
            .build()
val uri = authService.authorizationCodeFlow.newAuthorizationUrl()
            .setRedirectUri("/auth/google/callback")
            .toURI()

resulting uri:

https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=############-################################.apps.googleusercontent.com&redirect_uri&response_type=code&scope=https://www.googleapis.com/auth/drive

The problem was browser chaching that was redirecting me to a previous wrong route.
Futhermore you should specify full domain, and not only root relative one ("https://######/auth/google/callback").