我是Azure新手。我正在构建使用azure活动目录B2C进行电子邮件登录/注册的原生iOS应用程序。我能够登录并注册但问题是重定向网址无法正常工作。成功登录或signUp我仍然在浏览器而不是回到我的应用程序。
CODE
let kTenantName = "AppName"
let kSignupOrSigninPolicy = "B2C_1_signupPolicy"
let kClientId = "clientId"
let kRedirectUri = "https://appname.azurewebsites.net/.auth/login/aad/callback"
let kEndpoint = "https://login.microsoftonline.com/........"
@IBAction func bt_login(sender: UIButton) {
print("Signing in")
let authorizationEndpoint = NSURL(string: kEndpoint)!
let tokenEndpoint = NSURL(string: kEndpoint)!
let configuration = OIDServiceConfiguration(authorizationEndpoint: authorizationEndpoint, tokenEndpoint: tokenEndpoint)
let request = OIDAuthorizationRequest(configuration: configuration, clientId: kClientId, scopes: [OIDScopeOpenID, OIDScopeProfile], redirectURL: NSURL(string: kRedirectUri)!, responseType: OIDResponseTypeCode, additionalParameters: nil)
var appDelegate = (UIApplication.sharedApplication().delegate! as! AppDelegate);
appDelegate.currentAuthorizationFlow = OIDAuthState.authStateByPresentingAuthorizationRequest(request, presentingViewController: self) { (authState, error) in
if (authState != nil) {
print("Got ID token: \(authState!.lastTokenResponse!.idToken)")
}
else {
print("Authorization error: \(error!.localizedDescription)")
}
}
我在info.plist
文件中添加了相同的重定向网址。
此外,我已将重定向网址添加到Authentication/Authorization->ALLOWED EXTERNAL REDIRECT URLS
部分中的azure网络门户网站。
答案 0 :(得分:1)
您的重定向网址应该是com.onmicrosoft.contoso.appname:// redirect / path。有关如何注册本机应用程序和配置重定向URI的说明,请参阅this page。
此外,我已将身份验证/授权中的重定向网址添加到azure网络门户 - >允许外部重定位网址部分。
那不是正确的地方。请按照上面链接中的步骤操作。