Run code after openid connect login in Asp.net Core

I am trying to find the best way to run some code as soon as the user authenticated himself using OpenID Connect in the Dotnet Core MVC application. I don’t want to hardcode the redirect URL after logging in, because they should still be where they tried to go after authentication. I just need to run the code, for example. "check if it is registered the first time and set the flag" or something like that.

I used average software, but since it is called for every request, it causes some problems.

Does anyone have any ideas on how to achieve this?

+6
source share
2 answers

I believe that this type of selective rerouting should be done inside a class that inherits from AuthorizeAttribute; It can use many preamble actions, including the use of additional role contexts.

, (. "" ). MVC- . "TandC_Consent" ( ) , , [AuthorizePermission("TandC_Consent")] .

github , AuthorizeAttribute [AuthorizePermission()].

0

, , , , IdentityServer3. IUserService, , . - PostAuthenticateAsync IdentityServer3:

. , . . PostAuthenticationContext : SignInMessage: , . AuthenticateResult: AuthenticateResult. .

context AuthenticateResult, :

public override Task PostAuthenticateAsync(PostAuthenticationContext context)
{
    // code that will determine target url
    // redirectPath = ...
    context.AuthenticateResult = AuthenticateResult(redirectPath, claims);
}

redirectPath / ~/"

IUSerService.

0

All Articles