gcb_web_auth/backends/dukeds.py
def authenticate(self, token):
        """
        Authenticate a user with a DukeDS API token. Returns None if no user could be authenticated,
        and sets the errors list with the reasons
        :param token: A JWT token
        :return: an authenticated, populated user if found, or None if not.
        """
        self.failure_reason = None
        # 1. check if token is valid for this purpose
        try:
            check_jwt_token(token)
        except InvalidTokenError as e:
            self.failure_reason = e
            # Token may be expired or may not be valid for this service, so return None
            return None

        # Token is a JWT and not expired
        # 2. Check if token exists in database
        user = get_local_user(token)
        if user:
            # token matched a user, return it
            return user

        # 3. Token appears valid but we have not seen it before.
        # Fetch user details from DukeDS

        config = make_auth_config(token)
        auth = DataServiceAuth(config)
        api = DataServiceApi(auth, config.url)
        try:
            response = api.get_current_user()
            response.raise_for_status()
            user_dict = response.json()
        except HTTPError as e:
            self.failure_reason = e
            return None
        # DukeDS shouldn't stomp over existing user details
        user = self.save_user(user_dict, False)

        # 4. Have a user, save their token
        save_dukeds_token(user, token)
        self.handle_new_user(user, user_dict)
        return user

        Authenticate a user with a DukeDS API token. Returns None if no user could be authenticated,
        and sets the errors list with the reasons
        :param token: A JWT token
        :return: an authenticated, populated user if found, or None if not.
        
Authenticate a user with a DukeDS API token. Returns None if no user could be authenticated,
and sets the errors list with the reasons
Authenticate a user with a DukeDS API token . Returns None if no user could be authenticated and sets the errors list with the reasons
def authenticate(self, token):
        self.failure_reason = None
        try:
            check_jwt_token(token)
        except InvalidTokenError as e:
            self.failure_reason = e
            return None
        user = get_local_user(token)
        if user:
            return user
        config = make_auth_config(token)
        auth = DataServiceAuth(config)
        api = DataServiceApi(auth, config.url)
        try:
            response = api.get_current_user()
            response.raise_for_status()
            user_dict = response.json()
        except HTTPError as e:
            self.failure_reason = e
            return None
        user = self.save_user(user_dict, False)
        save_dukeds_token(user, token)
        self.handle_new_user(user, user_dict)
        return user
def authenticate ( self , token ) : self . failure_reason = None try : check_jwt_token ( token ) except InvalidTokenError as e : self . failure_reason = e return None user = get_local_user ( token ) if user : return user config = make_auth_config ( token ) auth = DataServiceAuth ( config ) api = DataServiceApi ( auth , config . url ) try : response = api . get_current_user ( ) response . raise_for_status ( ) user_dict = response . json ( ) except HTTPError as e : self . failure_reason = e return None user = self . save_user ( user_dict , False ) save_dukeds_token ( user , token ) self . handle_new_user ( user , user_dict ) return user
Authenticate a user with a DukeDS API token.
Authenticate a user with a DukeDS API token .
"""
        Authenticate a user with a DukeDS API token. Returns None if no user could be authenticated,
        and sets the errors list with the reasons
        :param token: A JWT token
        :return: an authenticated, populated user if found, or None if not.
        """ # 1. check if token is valid for this purpose # Token may be expired or may not be valid for this service, so return None # Token is a JWT and not expired # 2. Check if token exists in database # token matched a user, return it # 3. Token appears valid but we have not seen it before. # Fetch user details from DukeDS # DukeDS shouldn't stomp over existing user details # 4. Have a user, save their token
an authenticated, populated user if found, or None if not.
an authenticated populated user if found or None if not .
self
token
A JWT token
A JWT token