Help us understand the problem. What is going on with this article?

AWS Cognito User PoolにiOS SDKを使用してgetSessionしようとするとusername/passwordが正しいのに失敗する問題について

More than 3 years have passed since last update.

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のバグです。

https://forums.aws.amazon.com/thread.jspa?messageID=720209

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

karamage
モバイルアプリ開発が得意。「My感謝日記」など、人の心を豊かにするアプリを個人開発。TV番組でも紹介され累計20万DL突破。「エンジニアの心を整える技術」著者。Freelance Software Engineer
https://twitter.com/kara_mage
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした