是否可以直接在azure中通过clientId等url碎片获取token?

Can I get the token through url fragement such as clientId etc. in azure directly?

假设我在 azure 中有 clientId、tenantId、tokenType、redirectUri 等。我可以使用这些参数直接获取访问令牌吗?

我知道有一种方法可以将它们组合在一起以创建一个长字符串。

const url = 'https://login.microsoft.com/'+ tenantId+'/oauth2/v2.0/authorize?client_id='+clientId+'response_type=id_token&redirect_uri=window.location.origin&response_mode=fragment&scope=openid&state=11111&nonce=11111';

那我新开一个window

window.open(url, '_self');

一旦新的 window 弹出,url 就很长了。它包含了token和idtoken的所有信息。

但我不想使用这种方式,因为在 uri 中公开令牌是一件坏事。我想直接使用clientId等获取代码中的url片段。我猜 msal 内部破解了它,但不确定。

更新:

我的意思是我将长字符串放入 POSTMAN post 请求中,甚至设置 response_mode=form_post 然后单击发送按钮,但我只得到了一堆 HTML。这是正确的做法吗?

您可以尝试使用 response_mode=form_post、access_token ,id_token 将作为 post 参数发送以重定向 url。由于令牌是 post 参数的一部分,因此它不是 url 的一部分,而是请求正文的一部分。您可以使用开发者工具查看请求的 http trace。

自己找答案。 https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-implicit-grant-flow

点击url中的postman,替换部分参数。令牌将显示在 redirecturi 地址栏中。但它并不好,因为它是隐式流。

隐式流一般用在单页应用中。如果您使用的不是单页应用程序,那么使用此流程将毫无意义。

auth code flow只能在浏览器中获取授权码,然后在postman中使用授权码兑换token。 auth code流程不支持直接在浏览器地址栏获取token,所以你的问题应该使用交互式登录auth code流程。

1.Request浏览器中的授权码。

https://login.microsoftonline.com/{tenant id}/oauth2/v2.0/authorize?
client_id={client app client id}
&response_type=code
&redirect_uri={redirect_uri}
&response_mode=query
&scope=https://graph.microsoft.com/.default
&state=12345

2.Redeem 邮递员中的令牌。