Coder Social home page Coder Social logo

kleopatra999 / crossclientoauth2-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from googlearchive/drive-crossclientoauth2-android

0.0 2.0 0.0 1.42 MB

Cross-client authorization sample for Android

License: Apache License 2.0

Java 100.00%

crossclientoauth2-android's Introduction

Cross-Client OAuth 2.0 for Android

It's very common to build software with multiple components: a mobile app, Web back-end and etc. You Drive app should be in the same category and requires you to manage user authorization for multiple entities of the sample app. Google's OAuth 2.0 implementation provides some extentions to address the following cases:

  • Resolving user identity on Android apps without requiring the user to sign-in, if the user has already connected himself/herself on the Web application.
  • Enabling an Android app to retrieve an exchange code for its server-side component.

Warning: These extentions are only available if authorization scopes contain https://www.googleapis.com/auth/plus.login for now.

Configuration

Create or reuse a project on API console. You need to create two client IDs; one for your Web app, the other for your Android app.

Configure the sample with your Web app CLIENT_ID and the scopes required.

final private String CLIENT_ID = "abc123.apps.googleusercontent.com";
final private List<String> SCOPES = Arrays.asList(new String[]{
    "https://www.googleapis.com/auth/plus.login",
    "https://www.googleapis.com/auth/drive"
});

Resolve user identity with no sign-in

Retrieve an JSON Web Token (JWT) to identify user. You can exchange the JWT payload with your server-side to decrypt and identify user with his/her email address.

String scope = "audience:server:client_id:" + CLIENT_ID;
String idToken = GoogleAuthUtil.getToken(context, accountName, scope);

Retrieve access/refresh tokens for the server

String scope = String.format("oauth2:server:client_id:%s:api_scope:%s", CLIENT_ID, TextUtils.join(" ", SCOPES));
String exchangeCode = GoogleAuthUtil.getToken(context, accountName, scope);

Send the code to the server and exchange your code with Google to retrieve an access and a refresh token for your server-side.

POST https://accounts.google.com/o/oauth2/token
Content-Type: application/x-www-form-urlencoded

code=<exchangeCode>&
client_id=<CLIENT_ID>&
client_secret=<CLIENT_SECRET>&
grant_type=authorization_code

More details are explained on Google Drive's Cross-client Identity docs.

crossclientoauth2-android's People

Contributors

rakyll avatar

Watchers

rosa maria palacios juncosa avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.