def authenticate_credentials(self, payload):
        """Get or create an active user with the username contained in the payload."""
        username = payload.get('preferred_username') or payload.get('username')

        if username is None:
            raise exceptions.AuthenticationFailed('JWT must include a preferred_username or username claim!')
        else:
            try:
                user, __ = get_user_model().objects.get_or_create(username=username)
                attributes_updated = False
                for claim, attr in self.get_jwt_claim_attribute_map().items():
                    payload_value = payload.get(claim)

                    if getattr(user, attr) != payload_value and payload_value is not None:
                        setattr(user, attr, payload_value)
                        attributes_updated = True

                if attributes_updated:
                    user.save()
            except:
                msg = 'User retrieval failed.'
                logger.exception(msg)
                raise exceptions.AuthenticationFailed(msg)

        return user
def authenticate_credentials ( self , payload ) : username = payload . get ( 'preferred_username' ) or payload . get ( 'username' ) if username is None : raise exceptions . AuthenticationFailed ( 'JWT must include a preferred_username or username claim!' ) else : try : user , __ = get_user_model ( ) . objects . get_or_create ( username = username ) attributes_updated = False for claim , attr in self . get_jwt_claim_attribute_map ( ) . items ( ) : payload_value = payload . get ( claim ) if getattr ( user , attr ) != payload_value and payload_value is not None : setattr ( user , attr , payload_value ) attributes_updated = True if attributes_updated : user . save ( ) except : msg = 'User retrieval failed.' logger . exception ( msg ) raise exceptions . AuthenticationFailed ( msg ) return user
Get or create an active user with the username contained in the payload.