Azure:我如何获得刷新令牌?当连接的输出仅提供访问令牌时使用 Curl
Azure : How to i get the Refresh Token ? using Curl when the Output of the connection only gives Access Token
我无法使用 Azure 服务主体(使用客户端 ID 和客户端密码)获取刷新令牌
请帮助我通过 CURL 获取刷新令牌以及如何使用它。
当我在 Windows CMD 提示符中 运行 下面的 CURL 命令时,我正在获取访问令牌。而我没有获得刷新令牌。
我是不是遗漏了什么?
输入:
curl -X POST https://login.microsoftonline.com/12345/oauth2/token ^
-F grant_type=client_credentials ^
-F resource=https://management.core.windows.net/ ^
-F client_id=12345-abcde ^
-F client_secret=12345abcde
输出:
{
"token_type": "Bearer",
"expires_in": "3600",
"ext_expires_in": "3600",
"expires_on": "1554368330",
"not_before": "1554364430",
"resource": "https://management.core.windows.net/",
"access_token": "XXXXXXXXXXXXX"
}
因为输出没有刷新令牌(我怎么得到它)
恳请任何可能的见解
将grant_type更改为'password',在请求中添加用户名和密码。
curl -X POST https://login.microsoftonline.com/12345/oauth2/token ^
-F grant_type=password ^
-F resource=https://management.core.windows.net/ ^
-F client_id=12345-abcde ^
-F client_secret=12345abcde ^
-F username=user@XX.onmicrosoft.com ^
-F password=******
您将能够获得refresh_token。
{
"token_type": "Bearer",
"scope": "User.ReadWrite.All",
"expires_in": "3600",
"ext_expires_in": "3600",
"expires_on": "1554711949",
"not_before": "1554708049",
"resource": "https://management.core.windows.net/",
"access_token": "******",
"refresh_token": "******"
}
您可以使用refresh_token到refresh the access token。
您不会获得带有客户端 ID 和密码的刷新令牌。这没有意义。刷新令牌仅在涉及用户时才有意义。因为它允许您在不提示用户再次登录的情况下获取新令牌。
您不需要刷新令牌。您可以在需要时获得带有客户端 ID 和密码的新令牌。
给定一个现有的 refresh token
,此请求获得一个新的 access token
和一个新的 refresh token
,可以使用它们在到期期限之前迭代地获取新的 refresh token
,例如使用基于计时器的过程。
curl 'https://login.microsoftonline.com/common/oauth2/v2.0/token' \
-H "Origin: https://localhost" \
-H 'content-type: application/x-www-form-urlencoded;charset=utf-8' \
--data-raw "client_id=${CLIENT_ID}&refresh_token=${REFRESH_TOKEN}&grant_type=refresh_token&scope=openid%20profile%20User.Read%20offline_access"
我无法使用 Azure 服务主体(使用客户端 ID 和客户端密码)获取刷新令牌
请帮助我通过 CURL 获取刷新令牌以及如何使用它。
当我在 Windows CMD 提示符中 运行 下面的 CURL 命令时,我正在获取访问令牌。而我没有获得刷新令牌。
我是不是遗漏了什么?
输入:
curl -X POST https://login.microsoftonline.com/12345/oauth2/token ^
-F grant_type=client_credentials ^
-F resource=https://management.core.windows.net/ ^
-F client_id=12345-abcde ^
-F client_secret=12345abcde
输出:
{
"token_type": "Bearer",
"expires_in": "3600",
"ext_expires_in": "3600",
"expires_on": "1554368330",
"not_before": "1554364430",
"resource": "https://management.core.windows.net/",
"access_token": "XXXXXXXXXXXXX"
}
因为输出没有刷新令牌(我怎么得到它)
恳请任何可能的见解
将grant_type更改为'password',在请求中添加用户名和密码。
curl -X POST https://login.microsoftonline.com/12345/oauth2/token ^
-F grant_type=password ^
-F resource=https://management.core.windows.net/ ^
-F client_id=12345-abcde ^
-F client_secret=12345abcde ^
-F username=user@XX.onmicrosoft.com ^
-F password=******
您将能够获得refresh_token。
{
"token_type": "Bearer",
"scope": "User.ReadWrite.All",
"expires_in": "3600",
"ext_expires_in": "3600",
"expires_on": "1554711949",
"not_before": "1554708049",
"resource": "https://management.core.windows.net/",
"access_token": "******",
"refresh_token": "******"
}
您可以使用refresh_token到refresh the access token。
您不会获得带有客户端 ID 和密码的刷新令牌。这没有意义。刷新令牌仅在涉及用户时才有意义。因为它允许您在不提示用户再次登录的情况下获取新令牌。
您不需要刷新令牌。您可以在需要时获得带有客户端 ID 和密码的新令牌。
给定一个现有的 refresh token
,此请求获得一个新的 access token
和一个新的 refresh token
,可以使用它们在到期期限之前迭代地获取新的 refresh token
,例如使用基于计时器的过程。
curl 'https://login.microsoftonline.com/common/oauth2/v2.0/token' \
-H "Origin: https://localhost" \
-H 'content-type: application/x-www-form-urlencoded;charset=utf-8' \
--data-raw "client_id=${CLIENT_ID}&refresh_token=${REFRESH_TOKEN}&grant_type=refresh_token&scope=openid%20profile%20User.Read%20offline_access"