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.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

rbac_utils-1.0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rbac-utils-1.0.1.tar.gz
  • Upload date:
  • Size: 3.8 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.1.tar.gz
Algorithm Hash digest
SHA256 f3727ca9a925925d8bf102ad7bb100e5aaa7167855389e5a9f372bc1b2d49f05
MD5 da68ae7efa5808d55965eb654a6a0793
BLAKE2b-256 dc8034bd6733493e1650cae7dc0d6ea3ef5215df2db2f67195a3e0ba45ba9b56

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rbac_utils-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 466fca0e02e17b6b3c3bc526e8ee1718d85da2d73084014acbaba17e40cc42a1
MD5 eb045f31da00dc470d224f0d339377dd
BLAKE2b-256 ac05f1d1391572a1d2976bb24895e6f77b5fe85f5f699dacfed823c643bc13e0

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