Bhanuteja
Bhanuteja

Reputation: 71

Is there any way to Forget signed-in account in AzureAD MSAL in swift ios app?

I am trying to logout the user and when i try to login back it takes the previous user credentials with out entering the password. Is there any way to clear the credentials when user sign out in MSAL swift?

Upvotes: 3

Views: 2882

Answers (4)

Bhanuteja
Bhanuteja

Reputation: 71

let parameters = MSALInteractiveTokenParameters(scopes: kScopes) parameters.promptType = MSALPromptType.login

Keep the flag as .login so it will always ask the user to enter the credentials.

This is just the temp solution.

Upvotes: 4

zdravko zdravkin
zdravko zdravkin

Reputation: 2378

You need to set

 parameters.promptType = .selectAccount

then the user can logout by clicking on ... and select logout

enter image description here

Upvotes: 0

Ankit Sharma
Ankit Sharma

Reputation: 91

You can use this code for iOS 13 or below as well. By changing promptType enum, we can handle login behaviour in WebView.

 func acquireTokenInteractively() -> Single<(String, String)> {
            return Single<(String, String)>.create { [kScope] observer in
                guard let applicationContext = self.applicationContext else {
                    observer(.error(Errors.unknown))
                    return Disposables.create()
                }

                let parameters = MSALInteractiveTokenParameters(scopes: kScope, webviewParameters: MSALWebviewParameters(parentViewController: UIApplication.shared.keyWindow!.rootViewController!))
                parameters.promptType = .login //Change it based on ur requirement e.g. .selectAccount, .consent, .promptIfNecessary
                applicationContext.acquireToken(with: parameters) { (result, error) in
                    if let error = error {
                        NSLoggerSwift.Logger.shared.log(.custom("OutlookLogin"), .error, "\u{274C} Could not acquire token: \(error.localizedDescription)")
                        observer(.error(Errors.badToken))
                    }

                    guard let result = result else {
                        observer(.error(Errors.badToken))
                        return
                    }
                    observer(.success((result.accessToken, result.account.username ?? "")))
                }
                return Disposables.create()
            }
}

Upvotes: 1

ekscrypto
ekscrypto

Reputation: 3806

The short answer: On iOS it is not possible to do this as of 2019-05-30 due to limitations of the technologies selected.

You can read more at: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/589

And follow the feature request at: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/425

Upvotes: 0

Related Questions