gpt4 book ai didi

ios - iOS (Swift 4) 中的 Azure AD B2C ROPC 流错误 - 资源所有者流只能由通过 B2C 管理门户创建的应用程序使用

转载 作者:可可西里 更新时间:2023-11-01 01:08:35 26 4
gpt4 key购买 nike

我正在尝试将 Azure AD B2C ROPC Flow 实现到 iOS Swift 4 应用程序中。我已经按照 documentation 中的说明进行操作在这个 sample 。我替换了以下请求参数:

kIssuer: "https://login.microsoftonline.com/tfp/{Tenant Name}.onmicrosoft.com/{Signin Policy Name}/v2.0"
kIssuerROPC: "https://login.microsoftonline.com/tfp/{tenantName}.onmicrosoft.com/{Resource Owner Policy Name}/v2.0"
kClientId: "{Application ID}"
kRedirectUri: "https://login.microsoftonline.com/tfp/oauth2/nativeclient"

我的additionalParameters如下:

"[
username": "{test email account}",
"password": "{test password}",
"scope": "openid {kClientId} offline_access",
"response_type": "token id_token
]"

我将按如下方式执行方法OIDTokenRequest:

OIDTokenRequest(
configuration: configuration!,
grantType: OIDGrantTypePassword,
authorizationCode: nil,
redirectURL: redirectURI!,
clientID: self.kClientID,
clientSecret: nil,
scope: additionalParameters["scope"],
refreshToken: nil,
codeVerifier: nil,
additionalParameters: additionalParameters
)

我打印出以下消息:

"Performing ROPC with request [%@] <OIDTokenRequest: 0x6000002a17a0, request: <URL:https://login.microsoftonline.com/te/{tenant}.onmicrosoft.com/b2c_1_ropc_auth/oauth2/token, HTTPBody: password=TESTPW&response_type=token%20id_token&scope=openid%KCLIENTID%20offline_access&scope=openid%20KCLIENTID%20offline_access&refresh_token=offline_access&grant_type=password&username=TESTEMAIL&redirect_uri=https://login.microsoftonline.com/tfp/oauth2/nativeclient&client_id=KCLIENTID>>

我已经编写了 TESTEMAIL、TESTPW 和 KCLIENTID,如前两组参数中所述。

我收到此错误:

token 请求错误:“unauthorized_client:AADB2C90248:资源所有者流只能由通过 B2C 管理门户创建的应用程序使用。

我正在使用在 Azure AD B2C 中注册的应用程序的 kClientId,它在请求 URL 中显示了 3 次不同的时间。我尝试了各种参数组合,但这是我能得到的最远的组合。

我可能想到的唯一无法正常工作的部分是示例中的 kRedirectUrimsalb35a3d9b://oauth/redirect,并且步骤 4在这个documentation具体来说是将 info.plist 值更改为 msalb35a3d9b

在我的 AADB2C 注册应用程序中,我有 2 个 RedirectURIS:

urn:ietf:wg:oauth:2.0:oobhttps://login.microsoftonline.com/tfp/oauth2/nativeclient

我已将 urn:ietf:wg 添加到 info.plist,但没有任何效果。我仍然遇到同样的错误。

有人可以帮我解决这个问题吗?

最佳答案

这是对我有用的配置。

let clientId = "{Application ID}"
let authorizationEndpoint = URL(string: "https://login.microsoftonline.com/{TenantName}.onmicrosoft.com/oauth2/v2.0/authorize?p={ROPC Policy Name}")
let tokenEndpoint = URL(string: "https://login.microsoftonline.com/{TenantName}.onmicrosoft.com/oauth2/v2.0/token?p={ROPC Policy Name}")
let redirectUri = URL(string: "urn:ietf:wg:oauth:2.0:oob")

let configuration = OIDServiceConfiguration(authorizationEndpoint: authorizationEndpoint!, tokenEndpoint: tokenEndpoint!)

let additionalParameters = [
"username": "{Username}",
"password": "{Password}",
"scope": "openid {Application ID} offline_access",
"response_type": "token id_token"
]

let tokenExchangeRequest = OIDTokenRequest(configuration: configuration, grantType: OIDGrantTypePassword, authorizationCode: nil, redirectURL: self.redirectUri!, clientID: self.clientId, clientSecret: nil, scope: nil, refreshToken: nil, codeVerifier: nil, additionalParameters: additionalParameters)

然后执行 token 请求。

OIDAuthorizationService.perform(tokenExchangeRequest, callback: { tokenResponse, error in
if tokenResponse == nil {
print("Token request error: %@", error?.localizedDescription as Any)
} else {
print("Received token response with accessToken: %@", tokenResponse?.accessToken as Any)
}
})

关于ios - iOS (Swift 4) 中的 Azure AD B2C ROPC 流错误 - 资源所有者流只能由通过 B2C 管理门户创建的应用程序使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51487951/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com