Skip to content
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
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
*.iml
.gradle
.gradle/
/local.properties
/.idea/workspace.xml
/.idea/libraries

.idea/

.DS_Store
/build
/captures
/build/
/captures/
.externalNativeBuild
19 changes: 0 additions & 19 deletions .idea/gradle.xml

This file was deleted.

33 changes: 0 additions & 33 deletions .idea/misc.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/modules.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

48 changes: 31 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ MobileAuthentication supports Android API 23 and above so AES encryption can be

## Getting Started
project build.gradle:
```
```groovy
allprojects {
repositories {
...
Expand All @@ -16,7 +16,7 @@ allprojects {
```

app build.gradle:
```
```groovy
dependencies {
implementation "com.github.bcgov:mobile-authentication-android:<LATEST_VERSION>"
}
Expand All @@ -25,20 +25,34 @@ dependencies {
### Prerequisites
A Red Hat Single Sign-On server component that is setup to handle an OAuth2 authorization code flow.

### Android Manifest
You will need to add this to your AndroidManifest and specify what custom schema you're using in your redirectUri.
```xml
<activity android:name="ca.bc.gov.mobileauthentication.screens.redirect.RedirectActivity"
android:launchMode="singleInstance">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="<YOUR_CUSTOM_SCHEME_USED_IN_REDIRECT_URI>" />
</intent-filter>
</activity>
### Handling Custom Scheme Redirects

Specify the redirect value by setting the manifest placeholder value `appAuthRedirectScheme` in your project's build.gradle file:

```groovy
android {
defaultConfig {
...

manifestPlaceholders = [
'appAuthRedirectScheme': '<YOUR_CUSTOM_SCHEME_USED_IN_REDIRECT_URI>'
]

...
}
}
```

Only the scheme is required:

> 'appAuthRedirectScheme': 'custom-scheme' <- happiness

Adding any more isn't valid:

> 'appAuthRedirectScheme': 'custom-scheme://somePath' <- runtime issues

***Note:*** you were previously required to add RedirectActivity with an intent filter to your application's manifest. This is no longer required because the functionality is handled by this manifest placeholder value.

## Usage
There are four main commands for handling tokens that will be called using the MobileAuthenticationClient class.
1. Authenticate
Expand All @@ -62,7 +76,7 @@ The parameters needed for the client can all be found on your Red Hat Single Sig

The hint param is optional and can be used to directly send the user to the specified login.

We recommened you use a custom application schema for your redirectUri such as <NAME_OF_YOUR_APP>://android
We recommend you use a custom application schema for your redirectUri such as <NAME_OF_YOUR_APP>://android

Please use the context of the activity in which you are going to call authenticate to create the client.

Expand Down Expand Up @@ -100,7 +114,7 @@ If the token is expired and the refresh token is NOT expired the token will auto

Exceptions:
1. If there is no token locally a `TokenNotFoundException` will be thrown in the onError of the TokenCallback. This means the user has not yet been authenticated so no token exists locally.
2. If the token's refresh token is expired a `RefreshExpiredException` will be thrown in the onError of the TokenCallback. In this case the user will need to reauthenticate.
2. If the token's refresh token is expired a `RefreshExpiredException` will be thrown in the onError of the TokenCallback. In this case the user will need to re-authenticate.
3. If the token does not have a refresh token then a `NoRefreshTokenException` will be thrown in the onError of the TokenCallback. This means the Token data being returned does not contain the required refreshToken for this lib to work.

Calling getToken:
Expand Down Expand Up @@ -130,7 +144,7 @@ client?.getToken(object: MobileAuthenticationClient.TokenCallback {
Refresh token will refresh the locally stored token.

Exceptions:
1. If the token's refresh token is expired a `RefreshExpiredException` will be thrown in the onError of the TokenCallback. In this case the user will need to reauthenticate.
1. If the token's refresh token is expired a `RefreshExpiredException` will be thrown in the onError of the TokenCallback. In this case the user will need to re-authenticate.
2. If the token does not have a refresh token then a `NoRefreshTokenException` will be thrown in the onError of the TokenCallback. This means the Token data being returned does not contain the required refreshToken for this lib to work.

Calling refreshToken:
Expand Down
34 changes: 25 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,48 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 26

defaultConfig {
compileSdkVersion rootProject.ext.compileSdkVersion
applicationId "ca.bc.gov.mobileauthenticationandroidexample"
minSdkVersion 23
targetSdkVersion 26
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'

manifestPlaceholders = [
/*
Instead of an <intent-filter> in AndroidManifest.xml the redirectUri scheme is
defined here. Only give the scheme itself:

'appAuthRedirectScheme': 'custom-scheme' <- happiness

Adding any more isn't valid:

'appAuthRedirectScheme': 'custom-scheme://somePath' <- runtime issues
*/
'appAuthRedirectScheme': 'secure-image'
]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
namespace 'ca.bc.gov.mobileauthenticationandroidexample'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':mobileauthentication')

implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "com.android.support:appcompat-v7:26.1.0"
implementation "com.android.support.constraint:constraint-layout:1.0.2"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation "junit:junit:4.12"

androidTestImplementation "com.android.support.test:runner:1.0.1"
androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.1"
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
17 changes: 3 additions & 14 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ca.bc.gov.mobileauthenticationandroidexample">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand All @@ -14,24 +13,14 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="ca.bc.gov.mobileauthentication.screens.redirect.RedirectActivity"
android:launchMode="singleInstance">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="secure-image" />
</intent-filter>
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ca.bc.gov.mobileauthenticationandroidexample

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import ca.bc.gov.mobileauthentication.MobileAuthenticationClient
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ca.bc.gov.mobileauthenticationandroidexample.MainActivity">

</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.21'
ext.kotlinVersion = '1.7.10'

ext.compileSdkVersion = 28
ext.minSdkVersion = 23
ext.targetSdkVersion = 26

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Feb 07 13:43:17 PST 2018
#Mon Sep 19 11:37:24 PDT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
zipStoreBase=GRADLE_USER_HOME
Loading