I have been trying to add a parameter in the Login URL. E.g.
services.AddIdentityServer(options =>
{
options.UserInteraction.LoginUrl = "/{culture}/account/login";
});
Is it possible to have such types of parameterized URLs? Also, how would I pass this culture from my (JavaScript) client application? What other options do I have to retain this culture (e.g. as a query string parameter or route data)?
Thanks
You can pass dynamic values from client application using client oidc externParam. eg; for oidc-client library(https://www.npmjs.com/package/oidc-client)
// client side code
manager = new UserManager({
authority: localhost:5000 ,
client_id: xxx,
redirect_uri: xx,
response_type: 'code',
scope: 'openid profile .....',
//etc add more settings you need
};);
//initialize connection with identity server
//send settings to authorize endpoint (localhost:5000/connect/authorize)
this.manager.signinRedirect(
{
extraQueryParams: {abc:1} // you can add any number of custom key: value pairs
}
);
but now how to create dynamic options.UserInteraction.LoginUrl based on extraQueryParams received by identity Server at authorize endpoint? Example: I have two login pages login1 and login2; not on identity server but at some other url for instance localhost:4200/login1 localhost:4200/login2
now based on the extraQueryParams received you can add show either of these login pages using AuthorizeInteractionResponseGenerator.
//server side code
//startup.cs
services.AddIdentityServer()
.AddAuthorizeInteractionResponseGenerator<YourCustomAuthorizeEndpointResponseGenerator>();
//make new class
public class YourCustomAuthorizeEndpointResponseGenerator : AuthorizeInteractionResponseGenerator //extending default res generator; you can rewrite also using IAuthorizeInteractionResponseGenerator
{
public YourCustomAuthorizeEndpointResponseGenerator(ISystemClock clock,
ILogger<AuthorizeInteractionResponseGenerator> logger, IConsentService consent,
IProfileService profile,
IHttpContextAccessor httpContextAccessor,
IdentityServerOptions identityServerOptions, // Will be auto injected by identity server; use this to override loginUrl
)
: base(clock, logger, consent, profile)
{
if (httpContextAccessor.HttpContext.Request.QueryString.Value.ToString().Contains("abc=1"))
{
identityServerOptions.UserInteraction.LoginUrl = localhost:4200/login1;
}
else
{
identityServerOptions.UserInteraction.LoginUrl = localhost:4200/login2;
}
}
}
all redirection and callbacks will be taken care by identity server based upon the redirect_uri setting passed from client side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With