from rest_framework import authentication, exceptions
from common_middleware.nwisefinauth import NWisefinAuth
from common_middleware.request_middleware import NWisefinAuthentication

class NWisefinAuthentication(authentication.BaseAuthentication):
    def authenticate(self, request):
        auth_service = NWisefinAuthentication()
        auth_service.authenticate(request)
        if request.user is None:
            raise exceptions.AuthenticationFailed('Invalid credentials/token.')
        else:
            return request.user, None
