from nuxeo.client import Nuxeo
host = "https://<HOST>/nuxeo/"
auth = ("alice", "password")
server = Nuxeo(host=host, auth=auth)
from nuxeo.auth import JWTAuth
from nuxeo.client import Nuxeo
host = "https://<HOST>/nuxeo/"
auth = JWTAuth("token")
server = Nuxeo(host=host, auth=auth)
OAuth2 with automatic credentials renewal is available by default.
The OAuth2
class can take several optionnal keyword arguments:
authorization_endpoint
: custom authorization endpointclient_id
: the consumer client IDclient_secret
: the consumer client secretopenid_configuration_url
: configuration URL for OpenID Connect Discoveryredirect_uri
: the redirect URI (mandatory when using ADFS ofr instance)token
: existent tokentoken_endpoint
: custom token endpoint
When openid_configuration_url
is passed, authorization_endpoint
and token_endpoint
have no effect.
from nuxeo.auth import OAuth2
from nuxeo.client import Nuxeo
host = "https://<HOST>/nuxeo/"
nuxeo = Nuxeo(host=host)
nuxeo.client.auth = OAuth2(
nuxeo.client.host, client_id="<client-id>", client_secret="<client-secret>"
)
# Step 1, generate the auth URL
# (*state* and *code_verifier* should be used by the caller to validate the request)
uri, state, code_verifier = nuxeo.client.auth.create_authorization_url()
# Step 2, ask the user to open *uri* in their browser (here we are emulating such action)
req = requests.get(uri, auth=("Administrator", "Administrator"))
authorization_response = req.url
# Step 3, get the token
token = nuxeo.client.auth.request_token(
code_verifier=code_verifier,
authorization_response=authorization_response,
)
# Step 3, another possibility when you already parsed *authorization_response* and know the *code*
token = nuxeo.client.auth.request_token(
code_verifier=code_verifier,
code=code,
state=state,
)
from nuxeo.auth import OAuth2
from nuxeo.client import Nuxeo
# Token saved that we want to reuse
token = {
"access_token": "...",
"refresh_token": "...",
"token_type": "bearer",
"expires_in": 3599,
"expires_at": 1618242664,
}
host = "https://<HOST>/nuxeo/"
nuxeo = Nuxeo(host=host)
nuxeo.client.auth = OAuth2(
nuxeo.client.host, client_id="<client-id>", client_secret="<client-secret>", token=token
)
from nuxeo.auth import PortalSSOAuth
from nuxeo.client import Nuxeo
host = "https://<HOST>/nuxeo/"
auth = PortalSSOAuth("alice", "secret")
server = Nuxeo(host=host, auth=auth)
If the server is configured to use a digest algorithm different than MD5
, you can tell the client like:
# Example when the server is configured to use SHA256:
auth = PortalSSOAuth("alice", "secret", digest_algorithm="sha256")
from nuxeo.auth import TokenAuth
from nuxeo.client import Nuxeo
host = "https://<HOST>/nuxeo/"
auth = TokenAuth("token")
server = Nuxeo(host=host, auth=auth)