c# - .NET Core WebApi + Angular 身份验证和授权通过 Microsoft Azure 中的应用程序
问题描述
我们在 Angular 上有 2 个 Web 应用程序(FE_1,FE_2),在 .NET Core 上有 3 个 API 应用程序(见图) 需要从一个站点一次登录并在两个站点之间工作而无需任何额外的授权过程 我的意思是,当我们登录到site1 并接收令牌 #1,我希望此令牌也可以与 API_2 一起使用,反之亦然,当我们登录到 site2 并接收令牌 #2 时,我希望使用此令牌与 API_1 一起使用
所以我的问题是如何在 Azure 中正确配置应用程序并根据所描述的架构在内部配置它们?
解决方案
谢谢你曼尼什。发布您的建议作为帮助其他社区成员的答案。
从 BE 代码中提供的架构中,根据下图添加有效受众列表,使其为真
下面是示例代码,您可以在其中检查有效的受众代码。
services.AddAuthentication(cfg =>
{
cfg.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
cfg.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(opt =>
{
opt.Authority = "https://login.microsoftonline.com/common";
opt.Audience = "api://A134d6c8-8078-2924-9e90-98cef862eb9a"; // Set this to the App ID URL for the web API, which you created when you registered the web API with Azure AD.
opt.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidAudiences = new List<String>
{
// you could add a list of valid audiences
"A134d6c8-8078-2924-9e90-98cef862eb9a"
},
ValidIssuers = new List<string>
{
// Add tenant id after https://sts.windows.net/
"https://sts.windows.net/{YourTenantId}"
}
};
opt.Events = new JwtBearerEvents()
{
OnAuthenticationFailed = AuthenticationFailed
};
});
有关完整信息,请查看SO。
推荐阅读
- sql - Pl/ SQL 更新触发器,用于在对表进行更新操作时更新排名
- python - python AI的数据集预处理
- c - C vsnprintf() 忽略最后一个参数
- c - heapusage 检测到可能由 printf 引起的内存泄漏
- java - 在多次 POST/DELETE/PUT 后仅运行一次功能(例如清理)
- html - 复杂角材料表单元
- java - 无法在 Android Studio 中解析符号“R”但编译没有问题
- angular - Angular 7 - 在 For 循环中展开或折叠 Div
- java - 基本 Cucumber 测试项目 - 如何运行 java cucumber.api.cli.Main?
- shell - 在文件夹中存在的多个文件中将日期部分动态替换为当前日期 -15 天