Skip to content

Commit

Permalink
Merge pull request #95 from marnberg/twoAuth
Browse files Browse the repository at this point in the history
Adds ability to inject a http client into the afero client to enable app to handle authentication
  • Loading branch information
marnberg authored Mar 1, 2022
2 parents 056be28 + 4dfeca2 commit 18b979a
Show file tree
Hide file tree
Showing 47 changed files with 610 additions and 159 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ build
.classpath
bin
.vscode
.idea
.gradle
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change Log
==========

Version 1.5.0 *(2022-02-24)*
----------------------------
* New: Adds ability to configure the the underlying http client to enable oAuth to be handled by the app.
* New: Adds ability to configure softhub to connect to different services

Version 1.4.5 *(2019-09-20)*
----------------------------
* Fix: `AferoClient.resetPasswordWithCode` now actually works rather than returning a 400 error.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

MIT License

© Copyright 2017-2019 Afero, Inc.
© Copyright 2017-2022 Afero, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
author: Tony Myles
title: "AferoJavaSDK"
date: 2019-Sept-20
status: 1.4.5
date: 2022-Feb-28
status: 1.5.0
---

# AferoJavaSDK
Expand Down Expand Up @@ -32,23 +32,23 @@ The SDK is composed of four separate modules.

The `afero-sdk-core` module is required for base functionality such as interacting with the Afero Cloud and manipulating devices.
```Gradle
implementation 'io.afero.sdk:afero-sdk-core:1.4.5'
implementation 'io.afero.sdk:afero-sdk-core:1.5.0'
```

The `afero-sdk-client-retrofit2` module provides an optional implementation of the AferoClient REST API interface using [Retrofit2](http://square.github.io/retrofit/) and [okhttp3](http://square.github.io/okhttp/). If you choose not to include this module in your project, you will need to develop your own implementation of AferoClient using your preferred http client library.

```Gradle
implementation 'io.afero.sdk:afero-sdk-client-retrofit2:1.4.5'
implementation 'io.afero.sdk:afero-sdk-client-retrofit2:1.5.0'
```

The `afero-sdk-android` module is required for Android development.
```Gradle
implementation 'io.afero.sdk:afero-sdk-android:1.4.5'
implementation 'io.afero.sdk:afero-sdk-android:1.5.0'
```

The `afero-sdk-softhub` module is required for soft hub functionality on Android.
```Gradle
implementation 'io.afero.sdk:afero-sdk-softhub:1.4.5'
implementation 'io.afero.sdk:afero-sdk-softhub:1.5.0'
implementation "io.afero.sdk:hubby:1.0.844@aar"
```

Expand Down
4 changes: 2 additions & 2 deletions afero-sdk-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 26
compileSdkVersion 30

defaultConfig {
minSdkVersion 19
targetSdkVersion 26
targetSdkVersion 30
versionCode 1
versionName rootProject.version
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ private Config validate() {
e = new IllegalArgumentException("oauthClientId must be specified");
}

if (oauthClientSecret == null || oauthClientSecret.isEmpty()) {
e = new IllegalArgumentException("oauthClientSecret must be specified");
}

if (httpLogLevel == null) {
e = new IllegalArgumentException("httpLogLevel cannot be null");
}
Expand Down Expand Up @@ -245,11 +241,11 @@ public Config build() {
*
* @param config Config
*/
public AferoClientRetrofit2(Config config) {
public AferoClientRetrofit2(Config config, OkHttpClient client) {
mConfig = config;
mHttpClient = createHttpClient(config.httpLogLevel, config.defaultTimeout);
mHttpClient = client != null ? client : createHttpClient(config.httpLogLevel, config.defaultTimeout);
mAferoService = createRetrofit().create(AferoClientAPI.class);
mOAuthAuthorizationBase64 = Credentials.basic(config.oauthClientId, config.oauthClientSecret);
mOAuthAuthorizationBase64 = config.oauthClientSecret != null ? Credentials.basic(config.oauthClientId, config.oauthClientSecret) : "";
}

// don't use me
Expand Down
16 changes: 11 additions & 5 deletions afero-sdk-softhub/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@ repositories {
maven {
url "https://afero.jfrog.io/afero/hubby-android"
credentials {
username = project.aferoArtifactoryUserName
password = project.aferoArtifactoryPassword
username project.aferoArtifactoryUserName
password project.aferoArtifactoryPassword
}
authentication {
basic(BasicAuthentication)
}
metadataSources {
artifact()
}
}
}

final String hubbyVersion = "1.0.844"
final String hubbyVersion = "1.0.957"
final String hubType = project.findProperty('aferoSofthubType') ?: '"CONSUMER"'

android {
compileSdkVersion 26
compileSdkVersion 30

defaultConfig {
minSdkVersion 19
targetSdkVersion 26
targetSdkVersion 30

versionCode 1
versionName rootProject.version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public enum HubType {

private boolean mIsActive = true;
private String mService;
private String mHost;
private String mAuthCert;


private PublishSubject<AferoSofthub> mStartSubject;
private final PublishSubject<NotificationCallback.CompleteReason> mCompleteSubject = PublishSubject.create();
Expand Down Expand Up @@ -238,6 +241,15 @@ public boolean isStarting() {
return mStartSubject != null;
}

public void setHost(@NonNull String host) {
mHost = host;
}

public void setAuthCert(@NonNull String cert) {
mAuthCert = cert;
}


public void setService(@NonNull String service) {
mService = service;
}
Expand Down Expand Up @@ -315,6 +327,14 @@ private void startHubby() {
config.put(Hubby.Config.HARDWARE_INFO, hwInfo);
config.put(Hubby.Config.HUB_TYPE, mHubType.toString());

if (mHost != null) {
config.put(Hubby.Config.API_HOSTNAME, mHost);
}

if(mAuthCert != null) {
config.put(Hubby.Config.AUTHENTICATOR_CERT, mAuthCert);
}

if (mService != null) {
config.put(Hubby.Config.SERVICE, mService);
}
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.8.1"
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.15.2'
classpath "com.mobbeel.plugin:fat-aar:2.0.1"
}
}
Expand All @@ -19,6 +19,7 @@ allprojects {
repositories {
google()
jcenter()
mavenCentral()
}

apply plugin: 'com.jfrog.artifactory'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-all.zip
57 changes: 42 additions & 15 deletions samples/afero-lab/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
apply plugin: 'com.android.application'

final String sdkRepoKey = project.findProperty('aferoSDKConsumeRepoKey') ?: 'afero-java-sdk'
final String sdkVersion = project.findProperty('aferoSDKVersion') ?: '1.4.5'
final String sdkVersion = project.findProperty('aferoSDKVersion') ?: '1.5.0'

repositories {
maven {
url "https://afero.jfrog.io/afero/${sdkRepoKey}"
artifactUrls "https://afero.jfrog.io/afero/hubby-android"
artifactUrls "https://afero.jfrog.io/artifactory/hubby-android"
credentials {
username = project.aferoArtifactoryUserName
password = project.aferoArtifactoryPassword
}
authentication {
basic(BasicAuthentication)
}
metadataSources {
artifact()
}
}
}
configurations.all {
Expand All @@ -25,19 +31,30 @@ configurations.all {


android {
compileSdkVersion 27
compileSdkVersion 30

defaultConfig {
applicationId 'io.afero.aferolab'
minSdkVersion 19
targetSdkVersion 27
minSdkVersion 26
targetSdkVersion 30

versionCode 1
versionName '1.0'

buildConfigField 'String', 'AFERO_CLIENT_ID', project.aferoClientId
buildConfigField 'String', 'AFERO_CLIENT_SECRET', project.aferoClientSecret
buildConfigField 'String', 'AFERO_SERVICE_URL', project.findProperty('aferoServiceUrl') ?: '"https://api.afero.io"'
buildConfigField 'String', 'AFERO_SOFTHUB_SERVICE', project.findProperty('aferoSofthubService') ?: '"prod"'
buildConfigField 'String', 'AFERO_CLIENT_SECRET', project.findProperty('aferoClientSecret') ?: 'null'
buildConfigField 'String', 'AFERO_SERVICE_HOSTNAME', project.findProperty('aferoServiceHostname') ?: '"api.afero.io"'
buildConfigField 'String', 'AFERO_SOFTHUB_SERVICE', project.findProperty('aferoSofthubService') ?: 'null'
buildConfigField 'String', 'AFERO_SOFTHUB_AUTHENTICATOR_CERT', project.findProperty('aferoSofthubAuthenticatorCert') ?: 'null'

buildConfigField 'String', 'AFERO_OAUTH_AUTH_URL', project.findProperty('aferoOauthAuthUrl') ?: 'null'
buildConfigField 'String', 'AFERO_OAUTH_TOKEN_URL', project.findProperty('aferoOauthTokenUrl') ?: 'null'
buildConfigField 'String', 'AFERO_OAUTH_REDIRECT_SCHEME', project.findProperty('aferoOauthRedirectScheme') != null ? '"' + project.findProperty('aferoOauthRedirectScheme') + '"' : 'null'
buildConfigField 'String', 'AFERO_OAUTH_REDIRECT_HOST', project.findProperty('aferoOauthRedirectHost') != null ? '"' + project.findProperty('aferoOauthRedirectHost') + '"' : 'null'

manifestPlaceholders = [oAuthRedirectScheme: project.findProperty('aferoOauthRedirectScheme') != null ? project.findProperty('aferoOauthRedirectScheme') : "",
oAuthRedirectHost: project.findProperty('aferoOauthRedirectHost') != null ? project.findProperty('aferoOauthRedirectHost') : ""]

}

buildTypes {
Expand All @@ -60,6 +77,11 @@ android {
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

}

dependencies {
Expand All @@ -70,7 +92,8 @@ dependencies {
implementation "io.afero.sdk:afero-sdk-client-retrofit2:${sdkVersion}"
implementation "io.afero.sdk:afero-sdk-android:${sdkVersion}@aar"
implementation "io.afero.sdk:afero-sdk-softhub:${sdkVersion}@aar"
implementation "io.afero.sdk:hubby:1.0.844@aar"

implementation "io.afero.sdk:hubby:1.0.957@aar"

// https://github.com/square/retrofit
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
Expand All @@ -88,16 +111,20 @@ dependencies {
implementation 'io.reactivex:rxjava:1.3.0'

// http://jakewharton.github.io/butterknife/
implementation 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'

// https://github.com/dm77/barcodescanner
implementation 'me.dm7.barcodescanner:zxing:1.9.13'

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'


testImplementation 'junit:junit:4.12'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.0.0'

//https://github.com/openid/AppAuth-Android
implementation 'net.openid:appauth:0.9.1'
}
16 changes: 15 additions & 1 deletion samples/afero-lab/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
-->

<manifest package="io.afero.aferolab"
xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Expand All @@ -30,6 +31,19 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="net.openid.appauth.RedirectUriReceiverActivity"
tools:node="replace"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="${oAuthRedirectScheme}"
android:host="${oAuthRedirectHost}" />
</intent-filter>
</activity>
</application>

</manifest>
Loading

0 comments on commit 18b979a

Please sign in to comment.