Пример #1
0
    def authenticate(self, request=None, authorization_code=None, **kwargs):
        # If loaded data is too old, reload it again
        provider_config.load_config()

        # If there's no token or code, we pass control to the next authentication backend
        if authorization_code is None or authorization_code == '':
            logger.debug(
                "django_auth_adfs authentication backend was called but no authorization code was received"
            )
            return

        adfs_response = self.exchange_auth_code(authorization_code, request)
        access_token = adfs_response["access_token"]
        user = self.process_access_token(access_token, adfs_response)
        return user
Пример #2
0
    def authenticate(self, request=None, access_token=None, **kwargs):
        # If loaded data is too old, reload it again
        provider_config.load_config()

        # If there's no token or code, we pass control to the next authentication backend
        if access_token is None or access_token == '':
            logger.debug(
                "django_auth_adfs authentication backend was called but no authorization code was received"
            )
            return

        access_token = access_token.decode()
        try:
            user = process_access_token(self, access_token)
        except ValueError:
            raise PermissionDenied
        return user
Пример #3
0
    def authenticate(self, request=None, authorization_code=None, **kwargs):
        # If loaded data is too old, reload it again
        provider_config.load_config()

        # If there's no token or code, we pass control to the next authentication backend
        if authorization_code is None or authorization_code == '':
            logger.debug(
                "django_auth_adfs authentication backend was called but no authorization code was received"
            )
            return
        try:
            adfs_response = exchange_auth_code(authorization_code, request)
            access_token = adfs_response["access_token"]
            user = process_access_token(self, access_token, adfs_response)
        except (requests.HTTPError, ValueError):
            raise PermissionDenied
        return user
Пример #4
0
    def get(self, request):
        """
        Handles the token refresh for ADFS.
        The passed refresh token is used to acquire a new access token.
        Args:
            request (rest_framework.request.Request): A DRF Request object
        """
        # If loaded data is too old, reload it again
        provider_config.load_config()
        refresh_token = request.GET.get('token')

        data = {
            'grant_type': 'refresh_token',
            'client_id': adfs_settings.CLIENT_ID,
            'refresh_token': refresh_token,
        }

        try:
            adfs_response = exchange_refresh_token(refresh_token, request)
        except HTTPError:
            raise exceptions.APIException(
                detail='The authentication service is not available')

        return Response(status=status.HTTP_200_OK,
                        data={
                            'token_type':
                            adfs_response['token_type'],
                            'refresh_token_expires_in':
                            adfs_response['refresh_token_expires_in'],
                            'refresh_token':
                            adfs_response['refresh_token'],
                            'expires_in':
                            adfs_response['expires_in'],
                            'access_token':
                            adfs_response['access_token'],
                        })
Пример #5
0
 def __init__(self):
     # If loaded data is too old, reload it again
     provider_config.load_config()