【发布时间】:2018-03-15 12:32:49
【问题描述】:
我找到了一个tutorial,我可以在其中使用 Azure AD 凭据登录我的应用程序。
在我的前端中,我使用的是 Xamarin.Forms。 在我的后端,我使用 ASP.NET Core 2.0 WebApi。
后端:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseAuthentication();
app.UseMvc();
}
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.Authority = String.Format(Configuration["AzureAd:AadInstance"], Configuration["AzureAD:Tenant"]);
options.Audience = Configuration["AzureAd:Audience"];
});
}
这很简单。
在我的前端,我正在填写我的凭据并要求一个 access_token。
{
"token_type": "Bearer",
"scope": "user_impersonation",
"expires_in": "3600",
"ext_expires_in": "0",
"expires_on": "1507104075",
"not_before": "1507100175",
"resource": "my_resource",
"access_token": "my_access_token",
"refresh_token": "my_refresh_token"
}
我用bearer my_access_token 设置的Authorization 填写标题。
我的 Api 知道我的所有信息,因为它会自动使用我的 access_token 中的信息设置声明。此信息由 Azure AD 提供。 (全名,名,姓,...)
但是如何在我的前端获取这些信息?
【问题讨论】:
标签: asp.net-core xamarin.forms jwt azure-active-directory asp.net-core-webapi