Skip to content

Commit

Permalink
Merge pull request #169 from okta/bugfixes-library-updates
Browse files Browse the repository at this point in the history
Bug fixes and library updates
  • Loading branch information
FeiChen-okta authored Jul 21, 2020
2 parents e9600e5 + 24dcfec commit 0247ab5
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ It is recommended that your app extends [FragmentActivity][fragment-activity] or
Add the `Okta OIDC` dependency to your `build.gradle` file:

```gradle
implementation 'com.okta.android:oidc-androidx:1.0.13'
implementation 'com.okta.android:oidc-androidx:1.0.14'
```

### Sample app
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ dependencies {
androidTestImplementation 'androidx.test.uiautomator:uiautomator:' + rootProject.uiautomatorVersion
androidTestImplementation 'org.hamcrest:hamcrest-integration:1.3'

androidTestImplementation 'com.github.tomakehurst:wiremock-standalone:2.25.1'
androidTestImplementation 'com.github.tomakehurst:wiremock-standalone:2.26.3'

androidTestImplementation "io.jsonwebtoken:jjwt-api:${rootProject.jsonWebTokenVersion}"
androidTestImplementation "io.jsonwebtoken:jjwt-impl:${rootProject.jsonWebTokenVersion}"
Expand Down
19 changes: 10 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'org.owasp:dependency-check-gradle:5.2.2'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'org.owasp:dependency-check-gradle:5.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -36,29 +36,30 @@ subprojects {
}

ext {
versionNum = 15
versionName = "1.0.13"
versionNum = 16
versionName = "1.0.14"
versionDate = new Date()
minSdkVersion = 19
compileSdkVersion = 29
buildToolsVersion = "29.0.3"
browserVersion = '1.2.0'
appcompatVersion = '1.1.0'
androidxCore = '1.3.0'
// SDK dependency versions
bintrayVersion = "1.8.4"
gradlePluginVersion = "1.5"
gsonVersion = "2.8.6"

// Test dependency versions
junitVersion = '4.13'
mockitoVersion = "2.13.0"
mockitoVersion = "2.28.2"
robolectricVersion = '4.3.1'
okhttpVersion = '4.3.1'
jsonWebTokenVersion = '0.10.7'
assertjCoreVersion = '3.14.0'
okhttpVersion = '4.8.0'
jsonWebTokenVersion = '0.11.2'
assertjCoreVersion = '3.16.1'
assertjVersion = "1.2.0"

androidxLibVersion = "1.2.4"
androidxLibVersion = '1.2.5'
espressoVersion = "3.2.0"
uiautomatorVersion = "2.2.0"
securityVersion = "1.0.0-alpha02"
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

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

# When configured, Gradle will run in incubating parallel mode.
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Apr 09 11:23:47 PDT 2020
#Mon Jul 20 12:51:33 PDT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dependencies {
implementation "com.google.code.gson:gson:${rootProject.gsonVersion}"
implementation "androidx.browser:browser:${rootProject.browserVersion}"
implementation "androidx.fragment:fragment:${rootProject.androidxLibVersion}"
implementation "androidx.core:core:${rootProject.appcompatVersion}"
implementation "androidx.core:core:${rootProject.androidxCore}"
testImplementation "com.squareup.okhttp3:okhttp-tls:${rootProject.okhttpVersion}"
testImplementation "io.jsonwebtoken:jjwt-jackson:${rootProject.jsonWebTokenVersion}"
testImplementation("io.jsonwebtoken:jjwt-orgjson:${rootProject.jsonWebTokenVersion}") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static com.okta.oidc.OktaAuthenticationActivity.EXTRA_EXCEPTION;
import static com.okta.oidc.OktaResultFragment.REQUEST_CODE_SIGN_IN;
import static com.okta.oidc.OktaResultFragment.REQUEST_CODE_SIGN_OUT;
import static com.okta.oidc.util.AuthorizationException.AuthorizationRequestErrors.OTHER;

/**
* @hide Handle the call back data from chrome custom tabs.
Expand Down Expand Up @@ -83,8 +84,8 @@ private StateResult handleAuthenticationResult(int requestCode, int resultCode,
result = StateResult.exception(AuthorizationException
.fromJson(data.getExtras().getString(EXTRA_EXCEPTION, "")));
} catch (NullPointerException | IllegalArgumentException e) {
result = StateResult.exception(
AuthorizationException.AuthorizationRequestErrors.OTHER);
result = StateResult.exception(new AuthorizationException(OTHER.code,
e.getMessage(), e));
} catch (JSONException je) {
result = StateResult.exception(
AuthorizationException.GeneralErrors.JSON_DESERIALIZATION_ERROR);
Expand Down
5 changes: 4 additions & 1 deletion library/src/main/java/com/okta/oidc/Tokens.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package com.okta.oidc;

import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
Expand Down Expand Up @@ -62,7 +64,8 @@ public class Tokens {
public Tokens(@NonNull TokenResponse response) {
this(response.getIdToken(), response.getAccessToken(),
response.getRefreshToken(), Integer.parseInt(response.getExpiresIn()),
response.getScope().split(" "), response.getExpiresAt());
TextUtils.isEmpty(response.getScope()) ? null : response.getScope().split(" "),
response.getExpiresAt());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import java.io.IOException;
import java.lang.ref.WeakReference;

import static com.okta.oidc.util.AuthorizationException.AuthorizationRequestErrors.OTHER;

class SyncAuthClientImpl extends AuthAPI implements SyncAuthClient {
private SyncSessionClient sessionClient;

Expand Down Expand Up @@ -110,7 +112,7 @@ public Result signIn(String sessionToken, @Nullable AuthenticationPayload payloa
} catch (IOException e) {
return Result.cancel();
} catch (Exception e) {
return Result.error(AuthorizationException.AuthorizationRequestErrors.OTHER);
return Result.error(new AuthorizationException(OTHER.code, e.getMessage(), e));
} finally {
resetCurrentState();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void signOut(@NonNull final Activity activity, int flags,
}

private void cancelFuture() {
if (mFutureTask != null && (!mFutureTask.isDone() || !mFutureTask.isCancelled())) {
if (mFutureTask != null && (!mFutureTask.isDone() && !mFutureTask.isCancelled())) {
mFutureTask.cancel(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class ConnectionParameters {
*/
@RestrictTo(RestrictTo.Scope.LIBRARY)
public static final String USER_AGENT_HEADER = "okta-oidc-android/" + Build.VERSION.SDK_INT +
" " + BuildConfig.APPLICATION_ID + "/" + BuildConfig.VERSION_NAME;
" " + BuildConfig.LIBRARY_PACKAGE_NAME + "/" + BuildConfig.VERSION_NAME;

/**
* The enum Request method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,14 +781,24 @@ public AuthorizationException(
}

/**
* Instantiates an authorization request with description and root cause information.
* Instantiates an authorization exception with description and root cause information.
*/
public AuthorizationException(
@NonNull String errorDescription,
@Nullable Throwable rootCause) {
this(TYPE_GENERAL_ERROR, TYPE_GENERAL_ERROR, null, errorDescription, null, rootCause);
}

/**
* Instantiates an authorization exception with error code, description and root cause.
*/
public AuthorizationException(
int code,
@NonNull String errorDescription,
@Nullable Throwable rootCause) {
this(TYPE_GENERAL_ERROR, code, null, errorDescription, null, rootCause);
}

/**
* Produces a JSON representation of the authorization exception, for transmission or
* withStorage. This does not include any provided root cause.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 27)
Expand Down Expand Up @@ -234,6 +235,8 @@ public void onActivityResultEmptyIntent() throws InterruptedException {
assertNotNull(stateResult[0]);
assertEquals(stateResult[0].getStatus(), Status.ERROR);
assertEquals(stateResult[0].getException().code, AuthorizationRequestErrors.OTHER.code);
assertNotNull(stateResult[0].getException().getCause());
assertTrue(stateResult[0].getException().getCause() instanceof NullPointerException);
assertEquals(stateType[0], ResultType.SIGN_IN);
assertNull(AuthenticationResultHandler.handler().mCachedResult);
assertNull(AuthenticationResultHandler.handler().mCachedResultType);
Expand Down
17 changes: 17 additions & 0 deletions library/src/test/java/com/okta/oidc/TokensTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;


import static com.okta.oidc.util.TestValues.ACCESS_TOKEN;
import static com.okta.oidc.util.TestValues.ID_TOKEN;
import static com.okta.oidc.util.TestValues.REFRESH_TOKEN;
Expand All @@ -33,6 +34,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

@RunWith(RobolectricTestRunner.class)
Expand All @@ -47,6 +49,21 @@ public class TokensTest {
INVALID_EXPIRES_IN,
TextUtils.join(" ", VALID_SCOPES));

@Test
public void validateEmptyScopeIsAccepted() {
Tokens tokens = new Tokens(ID_TOKEN,
ACCESS_TOKEN,
REFRESH_TOKEN,
VALID_EXPIRES_IN,
null, System.currentTimeMillis());
assertNotNull(tokens);
assertEquals(ACCESS_TOKEN, tokens.getAccessToken());
assertEquals(REFRESH_TOKEN, tokens.getRefreshToken());
assertEquals(ID_TOKEN, tokens.getIdToken());
assertEquals(VALID_EXPIRES_IN, tokens.getExpiresIn());
assertNull(tokens.getScope());
}

@Test
public void validateTokenInit() {
Tokens tokens = new Tokens(ID_TOKEN,
Expand Down

0 comments on commit 0247ab5

Please sign in to comment.