Closed fredrik-lundin closed 6 years ago
You can derive from our default authorize interaction generator - and always trigger login. Don't have a sample - but search for an interface with Interaction in it ;)
Thanks for a very quick response and a great product!
Following your suggestion worked fine for us. Here is a really quick explanation of we solved it, if someone finding the issue in the future would be interested :)
AuthorizeInteractionResponseGenerator
and overrode the ProcessLoginAsync
methodpublic class ValidateAuthenticationMethodsAuthorizeInteractionResponseGenerator : AuthorizeInteractionResponseGenerator
{
public ValidateAuthenticationMethodsAuthorizeInteractionResponseGenerator(
ILogger<AuthorizeInteractionResponseGenerator> logger,
IdentityServerOptions options,
IConsentService consent,
IProfileService profile,
IConfiguration configuration)
: base(logger, options, consent, profile)
{ }
protected override Task<InteractionResponse> ProcessLoginAsync(ValidatedAuthorizeRequest request)
{
if (!request.Subject.IsAuthenticated())
{
return Task.FromResult(new InteractionResponse { IsLogin = true });
}
return ValidateUsedAuthenticationMethods(request); // Custom logic
}
....
}
IAuthorizeInteractionResponseGenerator
with your custom implementation in DIservices.AddIdentityServer(...);
var validateAuthenticationMethodsResponseGenerator = new ServiceDescriptor(
typeof(IAuthorizeInteractionResponseGenerator),
typeof(ValidateAuthenticationMethodsAuthorizeInteractionResponseGenerator),
ServiceLifetime.Transient);
services.Replace(validateAuthenticationMethodsResponseGenerator);
@fredrik-lundin
Hi, I implemented your code in your second post but it doesnt seems like ProcessLoginAsync
gets executed.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Hi,
I'm in a scenario where our SSO (identity server) has several clients. Different clients requires to be authenticated using different authentication methods.
QUESTION/TL;DR: Can we force identity server to run our login logic when in an already authenticated state, without having the user include prompt="login" in their auth request?
Background: To make this work right now, we are doing the following:
IdentityProviderRestrictions
property)User.GetAuthenticationMethods()
) to see if the we get a match. If we do, the authentication is fine and we just redirect back to the return url. Else, we force the user to login again, with a valid authentication method for the current clientIt looks something like this (maybe the code explains it better than my words..):
SignInAsync
. We merge the already used with the new authentication method into theauthenticationMethods
parameter. This allows us to add more authentication methods to the current SSO sessionForcing login on request to authorization endpoint To make this work, we obviously need to be able to run our login logic with every authorization request. Right now, the only solution we have found for this is to tell all our clients to include prompt="login" in their auth requests.
We would really like to find a way to trigger this behavior without relying on our clients having to include the prompt flag.
IdentityProviderRestrictions
and why we can't use it Identity server already supports a similar scenario with theIdentityProviderRestrictions
property on theClient
class. Though the logic for checking that property is to see if the currentIdp is in the IdentityProviderRestrictions list. This is not what we want, since thecurrentIdp
is not the list of used authentication methods, but just a single instance of the idp used. From the source code (link to code):