我有一个 azure 的 B2C 应用程序。当我通过 Portal.azure.com 中的 Users 应用程序创建用户(或使用 postman 发出发布请求)时,我必须发送 B2C 应用程序的 client_secret 来刷新 token 。 但是,对于通过 Powershell 使用 azureAD 模块创建的用户,我收到一条错误消息,指出我不应发送 client_secret。
{
"error": "invalid_request",
"error_description": "AADB2C90084: Public clients should not send a client_secret when redeeming a publicly acquired grant.\r\nCorrelation ID: 39abec35-770c-42e6-bd65-438d6501a124\r\nTimestamp: 2018-04-09 14:43:13Z\r\n"
}
为什么会有这样的差异?如何使用图形 API 创建不需要 client_secret 的用户?
提前致谢! 德语
最佳答案
根据错误信息,我假设您使用的应用程序是原生应用程序(正如juunas所说,Powershell也是原生应用程序),在Oauth中也称为公共(public)客户端。 client_secret
仅当您的应用程序是 Web App/API 时才需要,在 Oauth 中也称为 secret 客户端。
使用 native 应用程序刷新访问 token :
// Line breaks for legibility only
POST /{tenant}/oauth2/token HTTP/1.1
Host: https://login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
client_id=6731de76-14a6-49ae-97bc-6eba6914391e
&refresh_token=OAAABAAAAiL9Kn2Z27UubvWFPbm0gLWQJVzCTE9UkP3pSx1aXxUjq...
&grant_type=refresh_token
&resource=https%3A%2F%2Fservice.contoso.com%2F
NOTE: The application secret that you created in the app registration portal for your app. It cannot be used in a native app (public client), because
client_secrets
cannot be reliably stored on devices. It is required for web apps and web APIs (all confidential clients), which have the ability to store theclient_secret
securely on the server side.
因此,您只需删除请求正文中的 client_secret
即可解决此问题。
此外,Azure AD B2C 不支持 client_credentials 流。查看有关此的详细信息 here .
关于azure - 刷新 token azure b2c 不需要 client_secret,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49736910/