在本地数据库中搜索用户并向用户身份添加声明
我有一个内部使用的 Blazor 网页,想要使用我的 Azure AD 进行身份验证。用户登录后,我想从我的现场数据库中的 AzureID 搜索他们的姓名/ID/某些内容,并添加他们的员工编号,以便我可以在整个程序中使用它。
这是最好的方法吗?
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(
options =>
{
Configuration.Bind("AzureAd", options);
options.Events = new OpenIdConnectEvents();
options.Events.OnTokenValidated = OnTokenValidatedFunc;
}, options => { Configuration.Bind("AzureAd", options); })
.EnableTokenAcquisitionToCallDownstreamApi(options => Configuration.Bind("AzureAd", options), initialScopes)
.AddMicrosoftGraph(Configuration.GetSection("GraphAPI"))
.AddInMemoryTokenCaches();
它将使用该事件来搜索我的 EmployeeID
var oid = context.SecurityToken.Payload.FirstOrDefault(z => z.Key == "oid");
// Get the user his ID from the database
var employee = EmployeeLogic.GetEmployee()
.FirstOrDefault(x => x.AzureObjectId == oid.Value.ToString());
context.Principal?.Identities.FirstOrDefault()?
.AddClaim(new Claim("EmployeeID", employeeId.ToString(CultureInfo.InvariantCulture)));
,或者是否有更好的方法来添加我可以用作本地数据库标识符的内容。
提前致谢 莫里斯
I have an internally used Blazor webpage and want to use my Azure AD to authenticate against. After the user is logged in I want to search their name/ID/Something from AzureID in my onsite database and add their employee number so I can use it in the whole program.
Is this the best way?
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(
options =>
{
Configuration.Bind("AzureAd", options);
options.Events = new OpenIdConnectEvents();
options.Events.OnTokenValidated = OnTokenValidatedFunc;
}, options => { Configuration.Bind("AzureAd", options); })
.EnableTokenAcquisitionToCallDownstreamApi(options => Configuration.Bind("AzureAd", options), initialScopes)
.AddMicrosoftGraph(Configuration.GetSection("GraphAPI"))
.AddInMemoryTokenCaches();
Which will use the event to search for my EmployeeID
var oid = context.SecurityToken.Payload.FirstOrDefault(z => z.Key == "oid");
// Get the user his ID from the database
var employee = EmployeeLogic.GetEmployee()
.FirstOrDefault(x => x.AzureObjectId == oid.Value.ToString());
context.Principal?.Identities.FirstOrDefault()?
.AddClaim(new Claim("EmployeeID", employeeId.ToString(CultureInfo.InvariantCulture)));
or is there a better way to add something which I can use as Identifier to my local Database.
thanks in advance
Maurice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论