首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ROPC访问令牌中设置aud声明值

如何在ROPC访问令牌中设置aud声明值
EN

Stack Overflow用户
提问于 2019-05-28 23:18:27
回答 1查看 55关注 0票数 0

我正在使用下面的方法生成授权令牌来运行我们的API测试。

代码语言:javascript
复制
    /// <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的?:

代码语言:javascript
复制
{
  "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": 
  .
  .
  .
}
EN

回答 1

Stack Overflow用户

发布于 2019-05-28 23:43:34

您要求的是user.read作用域,它是https://graph.microsoft.com/user.read的缩写。

因此,您请求一个令牌来调用MS Graph API。你得到了一个令牌,在请求中传递到那里。如果您想要一个具有不同受众的访问令牌,则需要为另一个API指定作用域。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56345362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档