-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mobile authentication library module Added example use of mobile authentication library module
- Loading branch information
Aidan Laing
committed
Feb 7, 2018
1 parent
071ff19
commit e884bd6
Showing
47 changed files
with
2,074 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
app/src/main/java/ca/bc/gov/mobileauthenticationandroidexample/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,108 @@ | ||
package ca.bc.gov.mobileauthenticationandroidexample | ||
|
||
import android.content.Intent | ||
import android.support.v7.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.util.Log | ||
import ca.bc.gov.mobileauthentication.MobileAuthenticationClient | ||
import ca.bc.gov.mobileauthentication.common.exceptions.NoRefreshTokenException | ||
import ca.bc.gov.mobileauthentication.common.exceptions.RefreshExpiredException | ||
import ca.bc.gov.mobileauthentication.common.exceptions.TokenNotFoundException | ||
import ca.bc.gov.mobileauthentication.data.models.Token | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
private var client: MobileAuthenticationClient? = null | ||
|
||
private val tag = "MOBILE_AUTH" | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
val authEndpoint = "https://dev-sso.pathfinder.gov.bc.ca/auth/realms/mobile/protocol/openid-connect/auth" | ||
val baseUrl = "https://dev-sso.pathfinder.gov.bc.ca/" | ||
val clientId = "secure-image" | ||
val realmName = "mobile" | ||
val redirectUri = "bcgov://android" | ||
|
||
client = MobileAuthenticationClient(this, baseUrl, realmName, | ||
authEndpoint, redirectUri, clientId) | ||
|
||
client?.authenticate() | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
client?.clear() | ||
} | ||
|
||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
super.onActivityResult(requestCode, resultCode, data) | ||
client?.handleAuthResult(requestCode, resultCode, data, object: MobileAuthenticationClient.TokenCallback { | ||
override fun onError(throwable: Throwable) { | ||
Log.e(tag, throwable.message) | ||
} | ||
override fun onSuccess(token: Token) { | ||
Log.d(tag, "Authenticate Success") | ||
getToken() | ||
} | ||
}) | ||
} | ||
|
||
private fun getToken() { | ||
client?.getToken(object: MobileAuthenticationClient.TokenCallback { | ||
override fun onError(throwable: Throwable) { | ||
when (throwable) { | ||
is RefreshExpiredException -> { | ||
Log.e(tag, "Refresh token is expired. Please re-authenticate.") | ||
} | ||
is NoRefreshTokenException -> { | ||
Log.e(tag, "No Refresh token associated with Token") | ||
} | ||
is TokenNotFoundException -> { | ||
Log.e(tag, "No Token was found") | ||
} | ||
} | ||
} | ||
|
||
override fun onSuccess(token: Token) { | ||
Log.d(tag, "Get Success") | ||
refreshToken() | ||
} | ||
}) | ||
} | ||
|
||
private fun refreshToken() { | ||
client?.refreshToken(object: MobileAuthenticationClient.TokenCallback { | ||
override fun onError(throwable: Throwable) { | ||
Log.e(tag, throwable.message) | ||
when (throwable) { | ||
is RefreshExpiredException -> { | ||
Log.e(tag, "Refresh token is expired. Please re-authenticate.") | ||
} | ||
is NoRefreshTokenException -> { | ||
Log.e(tag, "No Refresh token associated with Token") | ||
} | ||
} | ||
} | ||
|
||
override fun onSuccess(token: Token) { | ||
Log.d(tag, "Refresh Success") | ||
deleteToken() | ||
} | ||
}) | ||
} | ||
|
||
private fun deleteToken() { | ||
client?.deleteToken(object: MobileAuthenticationClient.DeleteCallback { | ||
override fun onError(throwable: Throwable) { | ||
Log.e(tag, throwable.message) | ||
} | ||
|
||
override fun onSuccess() { | ||
Log.d(tag, "Delete Success") | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
apply plugin: 'kotlin-android' | ||
|
||
apply plugin: 'kotlin-android-extensions' | ||
|
||
android { | ||
|
||
compileSdkVersion 26 | ||
|
||
defaultConfig { | ||
minSdkVersion 23 | ||
targetSdkVersion 26 | ||
compileSdkVersion 26 | ||
buildToolsVersion '26.0.2' | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
postprocessing { | ||
removeUnusedCode false | ||
removeUnusedResources false | ||
obfuscate false | ||
optimizeCode false | ||
proguardFile 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
|
||
implementation "com.android.support:appcompat-v7:26.1.0" | ||
implementation "com.android.support:customtabs:26.1.0" | ||
implementation "com.android.support.constraint:constraint-layout:1.0.2" | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.21" | ||
|
||
implementation "io.reactivex.rxjava2:rxandroid:2.0.1" | ||
implementation "io.reactivex.rxjava2:rxjava:2.1.7" | ||
implementation "io.reactivex.rxjava2:rxkotlin:2.2.0" | ||
|
||
implementation "com.squareup.retrofit2:retrofit:2.3.0" | ||
implementation "com.squareup.retrofit2:converter-gson:2.3.0" | ||
implementation "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0" | ||
implementation "com.squareup.okhttp3:logging-interceptor:3.9.1" | ||
|
||
testImplementation "junit:junit:4.12" | ||
testImplementation "com.nhaarman:mockito-kotlin:1.5.0" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="ca.bc.gov.mobileauthentication"> | ||
|
||
<application> | ||
|
||
<activity | ||
android:name="ca.bc.gov.mobileauthentication.screens.redirect.RedirectActivity" | ||
android:theme="@style/AppTheme" /> | ||
|
||
</application> | ||
|
||
</manifest> |
Oops, something went wrong.