在 Azure AD B2C 的 Postman 中请求访问令牌
Request Access Token in Postman for Azure AD B2C
如何在 Postman against an Azure AD B2C 个租户中请求 Access Token
?
我尝试从 Azure 门户中的 Run Now
中获取 url 并将其放入 Auth Url
中,但这会产生以下错误:
更新
根据 Chris 的回答,我现在已经解决了上述错误。我可以登录,但仍然无法获取访问令牌:
AADB2C90085: The service has encountered an internal error. Please reauthenticate and try again.
Correlation ID: 45c56d47-4739-465f-8e02-49ba5b3a1b86
Timestamp: 2017-11-16 15:27:52Z
对于 Auth URL 字段,您只需输入授权端点 URL 而无需输入查询字符串参数:
https://login.microsoftonline.com/te/{tenant}/{policy}/oauth2/v2.0/authorize
对于访问令牌 URL 字段:
https://login.microsoftonline.com/te/{tenant}/{policy}/oauth2/v2.0/token
对于回调 URL 字段,您必须输入已注册到 Azure AD B2C 应用程序的回复 URL,例如:
https://www.getpostman.com/oauth2/callback
对于范围字段,输入 "openid" 以及任何 API 访问范围。
对于客户端身份验证字段,select "Send client credentials in body"。
使用 ,我能够使用 Implicit
授权类型使其工作(无法使用授权码 Gran 类型使其工作)。
资助类型:Implicit
回调URL:在我的 B2C 应用程序中定义的任何 URL
授权 URL: https://{tenant}.b2clogin.com/te/{tenant}.onmicrosoft.com/{policy}/oauth2/v2.0/authorize
客户 ID:Application ID
来自我的 B2C 应用
范围:https://{tenant}.onmicrosoft.com/{web api app id uri}/{scope name}
客户端身份验证:Either one, it didn't matter
我只是想为繁荣添加一些额外的信息,因为我最近花了太长时间试图解决与错误 AADB2C90085 相关的问题,这个问题是 Google 上的少数结果之一。 =14=]
Update
Following Chris's answer, I'm now past the above error. I'm able to sign-in but still can't get an access token:
AADB2C90085: The service has encountered an internal error. Please reauthenticate and try again. Correlation ID: 45c56d47-4739-465f-8e02-49ba5b3a1b86 Timestamp: 2017-11-16 15:27:52Z
并且:
Using @Chris Padgett's answer, I was able to get it working using the Implicit Grant Type (couldn't get it working w/ Authorization Code Gran Type).
我在使用授权代码流时收到此错误,因为我的 B2C_1A_TokenSigningKeyContainer 和 B2C_1A_TokenEncryptionKeyContainer 生成不正确.一旦我按照 Get started with custom policies in Azure Active Directory B2C 的指南进行操作,错误就停止了。
相关摘录自link:
Create the signing key
- Select Policy Keys and then select Add.
- For Options, choose Generate.
- In Name, enter TokenSigningKeyContainer. The prefix B2C_1A_ might be added automatically.
- For Key type, select RSA.
- For Key usage, select Signature.
- Click Create.
Create the encryption key
- Select Policy Keys and then select Add.
- For Options, choose Generate.
- In Name, enter TokenEncryptionKeyContainer. The prefix B2C_1A_ might be added automatically.
- For Key type, select RSA.
- For Key usage, select Encryption.
- Click Create.
我可以在 Postman 中获得适用于两种授权类型的 B2C 请求访问令牌:grant_type=implicit
以及 grant_type=authorization_code
。我相应地打开了一个关于 MS documentation:
的问题
- 更新文档并提及
grant_type=authorization_code"
也是可能的(参见描述):https://github.com/aspnet/Docs/issues/10336
需要进行以下更改:
grant_type=implicit
和 grant_type=authorization_code
之间的唯一区别是 grant_type=authorization_code
需要更多参数,如下所示:
Access Token(访问令牌请求)URL:https://login.microsoftonline.com/"tenant-name".onmicrosoft.com/oauth2/v2.0/token?p=B2C_1_"name-of-your-signup-signin-flow"
client_secret:为您的应用程序生成密钥:Azure 门户 -> Azure AD B2C -> 应用程序 -> -> 密钥 -> 生成密钥
2020-05-26 更新
Microsoft 更改了 Azure Active Directory B2C 的登录 URL,如您所见 here。
因此 必须更新为:
资助类型:Implicit
回调 URL:在我的 B2C 应用程序中定义的任何 URL
授权 URL: https://{tenant}.b2clogin.com/te/{tenant}.onmicrosoft.com/{policy}/oauth2/v2.0/authorize
客户端 ID:来自我的 B2C 应用程序的应用程序 ID
范围:https://{tenant}.onmicrosoft.com/{web api app id uri}/{scope name}
客户端身份验证:两者都无所谓
获得这个设置有点让人头疼。这是我从该线程中的答案拼凑而成的内容,已更新以利用 Postman 的 Grant Type: Authorization Code (With PKCE)
使用:Azure B2C 租户、JS SPA 前端、Azure Function 后端。
Azure 门户(Azure AD B2C)
SPA 和后端的设置或多或少如本 MS 文档中所述(小心,某些部分已过时!):https://docs.microsoft.com/en-us/azure/api-management/howto-protect-backend-frontend-azure-ad-b2c
@SPA申请注册>认证blade>将此值添加到'Single-page application Redirect URIs'
https://oauth.pstmn.io/v1/callback
@Azure AD B2C |应用程序注册,点击'endpoints'(蓝色地球图标@顶部)
记录 Azure AD B2C OAuth 2.0 令牌端点 (v2) 和 Azure AD B2c 2.0 授权端点 (v2)
邮递员
- 授权:Oauth 2.0
- 将授权数据添加到:请求 Headers
配置新令牌
代币名称:WhateverYouWant
授权类型:使用 PKCE 的授权码
-
[ ] 使用浏览器授权(未选中)
Auth URL: https://< tenant-name >.b2clogin.com/< tenant-name >.onmicrosoft.com/< policy-name> /oauth2/v2.0/授权
访问令牌URL:https://.b2clogin.com/.onmicrosoft.com/ < policy-name >/oauth2/v2.0/令牌
客户端 ID:
客户端密码:<空>
代码挑战方法:SHA-256
代码验证器:<空>
状态:<空>
范围:类似<租户名称>.onmicrosoft.com/Hello
客户端身份验证:在 body
中发送客户端凭据
单击 [清除 cookie] 和 [获取新访问令牌]
如何在 Postman against an Azure AD B2C 个租户中请求 Access Token
?
我尝试从 Azure 门户中的 Run Now
中获取 url 并将其放入 Auth Url
中,但这会产生以下错误:
更新
根据 Chris 的回答,我现在已经解决了上述错误。我可以登录,但仍然无法获取访问令牌:
AADB2C90085: The service has encountered an internal error. Please reauthenticate and try again. Correlation ID: 45c56d47-4739-465f-8e02-49ba5b3a1b86 Timestamp: 2017-11-16 15:27:52Z
对于 Auth URL 字段,您只需输入授权端点 URL 而无需输入查询字符串参数:
https://login.microsoftonline.com/te/{tenant}/{policy}/oauth2/v2.0/authorize
对于访问令牌 URL 字段:
https://login.microsoftonline.com/te/{tenant}/{policy}/oauth2/v2.0/token
对于回调 URL 字段,您必须输入已注册到 Azure AD B2C 应用程序的回复 URL,例如:
https://www.getpostman.com/oauth2/callback
对于范围字段,输入 "openid" 以及任何 API 访问范围。
对于客户端身份验证字段,select "Send client credentials in body"。
使用 Implicit
授权类型使其工作(无法使用授权码 Gran 类型使其工作)。
资助类型:Implicit
回调URL:在我的 B2C 应用程序中定义的任何 URL
授权 URL: https://{tenant}.b2clogin.com/te/{tenant}.onmicrosoft.com/{policy}/oauth2/v2.0/authorize
客户 ID:Application ID
来自我的 B2C 应用
范围:https://{tenant}.onmicrosoft.com/{web api app id uri}/{scope name}
客户端身份验证:Either one, it didn't matter
我只是想为繁荣添加一些额外的信息,因为我最近花了太长时间试图解决与错误 AADB2C90085 相关的问题,这个问题是 Google 上的少数结果之一。 =14=]
Update
Following Chris's answer, I'm now past the above error. I'm able to sign-in but still can't get an access token:
AADB2C90085: The service has encountered an internal error. Please reauthenticate and try again. Correlation ID: 45c56d47-4739-465f-8e02-49ba5b3a1b86 Timestamp: 2017-11-16 15:27:52Z
并且:
Using @Chris Padgett's answer, I was able to get it working using the Implicit Grant Type (couldn't get it working w/ Authorization Code Gran Type).
我在使用授权代码流时收到此错误,因为我的 B2C_1A_TokenSigningKeyContainer 和 B2C_1A_TokenEncryptionKeyContainer 生成不正确.一旦我按照 Get started with custom policies in Azure Active Directory B2C 的指南进行操作,错误就停止了。
相关摘录自link:
Create the signing key
- Select Policy Keys and then select Add.
- For Options, choose Generate.
- In Name, enter TokenSigningKeyContainer. The prefix B2C_1A_ might be added automatically.
- For Key type, select RSA.
- For Key usage, select Signature.
- Click Create.
Create the encryption key
- Select Policy Keys and then select Add.
- For Options, choose Generate.
- In Name, enter TokenEncryptionKeyContainer. The prefix B2C_1A_ might be added automatically.
- For Key type, select RSA.
- For Key usage, select Encryption.
- Click Create.
我可以在 Postman 中获得适用于两种授权类型的 B2C 请求访问令牌:grant_type=implicit
以及 grant_type=authorization_code
。我相应地打开了一个关于 MS documentation:
- 更新文档并提及
grant_type=authorization_code"
也是可能的(参见描述):https://github.com/aspnet/Docs/issues/10336
需要进行以下更改:
grant_type=implicit
和 grant_type=authorization_code
之间的唯一区别是 grant_type=authorization_code
需要更多参数,如下所示:
Access Token(访问令牌请求)URL:https://login.microsoftonline.com/"tenant-name".onmicrosoft.com/oauth2/v2.0/token?p=B2C_1_"name-of-your-signup-signin-flow"
client_secret:为您的应用程序生成密钥:Azure 门户 -> Azure AD B2C -> 应用程序 -> -> 密钥 -> 生成密钥
2020-05-26 更新
Microsoft 更改了 Azure Active Directory B2C 的登录 URL,如您所见 here。
因此
资助类型:Implicit
回调 URL:在我的 B2C 应用程序中定义的任何 URL
授权 URL: https://{tenant}.b2clogin.com/te/{tenant}.onmicrosoft.com/{policy}/oauth2/v2.0/authorize
客户端 ID:来自我的 B2C 应用程序的应用程序 ID
范围:https://{tenant}.onmicrosoft.com/{web api app id uri}/{scope name}
客户端身份验证:两者都无所谓
获得这个设置有点让人头疼。这是我从该线程中的答案拼凑而成的内容,已更新以利用 Postman 的 Grant Type: Authorization Code (With PKCE)
使用:Azure B2C 租户、JS SPA 前端、Azure Function 后端。
Azure 门户(Azure AD B2C)
SPA 和后端的设置或多或少如本 MS 文档中所述(小心,某些部分已过时!):https://docs.microsoft.com/en-us/azure/api-management/howto-protect-backend-frontend-azure-ad-b2c
@SPA申请注册>认证blade>将此值添加到'Single-page application Redirect URIs'
https://oauth.pstmn.io/v1/callback
@Azure AD B2C |应用程序注册,点击'endpoints'(蓝色地球图标@顶部)
记录 Azure AD B2C OAuth 2.0 令牌端点 (v2) 和 Azure AD B2c 2.0 授权端点 (v2)
邮递员
- 授权:Oauth 2.0
- 将授权数据添加到:请求 Headers
配置新令牌
代币名称:WhateverYouWant
授权类型:使用 PKCE 的授权码
[ ] 使用浏览器授权(未选中)
Auth URL: https://< tenant-name >.b2clogin.com/< tenant-name >.onmicrosoft.com/< policy-name> /oauth2/v2.0/授权
访问令牌URL:https://
.b2clogin.com/ .onmicrosoft.com/ < policy-name >/oauth2/v2.0/令牌 客户端 ID:
客户端密码:<空>
代码挑战方法:SHA-256
代码验证器:<空>
状态:<空>
范围:类似<租户名称>.onmicrosoft.com/Hello
客户端身份验证:在 body
中发送客户端凭据单击 [清除 cookie] 和 [获取新访问令牌]