Skip to content

Commit 909dc7d

Browse files
sirknightjpoojamat
andauthored
Set token expiration time when credentials provider is AWSMobileClient (#2582)
* Set token expiration time when credentials provider is AWSMobileClient * Throw exception instead of handling it Co-authored-by: poojamat <[email protected]>
1 parent 487f818 commit 909dc7d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

aws-android-sdk-kinesisvideo/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dependencies {
2020
exclude group: 'com.google.android', module: 'android'
2121
}
2222
implementation 'androidx.annotation:annotation:1.1.0'
23+
implementation project(path: ':aws-android-sdk-mobile-client')
2324
//noinspection DuplicatePlatformClasses
2425
compileOnly 'org.apache.httpcomponents:httpclient:4.5.12'
2526
testImplementation 'junit:junit:4.13.1'

aws-android-sdk-kinesisvideo/src/main/java/com/amazonaws/mobileconnectors/kinesisvideo/auth/KinesisVideoCredentialsProviderImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
import com.amazonaws.kinesisvideo.common.exception.KinesisVideoException;
2929
import com.amazonaws.kinesisvideo.common.logging.Log;
3030
import com.amazonaws.kinesisvideo.common.preconditions.Preconditions;
31+
import com.amazonaws.mobile.client.AWSMobileClient;
3132

3233
import java.util.Date;
34+
import java.util.concurrent.TimeUnit;
3335

3436
/**
3537
* Implementation of the AWS Credentials Provider wrapper for Android
@@ -67,6 +69,14 @@ protected KinesisVideoCredentials updateCredentials() throws KinesisVideoExcepti
6769

6870
expiration = cognitoCredentialsProvider.getSessionCredentialsExpiration();
6971
log.debug("Refreshed token expiration is %s", expiration);
72+
} else if (credentialsProvider instanceof AWSMobileClient) {
73+
AWSMobileClient awsMobileClient = (AWSMobileClient) credentialsProvider;
74+
try {
75+
expiration = awsMobileClient.getTokens().getAccessToken().getExpiration();
76+
log.debug("Refreshed token expiration is %s", expiration);
77+
} catch (Exception e) {
78+
throw new KinesisVideoException("Failed to refresh! " + e.getMessage());
79+
}
7080
}
7181

7282
log.debug("Returning %scredentials with expiration %s",

0 commit comments

Comments
 (0)