use of com.amazonaws.auth.CognitoCredentialsProvider in project aws-sdk-android by aws-amplify.
the class KinesisVideoCredentialsProviderImpl method updateCredentials.
@Override
protected KinesisVideoCredentials updateCredentials() throws KinesisVideoException {
// Refresh the token first
log.debug("Refreshing credentials");
credentialsProvider.refresh();
// Get the AWS credentials and create Kinesis Video Credentials
final AWSCredentials awsCredentials = credentialsProvider.getCredentials();
String sessionToken = null;
if (awsCredentials instanceof AWSSessionCredentials) {
final AWSSessionCredentials sessionCredentials = (AWSSessionCredentials) awsCredentials;
sessionToken = sessionCredentials.getSessionToken();
}
Date expiration = KinesisVideoCredentials.CREDENTIALS_NEVER_EXPIRE;
if (credentialsProvider instanceof CognitoCredentialsProvider) {
final CognitoCredentialsProvider cognitoCredentialsProvider = (CognitoCredentialsProvider) credentialsProvider;
expiration = cognitoCredentialsProvider.getSessionCredentialsExpiration();
log.debug("Refreshed token expiration is %s", expiration);
} else if (credentialsProvider instanceof AWSMobileClient) {
AWSMobileClient awsMobileClient = (AWSMobileClient) credentialsProvider;
try {
expiration = awsMobileClient.getTokens().getAccessToken().getExpiration();
log.debug("Refreshed token expiration is %s", expiration);
} catch (Exception e) {
throw new KinesisVideoException("Failed to refresh! " + e.getMessage());
}
}
log.debug("Returning %scredentials with expiration %s", sessionToken == null ? "" : "session ", expiration);
return new KinesisVideoCredentials(awsCredentials.getAWSAccessKeyId(), awsCredentials.getAWSSecretKey(), sessionToken, expiration);
}
use of com.amazonaws.auth.CognitoCredentialsProvider in project aws-sdk-android by aws-amplify.
the class AWSConfigurationTest method testCognitoCachingCredentialsProviderWithAWSConfiguration.
@Test
public void testCognitoCachingCredentialsProviderWithAWSConfiguration() {
try {
JSONObject jsonObject = new JSONObject(jsonString);
AWSConfiguration awsConfiguration = new AWSConfiguration(jsonObject);
assertNotNull(awsConfiguration);
CognitoCredentialsProvider cognitoCredentialsProvider = new CognitoCredentialsProvider(awsConfiguration);
assertNotNull(cognitoCredentialsProvider);
} catch (JSONException e) {
fail("Error in constructing AWSConfiguration." + e.getLocalizedMessage());
}
}
use of com.amazonaws.auth.CognitoCredentialsProvider in project aws-sdk-android by aws-amplify.
the class CreateLexServiceRequest method generateRequestInternal.
/**
* Utility method for generating a request. Populates the request with a user ID from either interactionConfig or
* the credentialsProvider, which must be an instance of CognitoCredentialsProvider.
*
* @param sessionAttributes Session attributes for this current transaction.
* @param requestAttributes Attributes to add to the current request
* @param interactionConfig The configuration for the interaction, which must contain the user ID if
* credentialsProvider is not an instance of CognitoCredentialsProvider.
* @param credentialsProvider The credentialsProvider to obtain the Cognito IdentityId. If the user ID is not set in
* interactionConfig, credentialsProvider must be an instance of CognitoCredentialsProvider
* @param mode The desired response type
* @return a PostContentRequest with attributes and user ID, but no content
*/
private static PostContentRequest generateRequestInternal(Map<String, String> sessionAttributes, Map<String, String> requestAttributes, InteractionConfig interactionConfig, AWSCredentialsProvider credentialsProvider, ResponseType mode) {
final PostContentRequest request = new PostContentRequest();
request.setBotName(interactionConfig.getBotName());
request.setBotAlias(interactionConfig.getBotAlias());
request.setAccept(mode.toString());
final Map<String, String> newSessionAttributes = new HashMap<String, String>();
newSessionAttributes.putAll(interactionConfig.getGlobalSessionAttributes());
if (sessionAttributes != null) {
newSessionAttributes.putAll(sessionAttributes);
}
request.setSessionAttributes(mapToBase64(newSessionAttributes));
// Set the request attributes
if (requestAttributes != null) {
request.setRequestAttributes(mapToBase64(requestAttributes));
}
if (interactionConfig.getUserId() == null || interactionConfig.getUserId().isEmpty()) {
final CognitoCredentialsProvider cognitoCredentialsProvider = (CognitoCredentialsProvider) credentialsProvider;
request.setUserId(cognitoCredentialsProvider.getIdentityId());
} else {
request.setUserId(interactionConfig.getUserId());
}
return request;
}
use of com.amazonaws.auth.CognitoCredentialsProvider in project aws-mobile-appsync-sdk-android by awslabs.
the class AppSyncClientUnitTest method testAwsIamAuthProvider.
@Test
public void testAwsIamAuthProvider() {
awsConfiguration.setConfiguration("AwsIam");
final CognitoCredentialsProvider credentialsProvider = new CognitoCredentialsProvider(awsConfiguration);
final AWSAppSyncClient awsAppSyncClient = AWSAppSyncClient.builder().context(shadowContext).awsConfiguration(awsConfiguration).credentialsProvider(credentialsProvider).build();
assertNotNull(awsAppSyncClient);
}
use of com.amazonaws.auth.CognitoCredentialsProvider in project aws-mobile-appsync-sdk-android by awslabs.
the class AppSyncClientUnitTest method testConfigMismatch_ApiKey.
@Test(expected = RuntimeException.class)
public void testConfigMismatch_ApiKey() {
awsConfiguration.setConfiguration("AwsIam");
final CognitoCredentialsProvider credentialsProvider = new CognitoCredentialsProvider(awsConfiguration);
awsConfiguration.setConfiguration("ApiKey");
final AWSAppSyncClient awsAppSyncClient = AWSAppSyncClient.builder().context(shadowContext).awsConfiguration(awsConfiguration).credentialsProvider(credentialsProvider).build();
}
Aggregations