@@ -68,6 +68,8 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
6868
6969 let authority = try self . getAuthority ( forPolicy: self . kSignupOrSigninPolicy)
7070
71+ // Provide configuration for MSALPublicClientApplication
72+ // MSAL will use default redirect uri when you provide nil
7173 let pcaConfig = MSALPublicClientApplicationConfig ( clientId: kClientID, redirectUri: nil , authority: authority)
7274 self . application = try MSALPublicClientApplication ( configuration: pcaConfig)
7375 } catch {
@@ -108,18 +110,21 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
108110
109111 let webViewParameters = MSALWebviewParameters ( parentViewController: self )
110112 let parameters = MSALInteractiveTokenParameters ( scopes: kScopes, webviewParameters: webViewParameters)
113+ parameters. promptType = . selectAccount
111114 parameters. authority = authority
112115 application. acquireToken ( with: parameters) { ( result, error) in
113- if let result = result {
114- self . accessToken = result. accessToken
115- self . updateLoggingText ( text: " Access token is \( self . accessToken ?? " Empty " ) " )
116- self . signoutButton. isEnabled = true
117- self . callGraphApiButton. isEnabled = true
118- self . editProfileButton. isEnabled = true
119- self . refreshTokenButton. isEnabled = true
120- } else {
116+
117+ guard let result = result else {
121118 self . updateLoggingText ( text: " Could not acquire token: \( error ?? " No error informarion " as! Error ) " )
119+ return
122120 }
121+
122+ self . accessToken = result. accessToken
123+ self . updateLoggingText ( text: " Access token is \( self . accessToken ?? " Empty " ) " )
124+ self . signoutButton. isEnabled = true
125+ self . callGraphApiButton. isEnabled = true
126+ self . editProfileButton. isEnabled = true
127+ self . refreshTokenButton. isEnabled = true
123128 }
124129 } catch {
125130 self . updateLoggingText ( text: " Unable to create authority \( error) " )
@@ -227,13 +232,14 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
227232 parameters. account = thisAccount
228233
229234 self . application. acquireToken ( with: parameters) { ( result, error) in
230- if let result = result {
231- self . accessToken = result. accessToken
232- self . updateLoggingText ( text: " Access token is \( self . accessToken ?? " empty " ) " )
233-
234- } else {
235+
236+ guard let result = result else {
235237 self . updateLoggingText ( text: " Could not acquire new token: \( error ?? " No error informarion " as! Error ) " )
238+ return
236239 }
240+
241+ self . accessToken = result. accessToken
242+ self . updateLoggingText ( text: " Access token is \( self . accessToken ?? " empty " ) " )
237243 }
238244 return
239245 }
0 commit comments