MS Identity Azure 应用已注册但在隐式流中发送 unauthorized_client

MS Identity Azure app registered but sends unauthorized_client in implicit flow

我已在 Azure 中为 Microsoft Identity 平台注册了一个应用程序。我将其配置为允许 MS 帐户(例如 outlook.com),并且基本上完成了一些在线快速入门中的所有操作 here and here("add credentials to your web app" 除外)。我还选中了启用隐式流的框。

我将我的 React 应用程序重定向到 URL 以登录(使用隐式流程),我开始输入我的用户名,但随后我看到

unauthorized_client: The client does not exist or is not enabled for consumers. If you are the application developer, configure a new application through the App Registrations in the Azure Portal at https://go.microsoft.com/fwlink/?linkid=2083908

就像我上面提到的,我经历了几次快速入门并阅读了有关隐式流的内容 here 并在我的代码中遵循了他们的示例。

我也试过只删除应用程序注册并重新开始。运气不好。

JS 代码试图实现隐式流

将浏览器重定向到 Url 的 JS 代码,看起来像 Microsoft 在其 implicit flow page

上的第一个示例
goSignIn() {
    const tenant = 'common'; // (for us with MS accounts)
    const clientId = '*****';
    const redir = encodeURIComponent('http://localhost:3000/signin');
    const nonce = Math.round(Math.random() * 10000, 0);
    const uriTemplate = 'https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize?client_id={clientId}&response_type=id_token+token&redirect_uri={redirect}&scope=openid&response_mode=fragment&state={state}&nonce={nonce}';
    const filledTemplate = uriTemplate
      .replace('{tenant}', tenant)
      .replace('{clientId', clientId)
      .replace('{redirect}', redir)
      .replace('{nonce}', nonce)
      .replace('{state}', nonce);
    console.log(filledTemplate);
    window.location = filledTemplate;
  }

Azure 中的应用程序配置:

Azure -> 身份 -> 应用注册 -> MyApp -> 身份验证

Azure -> 身份 -> 应用注册 -> MyApp -> API 权限

根据我阅读的文档,我认为我已经对 id 令牌做了足够的工作。我不确定必须进行哪些调整才能使其正常工作。

看来您已经完成了足够的工作来获得令牌。我已经在我这边测试过了,效果很好。这里我把我的截图提供给你,你再看看。

此外,这是我的工作要求url,您可以使用您的msa登录进行测试。

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?
client_id=5fd66168-7ba3-4bbc-a155-bff662eed9f7
&response_type=id_token+token
&redirect_uri=http://localhost:3000/signin
&scope=openid
&response_mode=fragment
&state=12345
&nonce=678910

我遇到过这样的问题。我犯的错误与 App ID 有关:当您创建客户端密码时,Azure UI 将显示密码和密码 ID。此秘密 ID 不是 在您的应用程序配置中使用的 ID。相反,您需要在概览页面上找到的应用程序 ID。

我想可能有很多配置问题会产生此错误消息。总的来说:密切关注App ID,如果报错就是找不到app。