这里从模板项目调用微软图形API是下降的问题,我面对的一休:Azure的活动目录 - 在VS2013
- 我创建了一个项目从VS2013,MVC多租户组织 帐户登录,使用AAD认证
- 项目模板工作正常,我,但我需要更多的,我需要 调用图形API
- 在GitHub上sample项目调用图形API也能正常工作对自己,但我们需要将相同的概念应用到我们的项目 这是基于模板从VS2013
- 当试图调用从使用类似的方式 我们的解决方案的图形API,它不工作
这是我一直在痛苦的总结经历过去几天。
VS2013项目模板使用此代码为签到方法在帐户控制:
WsFederationConfiguration config = FederatedAuthentication.FederationConfiguration.WsFederationConfiguration;
string callbackUrl = Url.Action("Index", "Home", routeValues: null, protocol: Request.Url.Scheme);
SignInRequestMessage signInRequest = FederatedAuthentication.WSFederationAuthenticationModule.CreateSignInRequest(
uniqueId: String.Empty,
returnUrl: callbackUrl,
rememberMeSet: false);
signInRequest.SetParameter("wtrealm", IdentityConfig.Realm ?? config.Realm);
return new RedirectResult(signInRequest.RequestUrl.ToString());
从GitHub上的示例项目使用这样的:
HttpContext.GetOwinContext()
.Authentication.Challenge(new AuthenticationProperties {RedirectUri = "/"},
OpenIdConnectAuthenticationDefaults.AuthenticationType);
然后在启动类它抓住了AuthorizationCodeReceived像这样:
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = Authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications()
{
//
// If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
//
AuthorizationCodeReceived = (context) =>
{
var code = context.Code;
然后它将它保存在th EA TokenCache,调用图形API时,启动AuthenticationContext类这样的高速缓存
AuthenticationContext authContext = new AuthenticationContext(Startup.Authority,
new NaiveSessionCache(userObjectID));
ClientCredential credential = new ClientCredential(clientId, appKey);
result = authContext.AcquireTokenSilent(graphResourceId, credential,
new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
我试图做的是这样的:
AuthenticationContext authContext = new AuthenticationContext(authority);
ClientCredential credential = new ClientCredential(clientId, appKey);
结果=等待authContext.AcquireTokenAsync(graphResourceId,凭据);
这会返回一个较短的标记,其中包含一些缺失的信息。
如果您使用MVC和组织帐户登录在VS2013中创建新项目,然后尝试调用图API,则可以轻松地复制此问题。
我需要一种使用VS2013的模板项目调用图API的方法。
你需要从AD得到什么样的信息?您需要使用此令牌调用图表API – Thomas
使用AAD进行身份验证的简单方法仅返回用户的登录名。我们的一位客户的登录信息与他们的电子邮件不同。我需要得到他们的电子邮件。有这个信息的图形返回了一个名为“mail”的参数。 –