【问题标题】:Obtaining authorization token from Azure AD with Dotnetopenauth使用 Dotnetopenauth 从 Azure AD 获取授权令牌
【发布时间】:2016-11-30 06:32:51
【问题描述】:

我正在尝试通过 DotNetOpenAuth 库从 Azure AD 获取授权令牌。我不想使用 ADAL,因为我在 .net 3.5 中有一个庞大的项目,而 ADAL 不支持 .net 3.5(仅 .net > 4)。但是,我不能完全让它与 Azure AD 一起使用。我不知道要配置什么。到目前为止,这就是我所拥有的:

    private static WebServerClient _webServerClient;
    private static string _accessToken;
    // Client ID (as obtained from Azure AD portal)
    private static string clientId = "here goes my client id guid";
    // Client Secret (as obtained from Azure AD portal)
    private static string appKey = "here goes my secret";
    private static string aadInstance = "https://login.microsoftonline.com/{0}";
    private static string tenant = "mytenant.domain.com";
    private static string authority = string.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
    // Azure AD resource I am trying to access
    private static string serviceResourceId = "https://mytenant.domain.com/protectedresource";


    private static void InitializeWebServerClient()
    {
        var authorizationServer = new AuthorizationServerDescription
        {
            AuthorizationEndpoint = new Uri(""/* WHAT TO PUT HERE */),
            TokenEndpoint = new Uri(""/* WHAT TO PUT HERE */)
        };
        _webServerClient = new WebServerClient(authorizationServer, clientId, appKey);
    }



    private static void RequestToken()
    {
        var state = _webServerClient.GetClientAccessToken();
        _accessToken = state.AccessToken;
    }

    static void Main(string[] args) {
        InitializeWebServerClient();
        RequestToken();
    }

问题是我不知道该放什么。我不知道我应该在这里放置什么值:

AuthorizationEndpoint = new Uri(""/* 在这里放什么 */),

TokenEndpoint = new Uri(""/* 在这里放什么 */)

【问题讨论】:

    标签: azure oauth-2.0 access-token dotnetopenauth azure-active-directory


    【解决方案1】:

    检查此 GitHub 示例 是否可以帮助您进行身份验证。它有 3 种认证和获取认证令牌的方法,并附有详细说明。检查 app.config 以获取示例值和方法 cmets 以了解所需内容的详细信息。

    示例链接:Azure Authentication GitHub Sample

    示例的相关博客:Azure Authentication - Authenticating any Azure API Request in your Application

    【讨论】:

      【解决方案2】:

      我相信你想要的两个端点是:

      https://login.windows.net/{{tenantId}}/oauth2/authorize
      https://login.windows.net/{tenantId}/oauth2/token
      

      {tenantId} 是租户的 GUID 标识符。它也可能适用于您的域,但我还没有检查过。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-16
        • 1970-01-01
        • 1970-01-01
        • 2011-06-12
        • 1970-01-01
        • 2023-01-19
        相关资源
        最近更新 更多