大佬教程收集整理的这篇文章主要介绍了SwiftUI 应用程序中的 Azure AD B2C 集成错误并显示“不支持权限验证...”,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前尝试将 Azure AD B2C(通过 Apple 发送电子邮件和登录)集成到我的应用程序中。 当我从 Azure 门户预览登录页面时,一切看起来都很好并且工作正常。
但是当我从我的应用程序打开登录页面时,我收到以下错误:
Error Domain=MSALErrorDomain Code=-50000 "(null)" UserInfo={MSALErrorDescriptionKey=Authority valIDation is not supported for this type of authority,MSAlinternalErrorCodeKey=-42008,MSALCorrelationIDKey=2EFF58A4-24F2-4ABC-8D80-BC96EDD26AB7}
这是我的 AD B2C 部分的代码:
import SwiftUI
import MSAL
class MicrosoftLoginCotroller: UIVIEwController {
overrIDe func vIEwDIDLoad() {
super.vIEwDIDLoad()
}
overrIDe func vIEwWillAppear(_ animated: Bool) {
super.vIEwWillAppear(animated)
let btn = UIbutton(frame: CGRect(x: 20,y: self.vIEw.frame.height - 100,wIDth: self.vIEw.frame.wIDth - 40,height: 52))
btn.BACkgroundcolor = .green
btn.settitle("Lass uns starten!",for: .normal)
btn.settitlecolor(.white,for: .normal)
btn.addTarget(self,action: #SELEctor(buttonTapped),for: .touchUpInsIDE)
self.vIEw.addSubvIEw(btn)
}
@objc func buttonTapped(_ sender: UIbutton) {
do {
let authority = try MSALB2CAuthority(url: URL(String: "https://<tenant>.b2clogin.com/tfp/<tenant>.onmicrosoft.com/<policy>")!)
let pcaConfig = MSALPublicclIEntApplicationConfig(clIEntID: "my_correct_clIEnt_ID_from_the_azure_b2c_ad",redirectUri: nil,authority: authority)
let application = try MSALPublicclIEntApplication(configuration: pcaConfig)
let webVIEwParameters = MSALWebvIEwParameters(authpresentationVIEwController: self)
let interactiveParameters = MSAlinteractivetokenParameters(scopes: ["user.read"],webvIEwParameters: webVIEwParameters)
application.acquiretoken(with: interactiveParameters) { (result,error) in
guard let result = result else {
print("Error MSAL Token")
print(error!)
return
}
if let account = result.account.IDentifIEr {
print(account)
UIApplication.shared.windows.first { $0.isKeyWindow }!.rootVIEwController = UIHosTingController(rootVIEw: SignupProcessvIEw())
}
}
} catch {
print("Error MSAL")
print(error)
}
}
}
struct MicrosoftLoginVIEw: UIVIEwControllerRepresentable {
typealias UIVIEwControllerType = MicrosoftLoginCotroller
func makeUIVIEwController(context: UIVIEwControllerRepresentableContext<MicrosoftLoginVIEw>) -> MicrosoftLoginCotroller {
return MicrosoftLoginCotroller()
}
func updateUIVIEwController(_ uiVIEwController: MicrosoftLoginCotroller,context: Context) {
}
}
你知道我的错误在哪里吗?
非常感谢!
在浏览了 100 多个 Github 问题后,我发现了问题。 SDK 默认不信任 B2C MS 域。因此,您需要将您的授权人添加为受信任的域:
pcaConfig.knownAuthorities = [authority]
功能代码如下:
import SwiftUI
import MSAL
class MicrosoftLoginCotroller: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let btn = UIButton(frame: CGRect(x: 20,y: self.view.frame.height - 100,width: self.view.frame.width - 40,height: 52))
btn.BACkgroundColor = .green
btn.settitle("Lass uns starten!",for: .normal)
btn.settitleColor(.white,for: .normal)
btn.addTarget(self,action: #SELEctor(buttonTapped),for: .touchUpInsidE)
self.view.addSubview(btn)
}
@objc func buttonTapped(_ sender: UIButton) {
do {
let authority = try MSALB2CAuthority(url: URL(String: "https://<tenant>.b2clogin.com/tfp/<tenant>.onmicrosoft.com/<policy>")!)
let pcaConfig = MSALPublicClientApplicationConfig(clientId: "my_correct_client_id_from_the_azure_b2c_ad",redirectUri: nil,authority: authority)
pcaConfig.knownAuthorities = [authority]
let application = try MSALPublicClientApplication(configuration: pcaConfig)
let webViewParameters = MSALWebviewParameters(authpresentationViewController: self)
let interactiveParameters = MSALInteractiveTokenParameters(scopes: ["user.read"],webviewParameters: webViewParameters)
application.acquireToken(with: interactiveParameters) { (result,error) in
guard let result = result else {
print("Error MSAL Token")
print(error!)
return
}
if let account = result.account.identifier {
print(account)
UIApplication.shared.windows.first { $0.isKeyWindow }!.rootViewController = UIHosTingController(rootView: SignupProcessview())
}
}
} catch {
print("Error MSAL")
print(error)
}
}
}
struct MicrosoftLoginView: UIViewControllerRepresentable {
typealias UIViewControllerType = MicrosoftLoginCotroller
func makeUIViewController(context: UIViewControllerRepresentableContext<MicrosoftLoginView>) -> MicrosoftLoginCotroller {
return MicrosoftLoginCotroller()
}
func updateUIViewController(_ uiViewController: MicrosoftLoginCotroller,context: Context) {
}
}
以上是大佬教程为你收集整理的SwiftUI 应用程序中的 Azure AD B2C 集成错误并显示“不支持权限验证...”全部内容,希望文章能够帮你解决SwiftUI 应用程序中的 Azure AD B2C 集成错误并显示“不支持权限验证...”所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。