okta / samples-aspnet

samples-aspnet
https://github.com/okta/samples-aspnet
Apache License 2.0
42 stars 107 forks source link

redirect URI https://localhost:44343/authorization-code/callback returns HTTP Error 404.0 - Not Found #63

Open jayheavner opened 2 years ago

jayheavner commented 2 years ago

I'm using this with Kentico 13 and that's where I'm getting the error. If I do a vanilla asp.net website it works ok.

I have my redirect URI configured properly in my application. /authorization-code/callback is hardcoded into the package and cannot be change. I'm not getting a browser 404 but rather the IIS 10 Detailed Error page 404. How do I debug this?

laura-rodriguez commented 2 years ago

Hi @jayheavner,

Can you please provide more details of your use case? What sample app are you working on (okta-hosted, self-hosted, etc)? Would you mind sharing your Startup class? (Make sure to mask your secrets).

jayheavner commented 2 years ago

I’m using the Okta-hosted sample app. Like I said, the sample app works fine but when I move the code to my application I get the 404. I’m using a CMS called Kentico. It’s still using 4.8 and web forms. It may be doing something in its middleware to handling routing, I don’t know. My startup class should be fine. It’s identical to the one in the sample app that is working. I can post it in the morning. It seems like you’re calling this thing web forms but it’s really more MVC. Installing OWIN to use it doesn’t seem very web forms. I get that pattern is out-dated but that’s what I’m stuck with.

On Mon, May 30, 2022 at 3:16 PM Laura Rodríguez @.***> wrote:

Hi @jayheavner https://github.com/jayheavner,

Can you please provide more details of your use case? What sample app are you working on (okta-hosted, self-hosted, etc)? Would you mind sharing your Startup class? (Make sure to mask your secrets).

— Reply to this email directly, view it on GitHub https://github.com/okta/samples-aspnet/issues/63#issuecomment-1141426743, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAY53PGNNQ6OYAKSMBBFK2TVMUH2LANCNFSM5XLLBIMA . You are receiving this because you were mentioned.Message ID: @.***>

-- Jay Heavner

jayheavner commented 1 year ago

See attached for my startup class and login handler.

Here are web.config key/values.

.... ....

On Mon, May 30, 2022 at 11:27 PM Jay Heavner @.***> wrote:

I’m using the Okta-hosted sample app. Like I said, the sample app works fine but when I move the code to my application I get the 404. I’m using a CMS called Kentico. It’s still using 4.8 and web forms. It may be doing something in its middleware to handling routing, I don’t know. My startup class should be fine. It’s identical to the one in the sample app that is working. I can post it in the morning. It seems like you’re calling this thing web forms but it’s really more MVC. Installing OWIN to use it doesn’t seem very web forms. I get that pattern is out-dated but that’s what I’m stuck with.

On Mon, May 30, 2022 at 3:16 PM Laura Rodríguez @.***> wrote:

Hi @jayheavner https://github.com/jayheavner,

Can you please provide more details of your use case? What sample app are you working on (okta-hosted, self-hosted, etc)? Would you mind sharing your Startup class? (Make sure to mask your secrets).

— Reply to this email directly, view it on GitHub https://github.com/okta/samples-aspnet/issues/63#issuecomment-1141426743, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAY53PGNNQ6OYAKSMBBFK2TVMUH2LANCNFSM5XLLBIMA . You are receiving this because you were mentioned.Message ID: @.***>

-- Jay Heavner

-- Jay Heavner

using Microsoft.Owin.Security; using Microsoft.Owin.Security.OpenIdConnect; using System; using System.Linq; using System.Web; using System.Web.UI.WebControls;

namespace CMSApp.CMSPages { public partial class OktaLogin : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Request.IsAuthenticated) { HttpContext.Current.GetOwinContext().Authentication.Challenge( new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationType); } else { var claims = HttpContext.Current.GetOwinContext().Authentication.User.Claims.Select(x => new { Name = x.Type, Value = x.Value }).ToList(); var claim = claims.FirstOrDefault(c => c.Name.Equals("email", StringComparison.CurrentCultureIgnoreCase)); if (claim != null) CMS.Membership.AuthenticationHelper.AuthenticateUser(claim.Value, true, false); } } } } using Microsoft.Owin; using Microsoft.Owin.Security; using Microsoft.Owin.Security.Cookies; using Okta.AspNet; using Owin; using System.Collections.Generic; using System.Configuration;

[assembly: OwinStartup(typeof(CMSApp.OktaStartup))]

namespace CMSApp { public class OktaStartup { public void Configuration(IAppBuilder app) { app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseOktaMvc(new OktaMvcOptions()
        {
            OktaDomain = ConfigurationManager.AppSettings["okta:OktaDomain"],
            ClientId = ConfigurationManager.AppSettings["okta:ClientId"],
            ClientSecret = ConfigurationManager.AppSettings["okta:ClientSecret"],
            AuthorizationServerId = ConfigurationManager.AppSettings["okta:AuthorizationServerId"],
            RedirectUri = ConfigurationManager.AppSettings["okta:RedirectUri"],
            PostLogoutRedirectUri = ConfigurationManager.AppSettings["okta:PostLogoutRedirectUri"],
            GetClaimsFromUserInfoEndpoint = true,
            Scope = new List<string> { "openid", "profile", "email" },
        });

    }
}

}