Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Crossing Platforms With Google+ Sign-In

Ian Barber
September 27, 2013

Crossing Platforms With Google+ Sign-In

A brief look at some of the challenges of existing in a multi-device world, the benefits of having an identity to transition state between environments, and how the Google identity infrastructure and Google+ sign-in can help with that.

#ota13

Ian Barber

September 27, 2013
Tweet

More Decks by Ian Barber

Other Decks in Programming

Transcript

  1. <script type="application/ld+json"> { "@context": "http://schema.org", "@type": "FlightReservation", "reservationNumber": "RXJ34P", "underName":

    { "@type": "Person", "name": "Eva Green" }, "reservationFor": { "@type": "Flight", "flightNumber": "110", "airline": { "@type": "Airline", "name": "United", "iataCode": "UA" }...
  2. PlusShare.Builder builder = new PlusShare.Builder(this, mPlusClient); builder.addCallToAction("APPLY", callToActionUrl, callToActionDeepLinkId); builder.setContentUrl(linkUrl);

    builder.setContentDeepLinkId(deepLinkId, null, null, null); builder.setText(mEditSendText.getText().toString()); return builder.getIntent();
  3. // ... in didFinishLaunchingWithOptions [GPPDeepLink setDelegate:self]; [GPPDeepLink readDeepLinkAfterInstall]; - (BOOL)application:(UIApplication

    *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]; }
  4. gapi.signin.render(id, { 'clientid': '123456789.apps.googleusercontent.com', 'callback': 'signInCallback', 'cookiepolicy': 'single_host_origin', 'requestvisibleactions': 'http://schemas.google.com/AddActivity',

    'scope': 'https://www.googleapis.com/auth/plus.login ' + 'https://www.googleapis.com/auth/userinfo.email', 'accesstype': 'offline', 'apppackagename': 'deezer.android.app' });
  5. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sign_in_activity); mPlusClient =

    new PlusClient.Builder(this, this, this) .setScopes(Scopes.PLUS_LOGIN) .setVisibleActivities(MomentUtil.VISIBLE_ACTIVITIES) .build(); } @Override public void onStart() { super.onStart(); mPlusClient.connect(); }
  6. @Override public void onConnected(Bundle connectionHint) { String currentPersonName = mPlusClient.getCurrentPerson().getDisplayName();

    } @Override public void onConnectionFailed(ConnectionResult result) { mConnectionResult = result; }
  7. // In didFinishLaunchingWithOptions [[GPPSignIn sharedInstance] setClientID:@"YOUR_CLIENT_ID"]; [[GPPSignIn sharedInstance] setDelegate:self]; [[GPPSignIn

    sharedInstance] trySilentAuthentication]; // In view controller, trigger sign in [[GPPSignIn sharedInstance] authenticate]
  8. // In the sign-in delegate - (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error

    { if (error) { NSLog(@"Sign-In Error: %@", error); [[GPPSignIn sharedInstance] signOut]; } else { // We're signed in! } }
  9. $opts = array( 'http' => array( 'method' => 'POST', 'header'

    => 'Content-type: application/x-www-form-urlencoded', 'content' => "client_id=" . $clientId . "&scope=https://www.googleapis.com/auth/plus.me")); $ctx = stream_context_create($opts); $result = file_get_contents( "https://accounts.google.com/o/oauth2/device/code", false, $ctx); $result = json_decode($result); $code = $result->user_code;
  10. Device Google User Request Device Code Device Code Request Token

    For Code Error Enter Code Display Consent Grant Consent Request Token For Code Access Token Google Display Code
  11. function OnLoadCallback() { sessionParams = { 'client_id': 'YOUR_CLIENT_ID_HERE', 'session_state': null

    }; gapi.auth.checkSessionState(sessionParams, function(stateMatched) { if (stateMatched == true) { // Logged out } else { // Logged in } }); }
  12. public void onStateLoaded( int statusCode, int stateKey, byte[] data) {

    if (statusCode == AppStateClient.STATUS_OK) { try { String s = new String(data,"UTF-8"); SquashView sv = (SquashView)findViewById(R.id.squashView); sv.mScore = Integer.parseInt(s); } catch (Exception e) { e.printStackTrace(); } } else { Log.e("MultiSquash", "failed because: " + statusCode); } }
  13. GPGAppStateModel *model = [GPGManager sharedInstance].applicationModel.appState; NSNumber *slot = @0; [model

    loadForKey:slot completionHandler: ^(GPGAppStateLoadStatus status, NSError *error) { if (status == GPGAppStateLoadStatusSuccess) { NSData *data = [model stateDataForKey:slot]; NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSInteger value = [str intValue]; [self updatePreviousScoreWithData:value]; } } conflictHandler: ^NSData *(NSNumber *key, NSData *local, NSData *remote) { return remoteState; }];