Ejemplo n.º 1
0
def login():
    """Login a client to the Lowball application.

        The POST body of this request is going to be whatever is necessary to create
        the type of auth package that is configured to be used by the auth provider of
        this application. That data will be mapped into the __init__ of the auth provider
        package class. That auth package will be used to authenticate against the
        configured auth provider. The return data from that operation will be passed
        into the authenticator, which will create a token that is returned to the client.

        :rtype: tuple
        :return: token and token data, status code
        """
    if current_app.auth_provider is None:
        raise AuthenticationNotInitializedException

    if current_app.auth_db is None:
        raise NoAuthenticationDatabaseException

    post_data = request.get_json()

    auth_package_class = current_app.auth_provider.auth_package_class
    if not auth_package_class:
        raise NotImplementedException(
            "auth_package_class",
            "The auth provider has not defined an authentication package")
    try:
        auth_package = auth_package_class(**post_data)
    except Exception as err:
        raise MalformedAuthPackageException(str(err))

    client_data = current_app.auth_provider.authenticate(auth_package)
    if not isinstance(client_data, ClientData):
        raise NotImplementedException(
            "authenticate",
            "the auth provider is not returning a ClientData object")
    token, token_data = current_app.authenticator.create_token(
        client_id=client_data.client_id, roles=client_data.roles)
    current_app.logger.info(f"Successful login for {token_data.client_id}",
                            extra={
                                "client_id": token_data.client_id,
                                "token_id": token_data.token_id
                            })

    current_app.auth_db.add_token(token_data)

    return json.dumps({
        "token": token,
        "token_data": token_data.to_dict()
    }), 200, _JSON_HEADER
Ejemplo n.º 2
0
    def create_client(self, client_registration_package):
        """Create a client.

        :type client_registration_package: ClientRegistrationPackage
        :param client_registration_package: user to create
        :return: dict or ClientData Object
        """
        raise NotImplementedException("create_client")
Ejemplo n.º 3
0
    def client_registration_package_class(self):
        """property used to return the ClientRegistrationPackage class for this auth provider

        :return: ClientRegistrationPackage class accepted for this auth provider

        """

        raise NotImplementedException("client_registration_package_class")
Ejemplo n.º 4
0
    def update_client(self, update_client_package, client_id):
        """Update data for a client.

        :param update_client_package: client to update
        :type update_client_package: UpdateClientPackage
        :return: dict/ClientData
        """
        raise NotImplementedException("update_client")
Ejemplo n.º 5
0
    def delete_client(self, client_id):
        """Delete a user.

        :param client_id: user to delete
        :type client_id: str
        :return: dict
        """
        raise NotImplementedException("delete_client")
Ejemplo n.º 6
0
    def disable_client(self, client_id):
        """Disable a user.

        :param client_id: user to disable
        :type client_id: str
        :return: dict
        """
        raise NotImplementedException("disable_client")
Ejemplo n.º 7
0
    def enable_client(self, client_id):
        """Enable a client.

        :param client_id: client to enable
        :type client_id: str
        :return: dict/ClientData
        """
        raise NotImplementedException("enable_client")
Ejemplo n.º 8
0
    def get_client(self, client_id):
        """Get data for a user.



        :param client_id: user to get data for
        :type client_id: str
        :return: ClientData  or subclass
        """
        raise NotImplementedException("get_client")
Ejemplo n.º 9
0
    def delete_roles(self, client_id, roles):
        """Delete roles from a client.

        :param client_id: client to remove roles from
        :type client_id: str
        :param roles: list of roles to remove from the client
        :type roles: list
        :return: dict
        """
        raise NotImplementedException("delete_roles")
Ejemplo n.º 10
0
    def add_roles(self, client_id, roles):
        """Add roles to a client_id

        :param client_id: user to add roles to
        :type client_id: str
        :param roles: list of roles to add to the user
        :type roles: list
        :return: dict/ClientData
        """
        raise NotImplementedException("add_roles")
Ejemplo n.º 11
0
    def client_self_register(self, client_registration_package):
        """Allow a user to register themselves.

        This is intended to work the same as :meth:`create_user`, but to
        allow a user to perform the action on themself.

        :type client_registration_package: ClientRegistrationPackage
        :param client_registration_package: user to create
        :return: dict or ClientData Object
        """
        raise NotImplementedException("client_self_register")
Ejemplo n.º 12
0
    def client_self_update(self, self_update_client_package, client_id):
        """Allow a client to update data for their user.

        This is intended to work the same as :meth:`update_client`, but
        to allow a client to perform the action on himself.

        :type self_update_client_package: SelfUpdateClientPackage
        :param self_update_client_package: client info to update
        :type client_id: str
        :param client_id: client_id from token of authenticated client
        :return: dict
        """
        raise NotImplementedException("client_self_update")
Ejemplo n.º 13
0
def mock_get_client_not_implemented(monkeypatch):

    monkeypatch.setattr(
        TestAuthProvider, "get_client",
        Mock(side_effect=NotImplementedException("get_client")))
Ejemplo n.º 14
0
    def self_update_client_package_class(self):
        """Property used to return the SelfUpdateClientPackage class for this AuthProvider.

        :return: AuthPackage class accepted for this auth provider
        """
        raise NotImplementedException("self_update_client_package_class")
Ejemplo n.º 15
0
    def list_clients(self):
        """List clients being tracked.

        :return: list(dict/ClientData)
        """
        raise NotImplementedException("list_clients")