samples icon indicating copy to clipboard operation
samples copied to clipboard

404 problem

Open FixRM opened this issue 2 years ago • 1 comments

Hello! Sorry for asking stupid things, but help will be really appreciated. I'm trying to follow your blog post. The following code works like a charm with Microsoft.AspNetCore.Authentication.OpenIdConnect:

            services
                .AddAuthentication(cfg =>
                {
                    cfg.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    cfg.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
                })
                .AddCookie()
                .AddOpenIdConnect(cfg =>
                {
                    cfg.Authority = "https://myoauthserver/";
                    cfg.ClientId = "hangfire";
                    cfg.ResponseType = "code";

                    cfg.Scope.Clear();
                    cfg.Scope.Add("openid");
                    cfg.Scope.Add("profile");
                });

but similar code don't with Microsoft.Owin.Security.OpenIdConnect:

            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);           

            app.UseCookieAuthentication(new CookieAuthenticationOptions {  });

            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions()
            {   
                Authority = "https://myoauthserver/",
                ClientId = "hangfire",
                ResponseType = OpenIdConnectResponseType.Code,
                Scope = OpenIdConnectScope.OpenIdProfile
            });

At first, it doesn't pass redirect_url if it is not set explicitly. But if I set it to something like RedirectUri = "http://localhost:9001/signin-oidc" or just RedirectUri = "http://localhost:9001/" myself, redirect works but I got 404 error for / or /signin-oidc endpoint. Am I doing something wrong? I'm using latest version of Microsoft.Owin.Security.OpenIdConnect and unfortunately I stuck with Framework.

FixRM avatar Apr 18 '23 13:04 FixRM

In case if somebody struggle with the same problem: try too add RedeemCode = true to OpenIdConnectAuthenticationOptions. It should work similar to Core version.

The only problem that left is the need to explicitly set RedirectUri parameter (

FixRM avatar Apr 19 '23 10:04 FixRM