我正在使用下面的方法生成授权令牌来运行我们的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"
})
};响应成功生成,并具有以下声明的访问令牌。我的疑问是,上面方法中的哪部分代码负责aud声明,以及它是如何设置为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":
.
.
.
}发布于 2019-05-28 23:43:34
您要求的是user.read作用域,它是https://graph.microsoft.com/user.read的缩写。
因此,您请求一个令牌来调用MS Graph API。你得到了一个令牌,在请求中传递到那里。如果您想要一个具有不同受众的访问令牌,则需要为另一个API指定作用域。
https://stackoverflow.com/questions/56345362
复制相似问题