Sayo Oladeji
Sayo Oladeji

Reputation: 741

The State Parameter in the Google OAuth 2 Process in Java

Please I need a quick help on how to add the "state" parameter to a authorization request to the Google OAuth 2 service using the Java Client Library. According to the docs, the OAuth provider is said to roundtrip this parameter to keep an application state through the authorzation process. My app needs this to determine which user is doing what. I've searched online and I've come across a lot of junks. Please help me out, I'm running out of time. Thanks.

Upvotes: 2

Views: 2079

Answers (2)

Sayo Oladeji
Sayo Oladeji

Reputation: 741

Using the class com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAuthorizationRequestUrl, set the clientID, redirectURL and scope. Then call the build() method to build the request string then append &state=stateData to the string (where stateData is the data you want to roundtrip).

Hope this helps other people.

Upvotes: 1

Jan Gerlinger
Jan Gerlinger

Reputation: 7415

At some time (depending on your implementation) you have an instance of AuthorizationRequestUrl. Call its setState(String state) method to set the state parameter.

Upvotes: 1

Related Questions