Azure-Samples / ms-identity-mobile-apple-swift-objc

An iOS sample in Swift that authenticates Microsoft Account and Azure AD users and calls the Graph API using OAuth 2.0
https://aka.ms/aaddev
74 stars 37 forks source link

Login page does not render on wifi but does when wifi turned off #20

Closed jthake closed 6 years ago

jthake commented 6 years ago

This is a weird error I just can't seem to lock down. WHen it launches the UI to show the sign in pages, it sits on a white page. But if I turn wifi off on my iPhone, the login page renders properly. I don't see any errors being logged or output anywhere.

Has anyone seen this?

jthake commented 6 years ago

This appears to do with running MSAL in debug mode on app on device. Wifi of seems to fix this. Can't replicate on actual device not in debug mode.

jthake commented 6 years ago

I finally worked out that I needed to take the below code out of the viewDidLoad to viewDidAppear and this seems to have resolved this issue. The samples may need updating to stop others making this mistake.

if  try self.applicationContext.users().isEmpty {
                throw NSError.init(domain: "MSALErrorDomain", code: MSALErrorCode.interactionRequired.rawValue, userInfo: nil)
            } else {
                try self.applicationContext.acquireTokenSilent(forScopes: msalManager.kScopes, user: applicationContext.users().first) { (result, error) in
                    if error == nil {
                        self.accessToken = (result?.accessToken)!
                        self.getUser()
                    } else {
                        print("Could not acquire token silently: \(error ?? "No error informarion" as! Error)")
                    }
                }
            }