Authentication#

An authentication is a callable of the type AuthCallable that receive a request, perform an action to authenticate that request and return the authenticated request.

An authenticated request must have a valid token in an HTML header with one of the supported authentication methods; StandAloneToken scheme or Bearer scheme. The library provides implementations for both authentication methods.

Note

To learn more about tokens and how to get one visit the DEVO [.docs]

StandAloneToken scheme#

StandAloneToken scheme is implemented in HttpDevoStandAloneTokenAuth.

It adds an HTML header with this template:

standAloneToken: <token>

This is how you can use this authentication:

>>> from devo_ml.modelmanager import Client
>>> from devo_ml.modelmanager.auth import HttpDevoStandAloneTokenAuth

>>> auth = HttpDevoStandAloneTokenAuth("8a3vf98ai28sar1234lkj2l43td6f89a")
>>> client = Client("http://localhost", auth)

Bearer scheme#

Bearer scheme is implemented in HttpDevoBearerTokenAuth.

It adds an HTML header with this template:

Authorization: Bearer <token>

This is how you can use this authentication:

>>> from devo_ml.modelmanager import Client
>>> from devo_ml.modelmanager.auth import HttpDevoBearerTokenAuth

>>> auth = HttpDevoBearerTokenAuth("8a3vf98ai28sar1234lkj2l43td6f89a")
>>> client = Client("http://localhost", auth)

Authentication Factory#

With the authentication factory create_auth_from_token you can create the appropriate authentication.

>>> from devo_ml.modelmanager.auth import create_auth_from_token

>>> auth = create_auth_from_token("8a3vf98ai28sar1234lkj2l43td6f89a", auth_type="bearer")
>>> type(auth)
<class 'devo_ml.modelmanager.auth.HttpDevoBearerTokenAuth'>

you can use constants instead of literal for the auth_type; STANDALONE or BEARER