CLI to manage and verify user and app permissions on the FRST platform.
Project description
frst-auth-cli
frst-auth-cli is a Command Line Interface (CLI) and Python SDK for managing and verifying user and app permissions on the FRST platform.
- Quickly check user or app permissions via CLI or SDK
- Integrate easily with your Python projects
- Configurable environments for different stages (dev/prod, AWS/GCP)
- Extensible, testable, and production-ready
๐ฆ Installation
Recommended: install from PyPI
For most users and developers, simply install from PyPI:
pip install frst-auth-cli
Note: Requires Python 3.10 or higher.
For contributors: editable mode
If you wish to contribute or develop locally, clone this repository and install in editable mode:
git clone git@github.com:FRST-Falconi/frst-auth-cli.git
cd frst-auth-cli
pip install -r requirements.txt
pip install -e python
๐ Usage
CLI Commands
Initialize or show your config:
frst-auth-cli config init
frst-auth-cli config show
Validate a backend token (user) and display profile:
frst-auth-cli verify-backend-token <env> <token>
Validate an app token and display permissions:
frst-auth-cli verify-app-token <env> <token>
Use --help to see options for any command:
frst-auth-cli --help
frst-auth-cli config --help
Python SDK Usage
โน๏ธ Best Practice: Always create a single, global instance of
FrstAuthClientin your application. To avoid overloading the FRST platform and to maximize performance, this client implements an internal cache for token validation. Reuse the same instance (singleton) across your codebase. Do not create a new client for every request.
Common Use Case: Validate backend_token, get group, and check company permission
from frst_auth_cli.core import FrstAuthClient
from frst_auth_cli.exceptions import UserNotFoundError, GroupNotFoundError
client = FrstAuthClient("aws-dev")
backend_token = "YOUR_BACKEND_TOKEN_FROM_FRONTEND"
group_uuid = "GROUP_UUID_FROM_FRONTEND"
try:
user = client.verify_backend_token(backend_token)
group = user.get_group(group_uuid)
if group.company.has_permission("frst_auth.company_manager"):
print(f"User is company manager in {group.company.name}")
else:
print("User is NOT company manager for this group")
except UserNotFoundError:
print("User not found or invalid token.")
except GroupNotFoundError:
print("Group not found for this user.")
Check group permissions for a light admin (company_manager_custom)
from frst_auth_cli.core import FrstAuthClient
from frst_auth_cli.exceptions import UserNotFoundError, GroupNotFoundError
client = FrstAuthClient("aws-dev")
backend_token = "YOUR_BACKEND_TOKEN_FROM_FRONTEND"
group_uuid = "GROUP_UUID_FROM_FRONTEND"
try:
user = client.verify_backend_token(backend_token)
group = user.get_group(group_uuid)
if group.company.has_permission("frst_auth.company_manager"):
print(f"User is company manager in {group.company.name}")
print("Full access. No further group permission checks needed.")
elif group.company.has_permission("frst_auth.company_manager_custom"):
print(f"User is light admin in {group.company.name}")
# Now check specific group permissions
if group.has_permission("admin_report.can_view_overview_report"):
print(f"User can view the overview report in group {group.name}")
else:
print("User does NOT have permission to view the overview report in this group")
else:
print("User is NOT a company manager or light admin for this group/company")
except UserNotFoundError:
print("User not found or invalid token.")
except GroupNotFoundError:
print("Group not found for this user.")
Common Use Case: Validate an app token for backend-to-backend communication
When integrating two backend microservices, you should use an app token (a fixed token generated for your app in the FRST platform). You can validate this token and check the app's permissions using the code below:
from frst_auth_cli.core import FrstAuthClient
from frst_auth_cli.exceptions import AppNotFoundError
client = FrstAuthClient("aws-dev") # Environment name
app_token = "YOUR_APP_TOKEN"
try:
app = client.verify_app_token(app_token)
if app.has_permission("frst_auth.can_user_inactivation_sync"):
print("App can inactivate users")
else:
print("App does NOT have permission to inactivate users")
except AppNotFoundError:
print("App not found or invalid app token.")
Exploring User and Group objects
from frst_auth_cli.core import FrstAuthClient
from frst_auth_cli.exceptions import UserNotFoundError, GroupNotFoundError
client = FrstAuthClient("aws-dev")
backend_token = "YOUR_BACKEND_TOKEN"
try:
user = client.verify_backend_token(backend_token)
# 1. List all groups the user belongs to
print("User groups:")
for group in user.groups:
print(f"- {group.name} (uuid: {group.uuid})")
# 2. Get the default group
default_group = user.get_group_default()
print(f"Default group: {default_group.name}")
# 3. List modules of the default group
print("Modules in default group:")
for module in default_group.modules:
print(f"- {module.get('code')}")
# 4. Check the default module of the group
default_module_code = default_group.module_default
print(f"Default module: {default_module_code}")
# 5. Check if a specific module exists in the group
module_code = "content"
if default_group.has_module(module_code):
print(f"Module '{module_code}' exists in the default group")
else:
print(f"Module '{module_code}' does NOT exist in the default group")
except UserNotFoundError:
print("User not found or invalid token.")
except GroupNotFoundError:
print("Group not found for this user.")
โ๏ธ Configuration
The CLI stores environments and endpoint paths in a user config file (default: ~/.frst_auth_cli/config.json).
You can initialize or edit this config with:
frst-auth-cli config init # creates with default values
frst-auth-cli config show # prints current config
You can customize the environments and paths as needed.
๐๏ธ Project Structure
frst-auth-cli/
โโโ python/
โ โโโ frst_auth_cli/
โ โ โโโ __init__.py
โ โ โโโ app.py
โ โ โโโ caching.py
โ โ โโโ cli.py
โ โ โโโ company.py
โ โ โโโ config.py
โ โ โโโ core.py
โ โ โโโ group.py
โ โ โโโ user.py
โ โโโ tests/
โ โโโ README.md
โ โโโ requirements.txt
โ โโโ setup.py
โโโ LICENSE
โโโ README.md
โโโ .gitignore
๐ฉโ๐ป Contributing
Contributions, issues, and feature requests are welcome! Feel free to open an issue or submit a pull request.
- Fork this repo
- Clone to your machine
- Create your feature branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin feature/my-feature) - Open a pull request
Before submitting, please run tests with:
pytest python/tests
๐ก๏ธ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ซ Contact
For questions, support, or partnership inquiries, contact:
Happy coding with FRST! ๐
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file frst_auth_cli-1.0.1.tar.gz.
File metadata
- Download URL: frst_auth_cli-1.0.1.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87f6ac030257482e9da64500ddca06a652b522a22dbb05726941acc72810ed82
|
|
| MD5 |
8465d4c65142df63f8efce7e37cd445f
|
|
| BLAKE2b-256 |
8b134497f903deb52dba374095f01c76d111187e3deb6cffcf32ef44a17fb9db
|
File details
Details for the file frst_auth_cli-1.0.1-py3-none-any.whl.
File metadata
- Download URL: frst_auth_cli-1.0.1-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73b9573a4e039b9f19a4a8a9049d8a842aa7205d0388d72a81bea443cf72d8f0
|
|
| MD5 |
0ca33fd928a5ae4bdd2f7144a6cf39f7
|
|
| BLAKE2b-256 |
6c2ef6be8cb1efce43bbf09f30715cb8d02dbd9d224e84fdd9489079f665a005
|