

def validate_token_request(self, request):
    '\n        The client makes a request to the token endpoint by adding the\n        following parameters using the "application/x-www-form-urlencoded"\n        format per Appendix B with a character encoding of UTF-8 in the HTTP\n        request entity-body:\n\n        grant_type\n                REQUIRED.  Value MUST be set to "password".\n\n        username\n                REQUIRED.  The resource owner username.\n\n        password\n                REQUIRED.  The resource owner password.\n\n        scope\n                OPTIONAL.  The scope of the access request as described by\n                `Section 3.3`_.\n\n        If the client type is confidential or the client was issued client\n        credentials (or assigned other authentication requirements), the\n        client MUST authenticate with the authorization server as described\n        in `Section 3.2.1`_.\n\n        The authorization server MUST:\n\n        o  require client authentication for confidential clients or for any\n            client that was issued client credentials (or with other\n            authentication requirements),\n\n        o  authenticate the client if client authentication is included, and\n\n        o  validate the resource owner password credentials using its\n            existing password validation algorithm.\n\n        Since this access token request utilizes the resource owner\'s\n        password, the authorization server MUST protect the endpoint against\n        brute force attacks (e.g., using rate-limitation or generating\n        alerts).\n\n        .. _`Section 3.3`: http://tools.ietf.org/html/rfc6749#section-3.3\n        .. _`Section 3.2.1`: http://tools.ietf.org/html/rfc6749#section-3.2.1\n        '
    for param in ('grant_type', 'username', 'password'):
        if (not getattr(request, param, None)):
            raise errors.InvalidRequestError(('Request is missing %s parameter.' % param), request=request)
    for param in ('grant_type', 'username', 'password', 'scope'):
        if (param in request.duplicate_params):
            raise errors.InvalidRequestError(description=('Duplicate %s parameter.' % param), request=request)
    if (not (request.grant_type == 'password')):
        raise errors.UnsupportedGrantTypeError(request=request)
    log.debug('Validating username %s.', request.username)
    if (not self.request_validator.validate_user(request.username, request.password, request.client, request)):
        raise errors.InvalidGrantError('Invalid credentials given.', request=request)
    elif (not hasattr(request.client, 'client_id')):
        raise NotImplementedError('Validate user must set the request.client.client_id attribute in authenticate_client.')
    log.debug('Authorizing access to user %r.', request.user)
    self.validate_grant_type(request)
    if request.client:
        request.client_id = (request.client_id or request.client.client_id)
    self.validate_scopes(request)

dataset/ETHPy150Open idan/oauthlib/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py ResourceOwnerPasswordCredentialsGrant.validate_token_request/original