Skip to main content

Utilities for RBAC system

Project description

SETUP

INSTALLATION

Run this command to install the package pip install rbac-utils==1.0.0 -i http://3.110.83.156:3141/dev/ldc_packages --trusted-host 3.110.83.156

USAGE

  1. Install the library in your project using the above command.
  2. Create the rbac_utils.env file in your project root (keys below).
  3. import the main Utils class from lib to your code from rbac_utils.utils import Utils (I recommend renaming the import to RbacUtils this way from rbac_utils.utils import Utils as RbacUtils)
  4. Start using the utils functions on the class

    RbacUtils.generate_user_tokens('usr_id', {'key': 'value'})

rbac_utils.env keys

  1. RBAC_API_KEY='SECRET_KEY_OBTAINED_FROM_PERIPHERALS_TEAM'
  2. RBAC_BASE_URL='https://qa-rbac.lendenclub.com'

Docs

RbacUtils.generate_user_tokens(user_id, data)

Generate user tokens (access token and refresh token) for the given user_id.

Args: user_id (str): The identifier of the user for whom tokens are generated. data (dict): A dictionary containing custom key-value pairs. This dictionary is added as a value to the data key of the token.

Returns: dict: A dictionary containing the generated access token and refresh token. An empty dictionary is returned if the generation process fails.

RbacUtils.validate_access_token(access_token)

Validate an access token and retrieve user details.

Args: access_token (str): The access token to be validated.

Returns: dict: A dictionary containing user details if the token is valid. An empty dictionary is returned if validation fails.

RbacUtils.refresh_user_tokens(refresh_token)

Refresh user tokens using a refresh token.

Args: refresh_token (str): The refresh token used to obtain new tokens.

Returns: dict: A dictionary containing the new access token and refresh token. An empty dictionary is returned if token refresh fails.

RbacUtils.revoke_user_tokens(access_token, refresh_token)

Revoke user tokens.

Args: access_token (str): The access token to be revoked. refresh_token (str): The refresh token to be revoked.

Returns: bool: True if the tokens were successfully revoked, False otherwise.

RbacUtils.update_token_data(access_token, data)

Update a user's access token with new data. NOTE: The existing access token will be invalidated after the update and the newly returned one takes its place.

Args: access_token (str): The access token to be updated. data (dict): New data to be added to the access token.

Returns: str: The updated access token with the new data. None is returned if the update fails.

RbacUtils.extract_token_claims(token)

Extract token claims.

Args: token (str): The JWT from which claims will be extracted.

Returns: dict: A dictionary containing the claims from the JWT. An empty dictionary is returned if decoding fails.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rbac-utils-1.0.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

rbac_utils-1.0.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file rbac-utils-1.0.0.tar.gz.

File metadata

  • Download URL: rbac-utils-1.0.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.18

File hashes

Hashes for rbac-utils-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7ac72edd248b113f104b85f277255f308744aeae666923e43b24182fa7a238c9
MD5 ae8d3f5fcda615cfcd32ece0e7c490b3
BLAKE2b-256 16974e7cbc17132c1498205f426d3922c062c246801cfebbec7f0864cb3cd3ee

See more details on using hashes here.

File details

Details for the file rbac_utils-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: rbac_utils-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.18

File hashes

Hashes for rbac_utils-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfd37dad3a010b29bf827192f39e753da79251926a1c90b5685d78d4c78f6d09
MD5 047ed8d36a9313751df9da600c09a7c8
BLAKE2b-256 678ff8a405519f3d78b34977fee3ffd8cba67e01eb539f4f7b6b933168e1f7cb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page