0 votes
in Education by (1.7m points)
Is there any way to add a custom parameter to identityserver auth request. I tried this way. but it will add parameters return URL, not as auth request query strings.

 Events = new OpenIdConnectEvents

    {

        OnRedirectToIdentityProvider = context =>

        {

            if (context.Properties.Items.ContainsKey("connection"))

                context.ProtocolMessage.SetParameter("connection", context.Properties.Items["connection"]);

            return Task.FromResult(0);

        }

    }

but I need to have those parameters on request URL not a parameter of return url..

JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by (1.7m points)
The request url looks like:

https://login.dev.domain.com/connect/authorize?client_id=657ce44e-10a2-4b66-9078-7f1acf92811f&redirect_uri=https%3A%2F%2Fmyapp.dev.domain.com%2Fsignin-oidc&response_type=code&scope=openid%20email&response_mode=form_post&nonce=636888568253105245.ODY4MzNjNGMtZDQxYi00YTkzLTg5OTctNTJkZGRjM2IwNGRjMjEwMWEzZGQtYWY1Mi00ODQ0LWE0ZGYtZTAxOWU0YjQyODkz&ui_locales=en&state=CfDJ8F-9xHJQT19NjH-KMvnd4SnuYPsaINrq_yn6DAfN8Y6h5aHBoukF0TPqZHOYk0mroCw4tz-03ajp6cgaomZ8HnrE6Or6ZzzNdfUqzDpDNH4VwWCax8JwtsRreob9j-nsOnttzDkRVTCzVEjjHpR__OR498c-kVXf-RjudGPghE0K&x-client-SKU=ID_NETSTANDARD1_4&x-client-ver=5.2.0.0

where, in my case ui_locales=en is my custom parameter. It's not a part of redirect_uri, just one more query parameter, separated by & signs. That works when you need to pass some data to your IdP. When you need just to keep some data during the request and get it back with authorization response, you can involve the State pre-defined parameter.

services.AddAuthentication().AddOpenIdConnect(Constants.MyIdpName, Constants.MyIdpName, options => {

***           

options.Events = new OpenIdConnectEvents {

     OnRedirectToIdentityProvider = ctx => {

          var rcf = ctx.HttpContext.Features.Get<IRequestCultureFeature>();

              if (rcf.Provider != null) {

                    string lng = rcf.RequestCulture.Culture.TwoLetterISOLanguageName;

                    ctx.ProtocolMessage.Parameters.Add("ui_locales", lng == "nn" || lng == "nb" ? "no" : lng);

              }

              return Task.CompletedTask;

          }

     }

}
...