SaaS CMS has officially launched! Learn more now.

Startup class OIDC get URLs from CMS

ZZ
ZZ
Vote:
 

I am trying to implement OIDC (Startup class) in our CMS solution.

How can I get the URLs to redirectUri (login action method), error and postlogoutRedirectUri (homepage) without hardcoding / getting from web.config ?

 public class Startup
    {
        private readonly string _clientId = "xxxxxx";
        private readonly string _redirectUri = "http://localhost:8080/OIDClogin";
        private readonly string _postLogoutRedirectUri = "http://localhost:8080/";
        private readonly string _authority = "xxxxx";
        private readonly string _clientSecret = "xxxxx";

        public void Configuration(IAppBuilder app)
        {
            // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=316888
            ConfigureAuth(app);
        }

        public void ConfigureAuth(IAppBuilder app)
        {
            //app.UseCookieAuthentication(new CookieAuthenticationOptions
            //{
            //    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            //    LoginPath = new PathString("/Home/Signin"),
            //    CookieSameSite = SameSiteMode.None,
            //});
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            _ = app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                ClientId = _clientId,
                ClientSecret = _clientSecret,
                Authority = _authority,
                RedirectUri = _redirectUri,
                PostLogoutRedirectUri = _postLogoutRedirectUri,
                ResponseType = OpenIdConnectResponseType.CodeIdToken,
#270564
Edited, Jan 26, 2022 8:28
Vote:
 

Why don't you want to put it in the web.config? The standard approach is to keep the Uri paths the same for each site and change the domain depending on the context. Here you can see an example of how to do that (see the HandleMultiSiteReturnUrl method):

https://github.com/episerver/Quicksilver/blob/master/Sources/EPiServer.Reference.Commerce.Site/Infrastructure/Owin/MixedModeAuthStartup.cs

You could use a similar approach and use ContentReference.StartPage.GetPublicUrl() for example to get the current homepage URL.

#272632
Feb 21, 2022 2:27
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.