gpt4 book ai didi

ios - AWS 对 Amazon Cognito 的身份验证

转载 作者:技术小花猫 更新时间:2023-10-29 10:53:04 24 4
gpt4 key购买 nike

我是移动开发新手。我正在尝试向 Amazon Cognito 进行身份验证。我首先使用自定义服务模型使用用户名、pin、平台和 deviceToken 登录到 Credentials Provider - 然后我得到 identityId、endPoint 和 token 。我被告知我需要交换我取回的 token 并刷新我的凭据,以便我通过 AWS CognitoS3 的身份验证。但是所有的过程都是困惑的,并且有很多不同的例子。

我创建了一个 SignInProvider,扩展了 AWSSignInProvider 以访问 - (void) login: (void (^) (id result, NSError *error)) completionHanlder;我的登录方法中有我的 token 、端点和 identityId。我要如何处理完成处理程序以及接下来要做什么。

@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:@"example@email.co.za"];

[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;

}

最佳答案

要在 AWS 中交换/保存 token ,您需要在 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;
}];

关于ios - AWS 对 Amazon Cognito 的身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39019990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com