Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robertdean/29c100a609f863f74c515a7cdc8b2677 to your computer and use it in GitHub Desktop.
Save robertdean/29c100a609f863f74c515a7cdc8b2677 to your computer and use it in GitHub Desktop.
Microsoft ENTRA ID Fetching from iOS app
import MSAL
func acquireTokenInteractively() {
guard let applicationContext = self.applicationContext,
let webViewParameters = self.webViewParameters else {
return
}
let parameters = MSALInteractiveTokenParameters(scopes: ["User.Read"], webviewParameters: webViewParameters)
parameters.promptType = .selectAccount
applicationContext.acquireToken(with: parameters) { (result, error) in
if let error = error {
print("Could not acquire token: \(error)")
return
}
guard let result = result else {
print("No result returned")
return
}
let accessToken = result.accessToken
let userEmail = result.account.username
let userId = result.account.identifier
print("Access Token: \(accessToken)")
print("User Email: \(userEmail)")
print("User ID: \(userId)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment