TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Brunno Obristo
NA
29
3.8k
Asp net web api token authentication
Jul 24 2019 1:48 PM
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.
Reply
Answers (
1
)
C# MVC Printing a SSRS report from web page
how can i change console code to win Forms