Aws-sdk-ios: AWSMobileClient.sharedInstance().getUserAttributes never completes when Cognito refresh token expired

Created on 7 Jan 2020  路  8Comments  路  Source: aws-amplify/aws-sdk-ios

Hi,

Pods versions 2.9.9

I'm using AWSMobileClient with Cognito and everything works fine but when the Cognito refresh token expires after the 30 days the method for getting user attributes

AWSMobileClient.sharedInstance().getUserAttributes never completes, neither returning an error nor a dictionary with the user info

mobile client requesting info

Most helpful comment

@aarons22 UPDATE:- I've tried myself to getTokens from the background but it never completes same as getUserAttributes and same as pointed in this other issue

All 8 comments

I'm running into this issue as well. I'm calling getUserAttributes after initialize returns .signedIn for the currentUserState here. Ideally getUserAttributes would fail even if I didn't check the state first.

I called getTokens() to see if any valid tokens existed and it says the user is not signed in.

@aarons22 Good to know getTokens() did actually return something did you try to call it from the main thread? I've found an issue saying that if you call it from a background thread it would actually refresh the tokens if expired

@aarons22 UPDATE:- I've tried myself to getTokens from the background but it never completes same as getUserAttributes and same as pointed in this other issue

I'm facing the same issue. Even when I tried to force logout from the app using

AWSMobileClient.default().signOut(options: SignOutOptions(signOutGlobally: true)) { (error) in
            if let error = error{
                print(error)
            }
        }

It also hangs.

I'm stuck in a state now where the app is always signedIn and I can't do anything about it. @royjit please advice on how to fix this? Is it possible if I clear all the tokens so I can "re sign-in"?

UPDATE
So simply calling AWSMobileClient.default().signOut() would sign me out and would allow me to relogin again. Solving my immediate issue for now. However the bigger problem similar to everyone else stays the same.

@velociraptor111 FYI We have tried to invalidate the tokens but that doesn't solve any issue

@royjit this has already caused many unhappy users in our production app and a solution isn't yet provided, has been already 20 days, can you give us a solution or a timeline for this? Because the only solution I see at the moment is moving away from Cognito

Yeah, I'm not sure what is causing all this but I noticed recently people have been problems with regards to this. For example this other issue seems to be linked: https://github.com/aws-amplify/aws-sdk-ios/issues/2210 and also this too I think: https://github.com/aws-amplify/aws-sdk-ios/issues/2229

AWSMobileClient is intended to do as much work as possible in the background, such as refreshing credentials, but it will occasionally come up against situations (such as refresh token expiry) where it needs to hand control back to your app. In those cases, it notifies your app via the user state listener, which you can use to request your user to login again.

The larger problem here is that the sign in/get credentials/respond to state changes interactions, while much simplified from the old Cognito SDK, is still confusing. We're working on ways of simplifying this and will post updates when we have more information. But for now, registering a user state listener with appropriate responses to incoming state changes should clear up your issues.

If you continue to have problems, please do open new issues with specific details such as SDK version, clear steps to reproduce and if possible, code snippets showing how you initialize the AWSMobileClient and respond to user state changes.

Closing this because of inactivity, please read the suggestion mentioned above. Feel free to open new issue if you still face any problem.

Was this page helpful?
0 / 5 - 0 ratings