我正在生成使用以下方法运行API测试的授权令牌。
/// <summary>
/// This method returns the Bearer token with User as a claim
/// </summary>
/// <param name="tenantId">Tenant Id for the environment in use</param>
/// <param name="userName">Email Id of the user</param>
/// <param name="password">Password of the user</param>
/// <returns>string with the complete Bearer token</returns>
public async Task<string> GetAccessTokenROPC(string tenantId, string userName, string password)
{
string tokenUrl = string.Concat("https://login.microsoftonline.com/", tenantId, "/oauth2/v2.0/token");
var req = new HttpRequestMessage(HttpMethod.Post, tokenUrl)
{
Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
["client_id"] = this.utils.GetClientId(),
["scope"] = "user.read openid profile email offline_access",
["client_secret"] = this.utils.GetClientSecret(),
["username"] = userName,
["password"] = password,
["grant_type"] = "password"
})
};
响应成功生成,并具有以下声明的访问令牌。 我的查询是上述方法中代码的哪一部分负责音频声明以及如何设置https://graph.microsoft.com?:
{
"aud": "https://graph.microsoft.com",
"iss": "https://sts.windows.net/fa774de7-cc34-4a2d-838f-b83fdexxxxxxx/",
"iat": 1558960514,
"nbf": 1558960514,
"exp": 1558964414,
"acct": 0,
"acr": "1",
"aio":
.
.
.
}
答案 0 :(得分:0)
您要求提供user.read范围,它是https://graph.microsoft.com/user.read
的简写形式。
因此,您要求一个令牌来调用MS Graph API。并且您获得了令牌以将请求传递到该令牌。 如果您希望访问令牌具有不同的访问者,则可以为另一个API指定范围。