Created
July 14, 2025 20:03
-
-
Save robertdean/29c100a609f863f74c515a7cdc8b2677 to your computer and use it in GitHub Desktop.
Microsoft ENTRA ID Fetching from iOS app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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