Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing custom parameters to Identity Server 3

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?

like image 519
Kaspars Ozols Avatar asked Apr 19 '16 10:04

Kaspars Ozols


1 Answers

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).

Update (Logging out)

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...

like image 178
Scott Brady Avatar answered Nov 15 '22 08:11

Scott Brady