Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a OAuth2 authorization code that can be shared with a server

My Android app needs to send an authorization code to my server so that the server can use that to acquire an access token for the user's Google Drive account. I have been trying to figure out how to acquire the authorization code and I found this in the Google API documentation (Using OAuth 2.0 for Installed Applications):

This sequence starts by redirecting a browser (system browser or embedded in the application as a web view) to a Google URL with a set of query parameters that indicate the type of Google API access the application requires. Like other scenarios, Google handles the user authentication and consent, but the result of the sequence is an authorization code. The authorization code is returned in the title bar of the browser or as a query string parameter (depends on the parameters sent in the request).

After receiving the authorization code, the application can exchange the code for an access token and a refresh token. The application presents its client_id and client_secret (obtained during application registration) and the authorization code during this exchange. Upon receipt of the refresh token, the application should store it for future use. The access token gives your application access to a Google API.

Now I am not sure how to get this authorization code in my Android app since the Android examples I have seen seem to get the access tokens directly. I am looking at the Android AccountManager class and it has a method getAuthToken but this seems to refer to the access token and not the authorization code.

So how does one acquire the authorization code that can be shared with a server? If it is possible I would greatly appreciate some example code. If this is not possible what are the possible workarounds?

like image 457
charles young Avatar asked May 23 '13 22:05

charles young


1 Answers

You may want to take a look at the Cross-client Identity document. It should keep you from needing to pass user tokens back and forth.

like image 132
Jay Lee Avatar answered Sep 28 '22 18:09

Jay Lee