Logo Lanfrica

National-ID-Program-Ethiopia/fayda-auth-python

Domaine:

digital infrastructure

Type de record:

software
Créateur:
Nat
Hôte:
Proof of concept of verify fayda 2 (esignet) using python # Fayda Auth Python Library `fayda-auth` is a Python library for integrating with Fayda Esignet OAuth authentication. It simplifies the process of generating authorization URLs, managing sessions with Redis, and authenticating users via token exchange, supporting modern JWK-based client assertions. --- ## Features - Generate OAuth authorization URLs for Fayda Esignet. - Secure session management using Redis. - Client assertion generation with JWK private keys. - Easy integration with Python applications (e.g., Flask, django, etc..). --- ## Installation Install `fayda-auth` from PyPI: ```bash pip install fayda-auth ``` ### Requirements - Python 3.8 or higher - A running Redis server --- ## Quick Start Here’s a basic example to get started: ```python from fayda_auth import FaydaAuth, HostConfig import redis # Initialize Redis client redis_client = redis.Redis(host='localhost', port=6379, db=0) # Configure FaydaAuth auth = FaydaAuth( host_configs=[HostConfig(origin="localhost", redirect_uri="localhost")], redis_client=redis_client, env_file=".env" ) # Generate authorization URL result = auth.authorize("localhost") print(result) # Authenticate (example with mock data) auth_result = auth.authenticate( session_id=result["data"]["session_id"], auth_code="mock_auth_code", csrf_token=result["data"]["state"] ) print(auth_result) ``` --- ## Configuration Create a `.env` file in your project root with the following variables: ```plaintext REDIS_HOST=localhost REDIS_PORT=6379 FAYDA_OAUTH_CLIENT_ID=your_client_id FAYDA_OAUTH_CLIENT_ASSERTION_TYPE=urn:ietf:params:oauth:client-assertion-type:jwt-bearer FAYDA_OAUTH_PRIVATE_KEY= FAYDA_AUTHORIZE_URL=esignet.example.com FAYDA_TOKEN_URL=esignet.example.com FAYDA_USER_INFO_URL=esignet.example.com ``` ### Notes - `FAYDA_OAUTH_PRIVATE_KEY` must be a base64-encoded JWK (JSON Web Key) RSA p …