-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthorizationServerProvider.cs
More file actions
37 lines (34 loc) · 1.34 KB
/
AuthorizationServerProvider.cs
File metadata and controls
37 lines (34 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Microsoft.Owin.Security.OAuth;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web;
namespace WebApplication4
{
public class AuthorizationServerProvider : OAuthAuthorizationServerProvider
{
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
context.Validated();
}
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
using (UserAuthentication OBJ = new UserAuthentication())
{
var user = OBJ.ValidateUser(int.Parse(context.UserName), context.Password);
if (user == null)
{
context.SetError("invalid_grant", "Username or password is incorrect");
return;
}
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Role, user.type));
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.user_id.ToString()));
//identity.AddClaim(new Claim("Email", user.UserEmailID));
context.Validated(identity);
}
}
}
}