Skip to main content

Authorisation Service

If you need more information on this subject, see Authorisations.

List of all options:

  • Authorisations management
  • Authorisation types management
  • Authorisation sources management
  • Authorisation grant right management (OIDC only)

Authorisations management

from trivoreid.models.paycard import Authorisation
from trivoreid.utils.criteria import Filter

# Get list of all authorizations
page = api.authorization_service.get_all()

# Apply filter
filt = Filter(Filter.EQUAL, 'revoked', True)
page = api.paycard_service.get_all(filt)

# Add new Authorisation
auth = Authorisation()
auth.subject.type = 'User'
auth.object.type = 'User'

authType = api.authorization_service.get_all_types().resources[0]
auth.authType = authType.code

# This method returns authorisation object with the generated ID
auth = api.authorization_service.create(auth)
authId = auth.id

# Revoke Authorization
api.authorization_service.revoke(authId)

# Get one, Update and Delete
auth = api.authorization_service.get(authId)

auth.validTo = '2022-10-20T07:17:17.606Z'
auth = api.authorization_service.update(auth)

api.authorization_service.delete(authId)

Authorisation types management

from trivoreid.models.paycard import AuthorisationType
from trivoreid.utils.criteria import Filter

# Get list of all authorization types
page = api.authorization_service.get_all_types()

# Apply filter
filt = Filter(Filter.EQUAL, 'code', 'examplecode')
page = api.paycard_service.get_all_types(filt)

# Add new Authorisation Type
auth_type = AuthorisationType()
auth_type.nsCode = 'nsCode'
auth_type.code = 'exampleCode'

# This method returns authorisation type object with the generated ID
auth_type = api.authorization_service.create_type(auth_type)
typeId = auth_type.id

# Get one, Update and Delete
auth_type = api.authorization_service.get_type(typeId)

auth_type.description = 'Example'
auth_type = api.authorization_service.update_type(auth_type)

api.authorization_service.delete_type(typeId)

Authorisation sources management

from trivoreid.models.paycard import AuthorisationType
from trivoreid.utils.criteria import Filter

# Get list of all authorization sources
page = api.authorization_service.get_all_sources()

# Apply filter
filt = Filter(Filter.EQUAL, 'code', 'examplecode')
page = api.paycard_service.get_all_sources(filt)

# Add new Authorisation Type
auth_source = AuthorisationType()
auth_source.nsCode = 'nsCode'
auth_source.code = 'exampleCode'

# This method returns authorisation type object with the generated ID
auth_source = api.authorization_service.create_source(auth_source)
sourceId = auth_source.id

# Get one, Update and Delete
auth_source = api.authorization_service.get_source(sourceId)

auth_source.description = 'Example'
auth_source = api.authorization_service.update_source(auth_source)

api.authorization_service.delete_source(sourceId)

Authorization grant right management

from trivoreid.models.paycard import AuthorisationGrantRight
from trivoreid.utils.criteria import Filter

# Get list of all authorization grant rights
page = api.authorization_service.get_all_grant_rights()

# Apply filter
filt = Filter(Filter.EQUAL, 'code', 'examplecode')
page = api.paycard_service.get_all_sources(filt)

# Add new Authorisation Type
right = AuthorisationGrantRight()

right.principal.type = 'User'
right.principal.value = userId

# This method returns authorisation grant right object with the generated ID
right = api.authorization_service.create_grant_right(right)
rightId = right.id

# Get one and revoke
right = api.authorization_service.get_grant_right(rightId)

api.authorization_service.revoke_grant_right(rightId)