What is the difference between the ValidateClientAuthentication method and the GrantResourceOwnerCredentials method in OAuth OWIN?

I am starting to use oauth and owin in .NET. I tried to understand these ValidateClientAuthentication methods and the GrantResourceOwnerCredentials method. I realized that the GrantResourceOwnerCredentials method can be used to verify credentials and generate a token. Then what is the purpose of the ValidateClientAuthentication () method. kindly advise me about this. Many thanks.

 public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            return Task.Factory.StartNew(() =>
            {
                var userName = context.UserName;
                var password = context.Password;
                var userService = new UserService(); // our created one
                var user = userService.ValidateUser(userName, password);
                if (user != null)
                {
                    var claims = new List<Claim>()
                    {
                        new Claim(ClaimTypes.Sid, Convert.ToString(user.Id)),
                        new Claim(ClaimTypes.Name, user.Name),
                        new Claim(ClaimTypes.Email, user.Email)
                    };
                    ClaimsIdentity oAuthIdentity = new ClaimsIdentity(claims,Startup.OAuthOptions.AuthenticationType);


                    var properties = CreateProperties(user.Name);
                    var ticket = new AuthenticationTicket(oAuthIdentity, properties);
                    context.Validated(ticket);
                }
                else
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect");
                }
            });
        }
        #endregion

        #region[ValidateClientAuthentication]
        public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            if (context.ClientId == null)
                context.Validated();

            return Task.FromResult<object>(null);
        }
        #endregion
+4
source share
1 answer

This is due to Client Credentials Flow vs Resource Owner Credentials Password Credentials in OAuth 2.0 Specification

, OAuth. .

GrantResourceOwnerCredentials, .

ValidateClientAuthentication , , - , . , , , .

, , . Validated(), . , . : http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-jwt-owin-authorization-server/

+1

Source: https://habr.com/ru/post/1691339/


All Articles