Skip to content

Commit

Permalink
Merge pull request #45 from trivago/feature/make_it_android_independant
Browse files Browse the repository at this point in the history
Feature/make it android independant
  • Loading branch information
Gi-lo committed Oct 24, 2017
2 parents 90e364a + 3b22aec commit 456163a
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 246 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Expand Up @@ -12,7 +12,8 @@ env:
android:
components:
- tools
- build-tools-23.0.3
- build-tools-25.0.3
- android-25
- android-24
- android-22
- android-23
Expand All @@ -29,4 +30,4 @@ before_script:
- android-wait-for-emulator
- adb shell input keyevent 82 &

script: ./gradlew library:connectedAndroidTest
script: ./gradlew library:test
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.android.tools.build:gradle:2.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Thu Mar 30 11:28:56 CEST 2017
#Tue Oct 24 09:19:37 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
54 changes: 8 additions & 46 deletions library/build.gradle
@@ -1,54 +1,18 @@
apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'groovyx.grooid.groovy-android'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'groovy'

buildscript {
repositories {
mavenCentral()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'me.tatarka:gradle-retrolambda:2.5.0'
classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.6'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
classpath 'me.tatarka:gradle-retrolambda:3.6.1'
}
}

group = 'com.github.rheinfabrik'

android {
compileSdkVersion 24
buildToolsVersion "23.0.3"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

packagingOptions {
exclude 'LICENSE'
exclude 'LICENSE.txt'
exclude 'META-INF/services/org.codehaus.groovy.transform.ASTTransformation'
}

defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 107
versionName "1.0.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
}
}
}

repositories {
mavenCentral()
jcenter()
Expand All @@ -60,15 +24,13 @@ dependencies {
compile 'io.reactivex:rxjava:1.1.1'

// GSON
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.code.gson:gson:2.8.0'

// Spock
androidTestCompile 'org.codehaus.groovy:groovy:2.4.2:grooid'
androidTestCompile "com.andrewreitz:spock-android:1.2.1"
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude group: 'org.codehaus.groovy'
// Testing
testCompile 'junit:junit:4.12'
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude group: 'junit'
}
androidTestCompile "com.google.dexmaker:dexmaker:1.2"
testCompile "cglib:cglib:2.2"
testCompile "org.objenesis:objenesis:1.2"
}

This file was deleted.

@@ -1,6 +1,12 @@
package de.rheinfabrik.heimdall.grants;

import android.net.Uri;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import de.rheinfabrik.heimdall.OAuth2AccessToken;
import rx.Observable;
Expand Down Expand Up @@ -64,21 +70,21 @@ public abstract class OAuth2AuthorizationCodeGrant<TAccessToken extends OAuth2Ac
/**
* Observable emitting the authorization Uri.
*/
public final Observable<Uri> authorizationUri() {
return mAuthorizationUriSubject.asObservable();
public final Observable<URL> authorizationUri() {
return mAuthorizationUrlSubject.asObservable();
}

/**
* Command you should send a value to whenever an url in e.g. your web view has been loaded.
*/
public final PublishSubject<Uri> onUriLoadedCommand = PublishSubject.create();
public final PublishSubject<URL> onUrlLoadedCommand = PublishSubject.create();

// Abstract Api

/**
* Called when the grant needs the authorization uri.
* Called when the grant needs the authorization url.
*/
public abstract Uri buildAuthorizationUri();
public abstract URL buildAuthorizationUrl();

/**
* Called when the grant was able to grab the code and it wants to exchange it for an access token.
Expand All @@ -87,20 +93,48 @@ public final Observable<Uri> authorizationUri() {

// Members

private final BehaviorSubject<Uri> mAuthorizationUriSubject = BehaviorSubject.create();
private final BehaviorSubject<URL> mAuthorizationUrlSubject = BehaviorSubject.create();

// OAuth2AccessToken

@Override
public Single<TAccessToken> grantNewAccessToken() {
mAuthorizationUriSubject.onNext(buildAuthorizationUri());
mAuthorizationUrlSubject.onNext(buildAuthorizationUrl());

return onUriLoadedCommand
.map(uri -> uri.getQueryParameter(RESPONSE_TYPE))
return onUrlLoadedCommand
.map(uri -> {
List<String> values = getQueryParameters(uri).get(RESPONSE_TYPE);
if (values != null && values.size() >= 1) {
return values.get(0);
}

return null;
})
.filter(code -> code != null)
.take(1)
.retry()
.concatMap(this::exchangeTokenUsingCode)
.toSingle();
}

// Private

private static Map<String, List<String>> getQueryParameters(URL url) {
final Map<String, List<String>> query_pairs = new LinkedHashMap<>();
final String[] pairs = url.getQuery().split("&");
for (String pair : pairs) {
final int idx = pair.indexOf("=");

try {
final String key = idx > 0 ? URLDecoder.decode(pair.substring(0, idx), "UTF-8") : pair;
if (!query_pairs.containsKey(key)) {
query_pairs.put(key, new LinkedList<>());
}
final String value = idx > 0 && pair.length() > idx + 1 ? URLDecoder.decode(pair.substring(idx + 1), "UTF-8") : null;
query_pairs.get(key).add(value);
} catch (Exception ignored) {}
}

return query_pairs;
}
}
@@ -1,13 +1,13 @@
package de.rheinfabrik.heimdall

import com.andrewreitz.spock.android.AndroidSpecification
import de.rheinfabrik.heimdall.grants.OAuth2Grant
import de.rheinfabrik.heimdall.grants.OAuth2RefreshAccessTokenGrant
import rx.Single
import spock.lang.Specification
import spock.lang.Title

@Title("Tests for the constructor of the OAuth2AccessTokenManager class")
class OAuth2AccessTokenManagerConstructorSpecs extends AndroidSpecification {
class OAuth2AccessTokenManagerConstructorSpecs extends Specification {

// Scenarios

Expand All @@ -26,7 +26,7 @@ class OAuth2AccessTokenManagerConstructorSpecs extends AndroidSpecification {
}

@Title("Tests for the grantNewAccessToken() function of the OAuth2AccessTokenManager class")
class OAuth2AccessTokenManagerGrantNewAccessTokenSpecs extends AndroidSpecification {
class OAuth2AccessTokenManagerGrantNewAccessTokenSpecs extends Specification {

// Scenarios

Expand Down Expand Up @@ -112,7 +112,7 @@ class OAuth2AccessTokenManagerGrantNewAccessTokenSpecs extends AndroidSpecificat
}

@Title("Tests for the getStorage() function of the OAuth2AccessTokenManager class")
class OAuth2AccessTokenManagerGetStorageSpecs extends AndroidSpecification {
class OAuth2AccessTokenManagerGetStorageSpecs extends Specification {

// Scenarios

Expand All @@ -133,7 +133,7 @@ class OAuth2AccessTokenManagerGetStorageSpecs extends AndroidSpecification {
}

@Title("Tests for the getValidAccessToken() function of the OAuth2AccessTokenManager class")
class OAuth2AccessTokenManagerGetValidAccessTokenSpecs extends AndroidSpecification {
class OAuth2AccessTokenManagerGetValidAccessTokenSpecs extends Specification {

// Scenarios

Expand Down

0 comments on commit 456163a

Please sign in to comment.