1 Replies - 1624 Views - Last Post: 04 December 2016 - 09:54 AM

#1 fearfulsc2  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 169
  • Joined: 25-May 16

Startup.cs path not being found?

Posted 16 November 2016 - 10:31 AM

Hey everyone, I am trying to figure out why I can't issue out a token when I do a POST request with the user's credentials. I keep getting a 404 error even though the code compiles and runs without any problems until I try to do this one POST request.

My code is
 public class Startup
  {
    public void Configuration(IAppBuilder app)
    {
      HttpConfiguration httpConfig = new HttpConfiguration();

      ConfigureOAuthTokenGeneration(app);

      ConfigureOAuthTokenConsumption(app);

      ConfigureWebApi(httpConfig);

      app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

      app.UseWebApi(httpConfig);
    }

    /// <summary>
    /// //Configure the db context and user manager to use a single instance per request
    /// </summary>
    /// <param name="app"></param>
    private void ConfigureOAuthTokenGeneration(IAppBuilder app)
    {
      
      app.CreatePerOwinContext(ApplicationDbContext.Create);
      app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
      app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);

      //Plug in the OAuth bearer JSON web token
      OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
      {
        //development purposes only. Set to false for production
        AllowInsecureHttp = true,
        TokenEndpointPath = new PathString("/oauth/token"),
        AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
        Provider = new CustomOAuthProvider(),
        AccessTokenFormat = new CustomJwtFormat(ConfigurationManager.AppSettings["Issuer"])
      };

      app.UseOAuthAuthorizationServer(OAuthServerOptions);
    }

    private void ConfigureWebApi(HttpConfiguration config)
    {
      config.MapHttpAttributeRoutes();

      var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First();
      jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
    }

    private void ConfigureOAuthTokenConsumption(IAppBuilder app)
    {
      var issuer = ConfigurationManager.AppSettings["Issuer"];
      string audienceId = ConfigurationManager.AppSettings["AudienceID"];
      byte[] audienceSecret = TextEncodings.Base64Url.Decode(ConfigurationManager.AppSettings["AudienceSecret"]);

      //Api controllers with an [Authorize] attribute will be validated with JWT
      app.UseJwtBearerAuthentication(
        new JwtBearerAuthenticationOptions
        {
          AuthenticationMode = AuthenticationMode.Active,
          AllowedAudiences = new[] { audienceId },
          IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
          {
            new SymmetricKeyIssuerSecurityTokenProvider(issuer, audienceSecret)
          }
        });
    }
  }



so when I do the localhost/PATH/oauth/token

I keep getting a 404 error. Am I missing something in the code that is not recognizing the Startup.cs file?

Is This A Good Question/Topic? 0
  • +

Replies To: Startup.cs path not being found?

#2 wtp  Icon User is offline

  • D.I.C Regular

Reputation: 26
  • View blog
  • Posts: 319
  • Joined: 08-December 11

Re: Startup.cs path not being found?

Posted 04 December 2016 - 09:54 AM

If you're getting a 404 the webpage that your posting to is not there. Make sure the site is up and accepting posts. I usually like to make requests to web apis in fiddler/postman first before writing code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1