使用Dotnetopenauth从Azure AD获取授权令牌

问题描述:

我想通过DotNetOpenAuth库从Azure AD获取授权令牌。我不想使用ADAL,因为我在.net 3.5中有一个巨大的项目,并且ADAL不支持.net 3.5(仅.net> 4)。但是,我无法完全使用Azure AD。我不知道要配置什么。到目前为止,这是我的:使用Dotnetopenauth从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 =新的URI( “” /*放什么HERE */),

TokenEndpoint =新的URI( “” /* WHAT TO PUT HERE */

检查是否GitHub示例帮助您进行身份验证。它有3种方法用于验证和获取具有详细说明的身份验证令牌。检查app.config中的样本值和方法注释以获取有关所需内容的详细信息。

链接到示例:Azure Authentication GitHub Sample

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

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

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

哪里{tenantId}是你的租户的GUID标识符。它也可能与您的域一起工作,但我没有检查过。