Amazon Cognito 使用开发人员身份验证 Obj C 设置 identityId
Amazon Cognito set identityId using developer authentication Obj C
我正在尝试使用 Cognito 和开发人员验证身份来验证我的用户。我的问题是如何使用 objective-c?
将 identityId 设置为在 iOS 中从我的开发人员后端返回的正确身份
如果我在代码中手动调用或使用邮递员,我的服务器会返回正确的 ID,Cognito 会识别它并正确交换令牌。
iOS 框架似乎在自行分配不正确的 identityId。我真的很难理解文档,因为其中大部分内容已经过时且含糊不清。
下面是我的代码:
NSLog(@"Complete login");
NSMutableDictionary *merge = [NSMutableDictionary dictionaryWithDictionary:self.credentialsProvider.logins];
[merge addEntriesFromDictionary:logins];
self.credentialsProvider.logins = merge;
// Force a refresh of credentials to see if we need to merge
task = [self.credentialsProvider refresh];
NSLog(@"Complete login 2-- %@", self.credentialsProvider.identityId); //The identityId assigned is incorrect...
NSLog(@"Complete login 2-- %@", self.credentialsProvider.identityPoolId); //The identityPoolId is correct
下面的一些清晰度:
到目前为止,它是这样工作的:
1 - 当应用程序运行时,它会自动从亚马逊分配一个随机的 identityId(因此用户最初是未经身份验证的)。
2 - 用户输入他们的凭据,然后我的代码向我的后端发出 URL 请求,其中 returns 一个有效的令牌以及用户名和密码的正确 identityId。
3 - 现在这个新的 identityId 需要在代码中以某种方式初始化以覆盖旧的未经身份验证的 identityId。
4 - 从我的服务器返回的新 idendityId 和令牌需要发送到 Cognito 进行最终身份验证和 Cognito returns 更多身份验证。当我手动说我是通过邮递员发送请求时。
简而言之:
1:如何change/set我的identityId?
2:如何将从客户端后端收到的更新凭据发送到 Cognito?
AWSCognitoCredentialsProvider 实例中的 identityId 字段具有只读属性,因此一旦初始化就无法更改。设置它的唯一方法是在它的初始化中。
id<AWSCognitoCredentialsProvider> credentialsProvider =
[[AWSCognitoCredentialsProvider alloc]
initWithRegionType:<Region>
identityProvider:identityProvider
unauthRoleArn:nil
authRoleArn:nil];
用户通过身份验证后,请确保按如下方式更新登录映射:
credentialsProvider.logins = @{DeveloperProviderName: userIdentifier}
[credentialsProvider refresh];
来源:http://docs.aws.amazon.com/cognito/latest/developerguide/developer-authenticated-identities.html
p.s.: 确保你正确地实现了身份提供者并且在刷新方法中你应该设置 identityId
- (AWSTask *)refresh {
/*
* Get the identityId and token by making a call to your backend
*/
// Call to your backend
// Set the identity id and token
self.identityId = response.identityId;
self.token = response.token;
return [AWSTask taskWithResult:self.identityId];
}
我正在尝试使用 Cognito 和开发人员验证身份来验证我的用户。我的问题是如何使用 objective-c?
将 identityId 设置为在 iOS 中从我的开发人员后端返回的正确身份如果我在代码中手动调用或使用邮递员,我的服务器会返回正确的 ID,Cognito 会识别它并正确交换令牌。
iOS 框架似乎在自行分配不正确的 identityId。我真的很难理解文档,因为其中大部分内容已经过时且含糊不清。
下面是我的代码:
NSLog(@"Complete login");
NSMutableDictionary *merge = [NSMutableDictionary dictionaryWithDictionary:self.credentialsProvider.logins];
[merge addEntriesFromDictionary:logins];
self.credentialsProvider.logins = merge;
// Force a refresh of credentials to see if we need to merge
task = [self.credentialsProvider refresh];
NSLog(@"Complete login 2-- %@", self.credentialsProvider.identityId); //The identityId assigned is incorrect...
NSLog(@"Complete login 2-- %@", self.credentialsProvider.identityPoolId); //The identityPoolId is correct
下面的一些清晰度: 到目前为止,它是这样工作的: 1 - 当应用程序运行时,它会自动从亚马逊分配一个随机的 identityId(因此用户最初是未经身份验证的)。 2 - 用户输入他们的凭据,然后我的代码向我的后端发出 URL 请求,其中 returns 一个有效的令牌以及用户名和密码的正确 identityId。 3 - 现在这个新的 identityId 需要在代码中以某种方式初始化以覆盖旧的未经身份验证的 identityId。 4 - 从我的服务器返回的新 idendityId 和令牌需要发送到 Cognito 进行最终身份验证和 Cognito returns 更多身份验证。当我手动说我是通过邮递员发送请求时。
简而言之: 1:如何change/set我的identityId? 2:如何将从客户端后端收到的更新凭据发送到 Cognito?
AWSCognitoCredentialsProvider 实例中的 identityId 字段具有只读属性,因此一旦初始化就无法更改。设置它的唯一方法是在它的初始化中。
id<AWSCognitoCredentialsProvider> credentialsProvider =
[[AWSCognitoCredentialsProvider alloc]
initWithRegionType:<Region>
identityProvider:identityProvider
unauthRoleArn:nil
authRoleArn:nil];
用户通过身份验证后,请确保按如下方式更新登录映射:
credentialsProvider.logins = @{DeveloperProviderName: userIdentifier}
[credentialsProvider refresh];
来源:http://docs.aws.amazon.com/cognito/latest/developerguide/developer-authenticated-identities.html
p.s.: 确保你正确地实现了身份提供者并且在刷新方法中你应该设置 identityId
- (AWSTask *)refresh {
/*
* Get the identityId and token by making a call to your backend
*/
// Call to your backend
// Set the identity id and token
self.identityId = response.identityId;
self.token = response.token;
return [AWSTask taskWithResult:self.identityId];
}