【问题标题】:Azure AuthenticationContext | What should be the value of the first parameter "authority"Azure AuthenticationContext |第一个参数“权限”的值应该是多少
【发布时间】:2019-02-16 21:54:37
【问题描述】:

我指的是以下文章:https://docs.microsoft.com/en-us/azure/storage/blobs/storage-encrypt-decrypt-blobs-key-vault

我需要帮助来理解下面粘贴的方法的参数:

private async static Task<string> GetToken(string authority, string resource, string scope)
{
    var authContext = new AuthenticationContext(authority);
    ClientCredential clientCred = new ClientCredential(
        ConfigurationManager.AppSettings["clientId"],
        ConfigurationManager.AppSettings["clientSecret"]);
    AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientCred);

    if (result == null)
        throw new InvalidOperationException("Failed to obtain the JWT token");

    return result.AccessToken;
}

请告知GetToken(字符串权限,字符串资源,字符串范围)的值应该是什么

【问题讨论】:

    标签: azure azure-active-directory azure-keyvault


    【解决方案1】:

    授权 - https://login.windows.net/&lt;your AD tenant GUID&gt;(这是颁发令牌的授权)

    资源 - https://vault.azure.net(这是请求令牌的资源)

    Scope - 这种情况下的空字符串。请注意,它是您方法中的一个参数,但实际上并没有在任何地方使用。

    另外请注意,在使用对象模型时,您会在极少数情况下直接调用此方法。很可能,您只需将此方法的委托传递给 KeyVaultClient.AuthenticationCallback 或 KeyValutKeyResolver,就像您分享的教程中所示。

    【讨论】:

      【解决方案2】:

      一个很好的example(我稍微修改了代码,因为它已经过时并且使用了您的客户端/机密值),用于使用 AD 凭据获取 KeyVaultClient()。

      var keyVaultClient = new KeyVaultClient(async(authority, resource, scope) =>
      {
          var adCredential = new ClientCredential(ConfigurationManager.AppSettings["clientId"],
              ConfigurationManager.AppSettings["clientSecret"]);
          var authenticationContext = new AuthenticationContext(authority, null);
          var authenticationResult = await authenticationContext.AcquireTokenAsync(resource, adCredential);
          return authenticationResult.AccessToken;
      });
      

      authorityresourcescope由SDK提供(即您不必为它们提供值),并传递给委托函数AuthenticationCallback,该函数返回要获取的令牌密钥保管库客户端。希望这可以帮助! :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-02-10
        • 1970-01-01
        • 2018-02-07
        • 2021-11-02
        • 2018-12-11
        • 2022-01-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多