小编Fer*_*nSW的帖子

How to access database during OpenID (MSAL) authentication

I've used this sample to configure OpendID authentication for Azure AD with the MSAL v2 library. It uses the AzureAdAuthenticationBuilderExtensions class to configure OpenId connect events (code shown below).

I want to access my database (EF Core) within those events to check the tenantId and add some custom user claims. The problem is that the injected database context (services.AddDbContext()) is a scoped service and cannot be called within the Configure method.

public static AuthenticationBuilder AddAzureAd(this AuthenticationBuilder builder)
        => builder.AddAzureAd(_ => …
Run Code Online (Sandbox Code Playgroud)

asp.net-core azure-ad-msal azure-authentication

2
推荐指数
1
解决办法
756
查看次数