'Authenticate user and issue a token.'

def authenticate_for_token(self, request, auth=None):

    include_catalog = ('nocatalog' not in request.params)
    validate_issue_token_auth(auth)
    try:
        auth_info = core.AuthInfo.create(auth=auth)
        auth_context = core.AuthContext(extras={}, method_names=[], bind={})
        self.authenticate(request, auth_info, auth_context)
        if auth_context.get('access_token_id'):
            auth_info.set_scope(None, auth_context['project_id'], None)
        self._check_and_set_default_scoping(auth_info, auth_context)
        (domain_id, project_id, trust, unscoped) = auth_info.get_scope()
        method_names_set = set(auth_context.get('method_names', []))
        method_names = list(method_names_set)
        if (not self._mfa_rules_validator.check_auth_methods_against_rules(auth_context['user_id'], method_names_set)):
            raise exception.InsufficientAuthMethods(user_id=auth_context['user_id'], methods=('[%s]' % ','.join(auth_info.get_method_names())))
        expires_at = auth_context.get('expires_at')
        token_audit_id = auth_context.get('audit_id')
        is_domain = auth_context.get('is_domain')
        (token_id, token_data) = self.token_provider_api.issue_token(auth_context['user_id'], method_names, expires_at, project_id, is_domain, domain_id, auth_context, trust, include_catalog, parent_audit_id=token_audit_id)
        if trust:
            self.trust_api.consume_use(trust['id'])
        return render_token_data_response(token_id, token_data, created=True)
    except exception.TrustNotFound as e:
        LOG.warning(six.text_type(e))
        raise exception.Unauthorized(e)
