我在尝试使用 Azure 的活动目录 b2c 快速对用户进行身份验证时遇到问题。看来我可以在 webview 中成功登录。AD 能够找到我的用户并在密码错误时返回错误,但在我“登录”后我被重定向到我的应用程序并出现以下错误:
无法获取令牌:错误域=MSALErrorDomainCode=-41205"null" Userinfo={MSALErrorDescriptionKey=令牌响应缺少访问令牌}
let kSignupOrSigninPolicy = "b2c_1_signupandsignin" // Your signup and sign-in policy you created in the portal
let kScopes: [String] = [""]
let kEndpoint = "https://login.microsoftonline.com/tfp/%@/%@"
let kTenantName = "sampleapp.onmicrosoft.com" // Your tenant name
@IBAction func authorizationButton(_ sender: UIButton) {
let kAuthority = String(format: kEndpoint, kTenantName, kSignupOrSigninPolicy)
do {
let application = try MSALPublicClientApplication.init(clientId: kClientID, authority: kAuthority)
application.acquireToken(forScopes: kScopes) { (result, error) in
if error == nil {
self.accessToken = (result?.accessToken)!
self.loggingText.text = "Access token is \(self.accessToken)"
self.signoutButton.isEnabled = true;
self.callGraphApiButton.isEnabled = true;
self.editProfileButton.isEnabled = true;
self.refreshTokenButton.isEnabled = true;
} else {
self.loggingText.text = "Could not acquire token: \(error ?? "No error informarion" as! Error)"
}
}
} catch {
self.loggingText.text = "Unable to create application \(error)"
}
}
我怀疑我如何在前端列出范围的后端范围配置有问题。据我所知,我们在后端没有自定义范围配置。我为 kScopes 变量尝试了一些不同的字符串:
"openid"
""
"https://graph.windows.net/openid"
"https://graph.windows.com/openid"
"https://graph.microsoft.com/openid"