让我首先说这是我的第一个.net核心应用程序,因此我可能会在这里以一个白痴的身份出现。一般来说,我也是新的代币。从asp.net核心获取Microsoft Graph的访问令牌认证Web应用程序
这么说,我有一个应用程序,它验证对Azure的AD用户像这样:
Startup.cs
using Microsoft.AspNetCore.Authentication.Cookies;
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAuthentication(
SharedOptions => SharedOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);
services.AddAuthorization(options =>
{
//Auth Policies using group claims
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//loggerFactory
app.UseCookieAuthentication();
app.UseOpenIdConnectAtuhentication(new OpenIdConnectOptions
{
ClientID = Configuration["Authentication:AzureAd:ClientId"],
Authority = Configuration["Authentication:AzureAd:AADInstance"] + Configuration["Authentication:AzureAd:TenantId"],
CallbackPath = Configuration["Authentication:AzureAd:CallbackPath"]
});
//Mvc Routing
}
AccountController.cs
[HttpGet]
public IActionResult SignIn()
{
return Challenge(
new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectDefaults.AuthenticationScheme);
}
在控制器我要保护然后我用[Authorize(Policy = "Whatever")]
所有这些都是工作g reat,所以我的问题是我已经拥有的cookie是否包含我需要的令牌,如果是这样,我可以简单地使用User.Claims来访问它,还是需要使用IAuthenticationProvider
来设置它的示例。 net 4.6 Here。
如果是后者,我如何在没有使用Owin的情况下如此操作?
我应该补充说,虽然授权工作正常,但现在我想要做的事情包括像列出OU中的所有用户这样的事情。据我所知,我必须访问Microsoft Graph。也许,我正在走向完全错误的方向?
相关:https://stackoverflow.com/questions/41519132/how-to-store-the-token-received-in-acquiretokenasync-with-active-directory –