Cognito UserPoolを使ってみたが、何故かログイン処理が失敗する
本件、AWS SDK 2.4.2 にてすでに修正されています
UserPoolへのSDKを使用してログイン処理を実装してみたのですが、
現状、usernameもpasswordも合っているのにgetSession()が失敗する問題があります。
使用しているSDKのバージョンはAWSCognitoIdentityProvider 2.4.1です。
// Sign in the user
AWSCognitoIdentityUserPool *pool = [AWSCognitoIdentityUserPool CognitoIdentityUserPoolForKey:@"UserPool"];
AWSCognitoIdentityUser *user = [pool getUser];
[[user getSession:email password:pass validationData:nil scopes:nil]continueWithBlock:^id _Nullable(AWSTask<AWSCognitoIdentityUser *> * _Nonnull task) {
dispatch_async(dispatch_get_main_queue(), ^{
if(task.error){
if (block) {
block(nil, task.error);
}
}else {
AWSCognitoIdentityUserSession *session = task.result;
if (block) {
block(session, nil);
}
}});
return nil;
}];
エラー内容
[Debug] AWSURLResponseSerialization.m line:63 | -[AWSJSONResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response body:
{"__type":"NotAuthorizedException","message":"Incorrect username or password."}
原因はAWS SDKのバグです。
iOSの言語設定を英語以外に設定した際、正しく日時判定が行えずにログイン処理が失敗しているようです。
新しいSDKがリリースされるまでは、手動でSDKのソースにパッチを当てる必要があります。
If you need to patch it before the release, you can add this line before the return statement:
dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
here:
https://github.com/aws/aws-sdk-ios/blob/master/AWSCognitoIdentityProvider/Internal/AWSCognitoIdentityProviderSrpHelper.m#L266
上記の問題、GitHubのisuueに登録されたようです。
AWSCognitoIdentityUser getSession fails when device/simulator language differ than english #377
https://github.com/aws/aws-sdk-ios/issues/377