我已经在 Azure 中为 Microsoft Identity 平台注册了一个应用程序。我将其配置为允许 MS 帐户(例如 outlook.com),并且基本上在此处和此处的一些在线快速入门中完成了所有操作的一些在线快速入门中完成了所有操作(“向您的 Web 应用程序添加凭据”除外)。我还选中了启用隐式流的框。
我将我的 React 应用程序重定向到要登录的 URL(使用隐式流程),我输入了我的用户名,但随后我看到了
未授权客户端:客户端不存在或未为消费者启用。如果您是应用程序开发人员,请通过 Azure 门户中的应用程序注册配置新应用程序,网址为https://go.microsoft.com/fwlink/?linkid=2083908
就像我上面提到的那样,我已经经历了几个快速入门并在这里阅读了有关隐式流程的信息,并按照他们的示例编写了我的代码。
我还尝试删除应用程序注册并重新开始。没运气。
尝试实现隐式流的 JS 代码
将浏览器重定向到类似于 Microsoft 在其隐式流页面上的第一个示例的 URL 的 JS 代码
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 -> 身份验证
- 重定向 Uri:http://localhost:3000/signin(React 应用程序在 3000 上运行,我为 /signin 配置了路由)
- 不使用任何建议的重定向。
- 已选中 ID 令牌和访问令牌的隐式复选框
- 启用实时 SDK 支持
- 支持的帐户类型设置为“任何组织目录中的帐户和个人 Microsoft 帐户(例如 Skype、Xbox、Outlook.com)”
Azure -> 身份 -> 应用注册 -> MyApp -> API 权限
- 质谱图
- 用户读
- 电子邮件
- 轮廓
- 打开ID
从我阅读的文档中,我认为我已经对 id 令牌做了足够的工作。我不确定必须进行哪些调整才能使其正常工作。

