Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- context.SetError("invalid_credentials", Newtonsoft.Json.JsonConvert.SerializeObject(new { result = false, message = "Please enter password !!!" }));
- }
- });
- }
- else
- {
- return Task.Factory.StartNew(() =>
- {
- var username = _userName;
- var password = _passWord;
- var userService = new UserServices();
- User user = userService.GetUserByCredentials(username, password);
- if (user != null && user.IsValid)
- {
- var claims = new List<Claim>()
- {
- new Claim(ClaimTypes.Name, user.Name),
- new Claim("UserID", user.Id)
- };
- ClaimsIdentity oAutIdentity = new ClaimsIdentity(claims,
- Axmix.App_Start.Startup.OAuthOptions.AuthenticationType);
- context.Validated(new AuthenticationTicket(oAutIdentity, new AuthenticationProperties() { }));
- }
- else
- {
- context.SetError("invalid_grant", Newtonsoft.Json.JsonConvert.SerializeObject(new { result = false, message = "Invalid User Credentials !!!" }));
- }
- });
- }
- }
- public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
- {
- string clientId = string.Empty;
- string clientSecret = string.Empty;
- if (!context.TryGetFormCredentials(out clientId, out clientSecret))
- {
- context.SetError("invalid_client", "Client credentials could not be retrieved through the Authorization header.");
- context.Rejected();
- }
- if (!string.IsNullOrEmpty(clientId) && !string.IsNullOrEmpty(clientSecret))
- {
- context.Validated();
- _userName = clientId;
- _passWord = clientSecret;
- }
- else
- {
- context.Rejected();
- }
- //return Task.FromResult<object>(null);
- return base.ValidateClientAuthentication(context);
- }
Add Comment
Please, Sign In to add comment