這裏從模板項目調用微軟圖形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」的參數。 –