Reputation: 902
I'm a newbie on mobile dev. I'm trying to authenticate to Amazon Cognito
.
I first login to Credentials Provider
using a username, pin, platform and deviceToken using custom services model - I then get identityId, endPoint and token back. I'm told that I need to swap the token I got back and refresh my credentials in order for me to be authenticated to AWS Cognito
and S3
. But all the process is confusing and have a lot of examples that are different.
I've created a SignInProvider, extending AWSSignInProvider to access the - (void) login: (void (^) (id result, NSError *error)) completionHanlder; I have my token, endpoint and identityId inside my login method..what do I do with the completion handler and whats next after.
@implementation SignInProvider
+(instanceType) sharedInstance{}
- (NSString) identityProviderName{}
- (AWSTask<NSString*>*) token{}
- (BOOL) isLoggedIn{}
- (NSSting*) userName{}
- (void) reloadSession{}
- (void) login: (void (^) (id result, NSError *error)) completionHanlder{
authRequest = [IMPCLDMobileAuthenticationRequest new];
[authRequest setToken:@"930fc1b56d8ca19a84500f9a79af71b65f60331f0242ce4395cdf41186443692"];
[authRequest setPassword:@"pin"];
[authRequest setUsername:@"[email protected]"];
[authRequest setPlatform:@"ios"];
serviceClient = [IMPCLDImpressionInternalMicroserviceClient defaultClient];
[[serviceClient mobileAuthenticationPost:authRequest] continueWithBlock:^id(AWSTask *loginTask)
{
//what to do here with my loginTask results (token, endpoint, identityId)
}
return nil;
}
Upvotes: 11
Views: 277
Reputation: 2298
To swap/save token in AWS
you need to do below in your continueWithBlock
[[serviceClient mobileAuthenticationPost:authRequest] continueWithBlock:^id(AWSTask *loginTask)
{
AWSSNSCreateEndpointResponse *response = loginTask.result;
AWSSNSSubscribeInput *subscribeRequest = [AWSSNSSubscribeInput new];
subscribeRequest.endpoint = response.endpointArn;
subscribeRequest.protocols = @"application";
subscribeRequest.topicArn = YOUR_TOPIC_ARN;
return [sns subscribe:subscribeRequest];
}] continueWithBlock:^id(AWSTask *task) {
if (task.cancelled) {
NSLog(@"Task cancelled");
}
else if (task.error) {
NSLog(@"Error occurred: [%@]", task.error);
}
else {
NSLog(@"Success");
}
return nil;
}];
Upvotes: 2