Skip to content
This repository was archived by the owner on Aug 3, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions appauth-android_codelab_sso_managed/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 25
buildToolsVersion '25.0.0'

defaultConfig {
applicationId "com.google.codelabs.appauth"
minSdkVersion 21
targetSdkVersion 23
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
manifestPlaceholders = ['appAuthRedirectScheme': 'com.google.codelabs.appauth']

}
buildTypes {
release {
Expand All @@ -22,9 +24,9 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'net.openid:appauth:0.2.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'net.openid:appauth:0.6.0'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package com.google.codelabs.appauth;

import android.app.PendingIntent;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand All @@ -24,7 +23,6 @@
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.os.UserManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand All @@ -47,6 +45,7 @@
import net.openid.appauth.AuthorizationResponse;
import net.openid.appauth.AuthorizationService;
import net.openid.appauth.AuthorizationServiceConfiguration;
import net.openid.appauth.ResponseTypeValues;
import net.openid.appauth.TokenResponse;

import org.json.JSONException;
Expand Down Expand Up @@ -186,7 +185,7 @@ private void handleAuthorizationResponse(@NonNull Intent intent) {
AuthorizationException error = AuthorizationException.fromIntent(intent);
final AuthState authState = new AuthState(response, error);
if (response != null) {
Log.i(LOG_TAG, String.format("Handled Authorization Response %s ", authState.toJsonString()));
Log.i(LOG_TAG, String.format("Handled Authorization Response %s ", authState.jsonSerializeString()));
AuthorizationService service = new AuthorizationService(this);
service.performTokenRequest(response.createTokenExchangeRequest(), new AuthorizationService.TokenResponseCallback() {
@Override
Expand All @@ -207,7 +206,7 @@ public void onTokenRequestCompleted(@Nullable TokenResponse tokenResponse, @Null

private void persistAuthState(@NonNull AuthState authState) {
getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE).edit()
.putString(AUTH_STATE, authState.toJsonString())
.putString(AUTH_STATE, authState.jsonSerializeString())
.commit();
enablePostAuthorizationFlows();
}
Expand All @@ -225,7 +224,7 @@ private AuthState restoreAuthState() {
.getString(AUTH_STATE, null);
if (!TextUtils.isEmpty(jsonString)) {
try {
return AuthState.fromJson(jsonString);
return AuthState.jsonDeserialize(jsonString);
} catch (JSONException jsonException) {
// should never happen
}
Expand All @@ -248,15 +247,16 @@ public AuthorizeListener(@NonNull MainActivity mainActivity) {
public void onClick(View view) {
AuthorizationServiceConfiguration serviceConfiguration = new AuthorizationServiceConfiguration(
Uri.parse("https://accounts.google.com/o/oauth2/v2/auth") /* auth endpoint */,
Uri.parse("https://www.googleapis.com/oauth2/v4/token") /* token endpoint */
Uri.parse("https://www.googleapis.com/oauth2/v4/token") /* token endpoint */,
null /*registr ndpoint*/
);
AuthorizationService authorizationService = new AuthorizationService(view.getContext());
String clientId = "511828570984-fuprh0cm7665emlne3rnf9pk34kkn86s.apps.googleusercontent.com";
Uri redirectUri = Uri.parse("com.google.codelabs.appauth:/oauth2callback");
AuthorizationRequest.Builder builder = new AuthorizationRequest.Builder(
serviceConfiguration,
clientId,
AuthorizationRequest.RESPONSE_TYPE_CODE,
ResponseTypeValues.CODE,
redirectUri
);
builder.setScopes("profile");
Expand All @@ -271,7 +271,8 @@ public void onClick(View view) {

AuthorizationRequest request = builder.build();
String action = "com.google.codelabs.appauth.HANDLE_AUTHORIZATION_RESPONSE";
Intent postAuthorizationIntent = new Intent(action);
Intent postAuthorizationIntent = new Intent(view.getContext(), MainActivity.class);
postAuthorizationIntent.setAction(action);
PendingIntent pendingIntent = PendingIntent.getActivity(view.getContext(), request.hashCode(), postAuthorizationIntent, 0);
authorizationService.performAuthorizationRequest(request, pendingIntent);
}
Expand Down
2 changes: 1 addition & 1 deletion appauth-android_codelab_sso_managed/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.3.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down