I am using Identity Server 3 + OpenID Connect + OAuth 2.0 to implement Single Sign On in one of my projects. I have set up everything according to samples provided and everything works just fine. I am using Implicit flow to authenticate user in multiple MVC websites.
Now I have a use case when I need to pass custom parameters from client application to identity server. One of the simplest examples would be custom message that needs to be shown in one of Identity Server views. I would like to render this message in different pages - login, logout, logged out, etc.
I found that OpenIdConnectAuthentication middleware from Microsoft allows to set custom parameters in ProtocolMessage in RedirectToIdentityProvider notification.
For example,
RedirectToIdentityProvider = async ctx =>
{
ctx.ProtocolMessage.Parameters.Add("info_message", "Account activation succeeded. Please log in using new account.");
}
}
Unfortunately, I was not able to find where those parameters can be read in Identity Server. Is this even possible?
If this is not supported or just plain wrong, could you please advise what would be the best way to handle this use case?
When passing in custom parameters you should be using the OpenID Connect optional parameter of acr_values
. This is already used by Identity Server for passing through Tenant name and Identity Provider restrictions.
You can read acr_values
within Identity Server whenever you have access to IdentityServer3.Core.Models.SignInMessage
(for example in your user service).
acr_values
isn't part of logging out. If you really want to get a custom parameter here, it can be done by extending the DefaultViewService
and overriding the LoggedOut
method.
In this method you can see any extra URL parameters in the SignOutMessage
's ReturnUrl
property.
Once you have your value you can add it to the ViewModel using something like the following:
model.Custom = new { customMessage = "your value" };
You'll then need to create your own template for the logout page and have it display your custom value.
This isn't nice and it isn't pretty. I wouldn't recommend it but it certainly is possible...
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