gpt4 book ai didi

azure - Microsoft 身份验证库 (MSAL) 登录弹出 : Error The "provided request must include a ' client_secret' input parameter. |

转载 作者:行者123 更新时间:2023-12-02 06:05:37 28 4
gpt4 key购买 nike

我正在尝试使用 MSAL 为我的单页应用程序添加 SSO,目的是获取用于解析 Microsoft SaaS 订阅的 Oauth2 token 。我已经根据此示例存储库配置了我的代码:https://github.com/Azure-Samples/ms-identity-javascript-v2 。这使用 MSAL 2.0,而不是 1.X 版本。

这是在 /signup 页面上运行的相关代码片段:

var config = {
auth: {
clientId: <MY_CLIENT_ID>,
authority: "https://login.microsoftonline.com/common",
redirectUri: <APP_URL> + "/signup",
},
cache: {
cacheLocation: "sessionStorage",
storeAuthStateInCookie: false,
}
};
var msalInstance = new msal.PublicClientApplication(config);
msalInstance.loginPopup(["openid", "profile", "User.Read"]).then((response) => {
console.log(response)
}).catch(error => {
console.error(error);
});

在我的应用程序中调用此代码,我使用弹出窗口成功登录,但出现以下错误:ServerError: invalid_client: 70002 - [2020-09-03 16:55:35Z]: AADSTS70002: The提供的请求必须包含“client_secret”输入参数。

我可以看到底层网络调用是https://login.microsoftonline.com/common/oauth2/v2.0/token,具有以下表单数据:

client_id: <MY_CLIENT_ID>
redirect_uri: <APP_URL>/signup
scope: openid profile
code: <some value>
code_verifier: <some value>
grant_type: authorization_code
client_info: 1
client-request-id: <some value>

基于此处的文档 https://learn.microsoft.com/en-us/advertising/guides/authentication-oauth-identity-platform?view=bingads-13#request-accesstoken ,此调用应该有一个可配置的 client_secret 参数,这会导致我收到的错误。

我从 Azure 门户上的应用程序获得了所需的客户端 key 。我的问题是,如何在我的 config 对象中配置客户端 key ?我无法在网上找到任何示例,并且我尝试盲目地将 clientSecret 添加为我的配置中 auth 下的 key ,这并没有将其传递给 login.microsoftonline.com 调用。

更新

经过一番深入研究,我意识到我的设置的根本问题是我试图使用 authorization grant flow请求 token 但需要使用 client credentials flow 。将 token 获取移至后端(并在那里使用客户端 key )之后,以及 this followup thread 中的更多帮助我能够按预期进行 SSO 和 token 获取。

最佳答案

这将解决您的问题,而不是创建 Web 创建单页应用程序。请参阅下面的示例

enter image description here

关于azure - Microsoft 身份验证库 (MSAL) 登录弹出 : Error The "provided request must include a ' client_secret' input parameter. |,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63728609/

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