BadgrClient

class BadgrClient(username: str, password: str, client_id: str, scope: str = 'rw:profile rw:issuer rw:backpack', base_url: str = 'http://localhost:8000', token: str = None, refresh_token: str = None, unique_badge_names: bool = False)

Bases: object

__init__(username: str, password: str, client_id: str, scope: str = 'rw:profile rw:issuer rw:backpack', base_url: str = 'http://localhost:8000', token: str = None, refresh_token: str = None, unique_badge_names: bool = False)

Initalize a new client

Parameters:
  • username (str) – Badgr username(or email). Defaults to None.
  • password (str) – Badgr password. Defaults to None.
  • client_id (str) – client_id to use to connect to badgr. Defaults to None.
  • scope (str) – OAuth Scope. Defaults to None.
  • base_url (str) – badgr-server’s url. Defaults to ‘http://localhost:8000’.
  • token (str) – Token to use for auth. Defaults to None.
  • refresh_token (str) – Refresh token to use for auth. Defaults to None.
  • unique_badge_names (str) – Declares that badge_names per issuer are unique and can be used as a unique identifier for operations.

Note

Enabling unique_badge_names declares that badge names can be used as a unique identifier so the client can keep a track of badge names and their entity id in a dict. Use this if you would like to use badge names at certain places instead of entity id.

Note

If unique_badge_names is set to True call load_badge_names() to load badges of a particular issuer into the index or only badges you create will get registered in the client’s badge name index

static encode_image(file_path: str)

Encode file to base64 data-uri string

Parameters:file_path (str) – the path to file
Raises:BadgrClientError – Image format not supported
fetch_assertion(eid=None) → List[badgrclient.badgrmodels.Assertion]

Get Assertion of the specified entityId, if eid is not provided then get a list of Assertions in authenticated user’s backpack

Parameters:eid (string, optional) – entityId of the entity to fetch. Defaults to None.
fetch_badgeclass(eid=None) → List[badgrclient.badgrmodels.BadgeClass]

Get BadgeClass of the specified entityId, if eid is not provided then get a list of BadgeClasses for authenticated user

Parameters:eid (string, optional) – entityId of the entity to fetch. Defaults to None.
fetch_collection(eid=None)

Get Collection of the specified entityId, if eid is not provided then get a list of collections for authenticated user

Parameters:eid (string, optional) – entityId of the entity to fetch. Defaults to None.
fetch_issuer(eid=None) → List[badgrclient.badgrmodels.Issuer]

Get Issuer of the specified entityId, if eid is not provided then get a list of Issuers for authenticated user

Parameters:eid (string, optional) – entityId of the entity to fetch. Defaults to None.
fetch_tokens()

Get a list of access tokens for authenticated user

get_eid_from_badge_name(badge_name: str, issuer_eid: str)

Get eid from badge name and it’s issuer eid.

Parameters:
  • badge_name (string) – Name of badge.
  • issuer_eid (string) – entityId of the the issuer badge belongs to

Note

For this to work you need to have unique_badge_names enabled

load_badge_names(issuer_eid: str)

(Re)loads the badge name index for an issuer

Parameters:issuer_eid (str) – eid of the issuer
revoke_assertions(ids: List[str], reason='Revoked by badgerclient')

Revoke multiple assertions

Parameters:
  • ids (list) – List of entityIds of Assertionsto revoke
  • reason (string) – Revocation reason, defaults to ‘Revoked by badgerclient’
Raises:

BadgrClientError – Email/password not provided.