基本上,要调用受Azure AD保护的支持OAuth2.0授权第三方应用程序的REST,我们需要传递一个承载令牌。
为了查看代码示例,请确保您按照README.md的步骤列表进行操作。
注意:README.md中有关于配置权限的内容尚不清楚。代码示例使用的是代替Microsoft Graph的Azure AD图表,我们需要选择Windows Azure Active Directory而不是Microsoft Graph。我已经报告了这个问题here。
你可以看到有一个静态的申请命名,其中将设置当用户登录使用像下面Startup.Auth.cs代码值类AuthenticationHelper 令牌 :(不使用证书)
// Create a Client Credential Using an Application Key
ClientCredential credential = new ClientCredential(clientId, appKey);
string userObjectID = context.AuthenticationTicket.Identity.FindFirst(
"http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationContext authContext = new AuthenticationContext(Authority, new NaiveSessionCache(userObjectID));
AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(
code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);
AuthenticationHelper.token = result.AccessToken;
这里是通过OAuth 2.0用户码流批获得令牌的详细进展情况:
更多细节这个流程可以参考here。