RealmTeam / django-rest-framework-social-oauth2

python-social-auth and oauth2 support for django-rest-framework
MIT License
1.06k stars 191 forks source link

Global authentication problem (oauth2_provider.contrib.rest_framework.OAuth2Authentication) #165

Closed whuizhe closed 6 years ago

whuizhe commented 6 years ago

Django 2.1 djangorestframework 3.8.2 django-rest-framework-social-oauth2 1.1.0

Added in the global configuration "oauth2_provider. Contrib. Rest_framework. OAuth2Authentication", This authentication is skipped when API requests such as headers do not transmit token

def authenticate(self, request):
    """
    Returns two-tuple of (user, token) if authentication succeeds,
    or None otherwise.
    """
    oauthlib_core = get_oauthlib_core()
    valid, r = oauthlib_core.verify_request(request, scopes=[])
    if valid:
        return r.user, r.access_token
    request.oauth2_error = getattr(r, "oauth2_error", {})
    return None 

Authentication is skipped when valid is false

advice raise exceptions.AuthenticationFailed