Amplify-ios: Auth signOut after webUI signIn does not clear browser session

Created on 26 May 2020  路  9Comments  路  Source: aws-amplify/amplify-ios

Describe the bug
Amplify.Auth.signOut() does not clear the SFAuthentication session. This will not allow the user to signIn again with another users.

To Reproduce
Steps to reproduce the behavior:

  1. signIn using Amplify.Auth.signInWithWebUI
  2. After successful signIn, signout the user by Amplify.Auth.signOut
  3. Now try to signIn again using Amplify.Auth.signInWithWebUI.
  4. The user is not presented a signIn screen, Amplify automatically signin the user to the previous users account.

Expected behavior
After signOut Amplify.Auth.signInWithWebUI should work as a fresh start.

auth bug

Most helpful comment

Changes are merged to master and will be available in the next release.

All 9 comments

The way I am working around this is by forcing ASWebAuthenticationSession to connect to /logout on the Cognito endpoint.

    func experimentalCleanSignOut() {
        print("Signout succeded, clearing cache")

        // see https://stackoverflow.com/questions/47207914/sfauthenticationsession-aswebauthenticationsession-and-logging-out

        // to clear the SFAuthenticationSession cache and cookie, open a browser and visit this URL.
        // alternatively, it can redirect to myapp:// and have the app handle the redirect.  Should be implemented in AWSCognitoAuth.m ?

        DispatchQueue.main.async() {

            let signoutURL = URL(string: "https://amplify-lib-ios-demo-amplify.auth.eu-west-1.amazoncognito.com/logout?client_id=6s54gfquatdab7l888m8ka14k0&logout_uri=myapp://" )
            let authSession = ASWebAuthenticationSession(url: signoutURL!, callbackURLScheme: "myapp://") { url, error in
                if let e = error {
                    print("Error when trying to logout on Cognito : \(e)")
                }
            }
            class PCP : NSObject, ASWebAuthenticationPresentationContextProviding {
                func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
                    return UIApplication.shared.windows.first!
                }
            }
            let pcp = PCP()
            authSession.presentationContextProvider = pcp
            authSession.start()
        }

    }

Changes are merged to master and will be available in the next release.

This has been released in version 1.0.2 - https://github.com/aws-amplify/amplify-ios/releases/tag/v1.0.2 . Closing this issue.

I'm using v1.0.4 and seeing the Amplify.Auth.signInWithWebUI(presentationAnchor: UIApplication.shared.windows.first!) blow right by the provider screen and land on my redirect url with grant code; all after calling Amplify.Auth.signOut(options: options, listener:nil).

Any thoughts? Should I be expecting to see the fix automatically or do I need to try an experimentalCleanSignOut as above?

Any fix on this?

I am facing the same issue.
has anyone found the solution?

This is fixed since a few months. Test again with Amplify 1.5

    // signout
    public func signOut() {

        Amplify.Auth.signOut() { (result) in
            switch result {
            case .success:
                print("Successfully signed out")
            case .failure(let error):
                print("Sign out failed with error \(error)")
            }
        }
    }

I am using Amplify 1.5.0, and also used the same code for sign out but it is not worked for me.

I have used this code for sign in with google.

Amplify.Auth.signInWithWebUI(for: .google, presentationAnchor: self.view.window!) { result in
switch result {
case .success:
print("Sign in succeeded")
case .failure(let error):
print("Sign in failed (error)")
}
}

this issue is closed but i am getting this issue in 1.5.0.
can anyone help?

Was this page helpful?
0 / 5 - 0 ratings