Мне нужно внедрить AWS Cognito Magic Link для аутентификации пользователя. Я сделал в приложении запрос на отправку электронного письма. Я получаю электронное письмо с токеном. Разбираю в приложении. Как действовать и передать этот токен в sdk для аутентификации пользователя.
Я делаю следующее:
Код: Выделить всё
- (void)authenticateUserWithToken:(NSString *)token {
// Use the code to authenticate the user with AWS Cognito
self.user = [self.userPool getUser:@"user@email.com"];//email on which token was sent
self.token = token;
[[self.user getSession] continueWithBlock:^id _Nullable(AWSTask * _Nonnull task) {
self.session = task.result;
NSLog(@"Success: %@", self.session);
return nil;
}];
}
// AWSCognitoIdentityCustomAuthentication method
- (void)getCustomChallengeDetails:(AWSCognitoIdentityCustomAuthenticationInput *)authenticationInput customAuthCompletionSource:(AWSTaskCompletionSource *)customAuthCompletionSource {
if (self.user == nil || self.user.username == nil) {
return;
}
// Create custom challenge details with the token and username
AWSCognitoIdentityCustomChallengeDetails *authDetails = [[AWSCognitoIdentityCustomChallengeDetails alloc] initWithChallengeResponses:@{@"ANSWER" : self.token, @"USERNAME": self.user.username}];
// Set the result for the custom authentication
[customAuthCompletionSource setResult:authDetails];
NSLog(@"Custom authentication details: %@", customAuthCompletionSource.task.result);
}
// Called when custom authentication step completes with or without an error
- (void)didCompleteCustomAuthenticationStepWithError:(NSError * _Nullable)error {
if (error) {
NSLog(@"Error during custom authentication: %@", error);
}
}
Ошибка во время настройки аутентификация: Error Domain=com.amazonaws.AWSCognitoIdentityProviderErrorDomain Code=21 "(null)" UserInfo={__type=NotAuthorizedException, message=Неверное имя пользователя или пароль.После этого continueWithBlock вызывается с той же ошибкой.
Я действительно не понимаю, что происходит и как аутентифицировать пользователя. Пожалуйста, помогите!
Подробнее здесь: https://stackoverflow.com/questions/786 ... e-the-user
Мобильная версия