I'm using token authentication in my api, but when i test it in postman, it gives me an error 404 not found
(STARTUP.AUTH)
- public partial class Startup
- {
- public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; }
- public void Configuration(IAppBuilder app)
- {
- app.UseOAuthBearerTokens(OAuthOptions);
- }
- static Startup()
- {
- OAuthOptions = new OAuthAuthorizationServerOptions
- {
- AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
- AllowInsecureHttp = true,
- TokenEndpointPath = new PathString("/token"),
- Provider = new OAuthProvider()
- };
- }
- }
(OAUTH PROVIDER)
- public class OAuthProvider : OAuthAuthorizationServerProvider
- {
- public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
- {
- return Task.Factory.StartNew(() =>
- {
- string username = context.UserName;
- string password = context.Password;
- Usuarios user = new Usuarios().Get(username, password);
- if(user != null)
- {
- List<Claim> claims = new List<Claim>
- {
- new Claim(ClaimTypes.Name , user.EmailUsuario),
- new Claim("UserId", user.IdUsuario.ToString())
- };
- ClaimsIdentity OAuthIdentity = new ClaimsIdentity(claims, Startup.OAuthOptions.AuthenticationType);
- context.Validated(new Microsoft.Owin.Security.AuthenticationTicket(OAuthIdentity, new Microsoft.Owin.Security.AuthenticationProperties() { }));
- }
- else
- {
- context.SetError("erro", "erro");
- }
- });
- }
- public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
- {
- if(context.ClientId == null)
- {
- context.Validated();
- }
- return Task.FromResult<object>(null);
- }
- }
I have a user class with a list, but i guess that the problem isn't there.