Skip to content

Commit a57a80a

Browse files
committed
AWS AppSync Android SDK version 2.6.18
1 parent fced5e0 commit a57a80a

File tree

7 files changed

+74
-17
lines changed

7 files changed

+74
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log - AWS AppSync SDK for Android
22

3+
## [Release 2.6.18](https://github.com/awslabs/aws-mobile-appsync-sdk-android/releases/tag/release_v2.6.18)
4+
5+
### New Features
6+
7+
* Adds OpenID Connect (OIDC) support as an authorization option.
8+
39
## [Release 2.6.17](https://github.com/awslabs/aws-mobile-appsync-sdk-android/releases/tag/release_v2.6.17)
410

511
### Enhancements

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ Android library files for Offline, Sync, Sigv4.
1919
In the project's `build.gradle`, add the following dependency in
2020
the build script:
2121

22-
```
23-
classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:2.6.17'
22+
```groovy
23+
classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:2.6.18'
2424
```
2525

2626
**Sample project's build.gradle**
2727

28-
```
28+
```groovy
2929
// Top-level build file where you can add configuration options common to all sub-projects/modules.
3030
buildscript {
3131
// ..other code..
3232
dependencies {
3333
classpath 'com.android.tools.build:gradle:3.0.1'
34-
classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:2.6.17'
34+
classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:2.6.18'
3535
// NOTE: Do not place your application dependencies here; they belong
3636
// in the individual module build.gradle files
3737
}
@@ -42,27 +42,27 @@ the build script:
4242

4343
In the app's `build.gradle`, add the following plugin:
4444

45-
```
45+
```groovy
4646
apply plugin: 'com.amazonaws.appsync'
4747
```
4848

4949
Add the following dependency:
5050

51-
```
52-
compile 'com.amazonaws:aws-android-sdk-appsync:2.6.17'
51+
```groovy
52+
compile 'com.amazonaws:aws-android-sdk-appsync:2.6.18'
5353
```
5454

5555
**Sample app's build.gradle**
5656

57-
```
57+
```groovy
5858
apply plugin: 'com.android.application'
5959
apply plugin: 'com.amazonaws.appsync'
6060
android {
6161
// Typical items
6262
}
6363
dependencies {
6464
// Typical dependencies
65-
compile 'com.amazonaws:aws-android-sdk-appsync:2.6.17'
65+
compile 'com.amazonaws:aws-android-sdk-appsync:2.6.18'
6666
}
6767
```
6868

@@ -71,7 +71,7 @@ Add the following dependency:
7171
Add the permissions to access network state to determine if the device
7272
is offline.
7373

74-
```
74+
```xml
7575
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7676
```
7777

@@ -113,7 +113,7 @@ are added in the build path.
113113

114114
## Create a client
115115

116-
```
116+
```java
117117
AWSAppSyncClient client = AWSAppSyncClient.builder()
118118
.context(context)
119119
.apiKey(new BasicAPIKeyAuthProvider(Constants.APPSYNC_API_KEY)) // API Key based authorization
@@ -124,7 +124,7 @@ AWSAppSyncClient client = AWSAppSyncClient.builder()
124124

125125
## Make a call
126126

127-
```
127+
```java
128128
public void addPost() {
129129
AddPostMutation addPostMutation = AddPostMutation.builder()
130130
.id(UUID.randomUUID().toString())
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Generated file. Do not edit!
22
package com.apollographql.android
3-
val VERSION = "2.6.17"
3+
val VERSION = "2.6.18"

aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/AWSAppSyncClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.amazonaws.mobileconnectors.appsync.sigv4.APIKeyAuthProvider;
2727
import com.amazonaws.mobileconnectors.appsync.sigv4.AppSyncSigV4SignerInterceptor;
2828
import com.amazonaws.mobileconnectors.appsync.sigv4.CognitoUserPoolsAuthProvider;
29+
import com.amazonaws.mobileconnectors.appsync.sigv4.OidcAuthProvider;
2930
import com.amazonaws.mobileconnectors.appsync.subscription.RealSubscriptionManager;
3031
import com.amazonaws.regions.Regions;
3132
import com.apollographql.apollo.ApolloClient;
@@ -73,6 +74,8 @@ private AWSAppSyncClient(AWSAppSyncClient.Builder builder) {
7374
appSyncSigV4SignerInterceptor = new AppSyncSigV4SignerInterceptor(builder.mCredentialsProvider, builder.mRegion.getName());
7475
} else if (builder.mCognitoUserPoolsAuthProvider != null) {
7576
appSyncSigV4SignerInterceptor = new AppSyncSigV4SignerInterceptor(builder.mCognitoUserPoolsAuthProvider, builder.mRegion.getName());
77+
} else if (builder.mOidcAuthProvider != null) {
78+
appSyncSigV4SignerInterceptor = new AppSyncSigV4SignerInterceptor(builder.mOidcAuthProvider);
7679
} else if (builder.mApiKey != null) {
7780
appSyncSigV4SignerInterceptor = new AppSyncSigV4SignerInterceptor(builder.mApiKey, builder.mRegion.getName());
7881
} else {
@@ -155,6 +158,7 @@ public static class Builder {
155158
AWSCredentialsProvider mCredentialsProvider;
156159
APIKeyAuthProvider mApiKey;
157160
CognitoUserPoolsAuthProvider mCognitoUserPoolsAuthProvider;
161+
OidcAuthProvider mOidcAuthProvider;
158162
NormalizedCacheFactory mNormalizedCacheFactory;
159163
CacheKeyResolver mResolver;
160164
ConflictResolverInterface mConflictResolver;
@@ -194,6 +198,11 @@ public Builder cognitoUserPoolsAuthProvider(CognitoUserPoolsAuthProvider cognito
194198
return this;
195199
}
196200

201+
public Builder oidcAuthProvider(OidcAuthProvider oidcAuthProvider) {
202+
mOidcAuthProvider = oidcAuthProvider;
203+
return this;
204+
}
205+
197206
public Builder serverUrl(String serverUrl) {
198207
mServerUrl = serverUrl;
199208
return this;

aws-android-sdk-appsync/src/main/java/com/amazonaws/mobileconnectors/appsync/sigv4/AppSyncSigV4SignerInterceptor.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,22 @@ public class AppSyncSigV4SignerInterceptor implements Interceptor {
4747
private final AWSCredentialsProvider credentialsProvider;
4848
private final APIKeyAuthProvider apiKey;
4949
private final CognitoUserPoolsAuthProvider cognitoUserPoolsAuthProvider;
50+
private final OidcAuthProvider oidcAuthProvider;
5051
private final String awsRegion;
5152
private final AuthMode authMode;
5253

5354
private enum AuthMode {
5455
API_KEY,
5556
IAM,
56-
USER_POOL
57+
AUTHORIZATION_TOKEN
5758
}
5859

5960
public AppSyncSigV4SignerInterceptor(APIKeyAuthProvider apiKey, final String awsRegion){
6061
this.apiKey = apiKey;
6162
this.awsRegion = awsRegion;
6263
this.credentialsProvider = null;
6364
this.cognitoUserPoolsAuthProvider = null;
65+
this.oidcAuthProvider = null;
6466
authMode = AuthMode.API_KEY;
6567
}
6668

@@ -69,6 +71,7 @@ public AppSyncSigV4SignerInterceptor(AWSCredentialsProvider credentialsProvider,
6971
this.awsRegion = awsRegion;
7072
this.apiKey = null;
7173
this.cognitoUserPoolsAuthProvider = null;
74+
this.oidcAuthProvider = null;
7275
authMode = AuthMode.IAM;
7376
}
7477

@@ -77,7 +80,17 @@ public AppSyncSigV4SignerInterceptor(CognitoUserPoolsAuthProvider cognitoUserPoo
7780
this.awsRegion = awsRegion;
7881
this.apiKey = null;
7982
this.cognitoUserPoolsAuthProvider = cognitoUserPoolsAuthProvider;
80-
authMode = AuthMode.USER_POOL;
83+
this.oidcAuthProvider = null;
84+
authMode = AuthMode.AUTHORIZATION_TOKEN;
85+
}
86+
87+
public AppSyncSigV4SignerInterceptor(OidcAuthProvider oidcAuthProvider){
88+
this.credentialsProvider = null;
89+
this.awsRegion = null;
90+
this.apiKey = null;
91+
this.cognitoUserPoolsAuthProvider = null;
92+
this.oidcAuthProvider = oidcAuthProvider;
93+
authMode = AuthMode.AUTHORIZATION_TOKEN;
8194
}
8295

8396
@Override
@@ -99,13 +112,20 @@ public Response intercept(Chain chain) throws IOException {
99112
dr.setHttpMethod(HttpMethodName.valueOf(req.method()));
100113
if (AuthMode.API_KEY.equals(authMode)) {
101114
dr.addHeader("x-api-key", apiKey.getAPIKey());
102-
} else if (AuthMode.USER_POOL.equals(authMode)) {
115+
} else if (AuthMode.AUTHORIZATION_TOKEN.equals(authMode) && cognitoUserPoolsAuthProvider != null) {
103116
try {
104117
dr.addHeader("authorization", cognitoUserPoolsAuthProvider.getLatestAuthToken());
105118
} catch (Exception e) {
106119
IOException ioe = new IOException("Failed to retrieve Cognito User Pools token.", e);
107120
throw ioe;
108121
}
122+
} else if (AuthMode.AUTHORIZATION_TOKEN.equals(authMode) && oidcAuthProvider != null) {
123+
try {
124+
dr.addHeader("authorization", oidcAuthProvider.getLatestAuthToken());
125+
} catch (Exception e) {
126+
IOException ioe = new IOException("Failed to retrieve OIDC token.", e);
127+
throw ioe;
128+
}
109129
}
110130

111131
dr.addHeader(HEADER_USER_AGENT, VersionInfoUtils.getUserAgent());
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright 2018-2018 Amazon.com,
3+
* Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Amazon Software License (the "License").
6+
* You may not use this file except in compliance with the
7+
* License. A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/asl/
10+
*
11+
* or in the "license" file accompanying this file. This file is
12+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
* CONDITIONS OF ANY KIND, express or implied. See the License
14+
* for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.amazonaws.mobileconnectors.appsync.sigv4;
19+
20+
public interface OidcAuthProvider {
21+
public String getLatestAuthToken();
22+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ org.gradle.jvmargs=-Xmx1536m
1313
org.gradle.parallel=true
1414

1515
GROUP=com.amazonaws
16-
VERSION_NAME=2.6.17
16+
VERSION_NAME=2.6.18
1717

1818
POM_URL=https://github.com/awslabs/aws-mobile-appsync-sdk-android
1919
POM_SCM_URL=https://github.com/awslabs/aws-mobile-appsync-sdk-android

0 commit comments

Comments
 (0)