jeudi 19 août 2021

How do I add another check condition in this statement C# asp.net core

I have three case like this

  1. When the user first sign in I will validate their request session id to build the cookie
  2. When the user is already authenticated (previously signedin), I will validate the sessionId from their claim.

However there is another case that comes up

  1. When the user is already authenticated (previously signedin), do a certain activity, that can potentially prompt a change in their session Id, now if I validate with the session Id from their claim it will be wrong so I have to detect if there is a change between the claimSessionId and the requestSessionId => validate their requestSessionId.
var sessionToValidate = !UserPreviouslySignedIn() 
                ? GetRequestSessionId()
                : GetClaimSessionId();

await ValidateUserRequest(context, sessionToValidate);

How do I apply the check condition that a user may previously signed in but if sessionId != claimId then validate sessionid to this block of code and not having a bunch of if condition?

Aucun commentaire:

Enregistrer un commentaire