Add your description here
Project description
Pulse MSAL
Microsoft Entra ID (Azure AD) authentication plugin for Pulse applications using MSAL.
Architecture
Server-side OAuth2 authentication using Microsoft Authentication Library (MSAL). Handles token acquisition, caching, and session management.
┌──────────────────────────────────────────────────────────────────┐
│ Pulse App │
│ ┌────────────────┐ ┌─────────────────┐ ┌──────────────────┐ │
│ │ MSALPlugin │──│ TokenCacheStore │──│ UserSession │ │
│ └────────────────┘ └─────────────────┘ └──────────────────┘ │
│ │ │
│ │ OAuth2 Auth Code Flow │
│ ▼ │
│ ┌────────────────────────────────────────────────────────────┐ │
│ │ Microsoft Entra ID │ │
│ └────────────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────┘
Folder Structure
src/pulse_msal/
├── __init__.py # Public exports
└── plugin.py # MSALPlugin, TokenCacheStore, auth helpers
Usage
Setup
import pulse as ps
from pulse_msal import MSALPlugin, FileTokenCacheStore
app = ps.App(
plugins=[
MSALPlugin(
client_id="your-client-id",
client_secret="your-client-secret",
tenant_id="your-tenant-id",
redirect_uri="http://localhost:8000/auth/callback",
scopes=["User.Read"],
token_cache_store=FileTokenCacheStore(".token_cache"),
),
],
routes=[...],
)
Authentication Functions
from pulse_msal import auth, login, logout
@ps.component
def protected_page():
user = auth()
if not user:
return ps.button("Login", onClick=lambda _: login())
return ps.div([
ps.p(f"Hello, {user['name']}"),
ps.button("Logout", onClick=lambda _: logout()),
])
Claims Mapping
Custom claims extraction:
from pulse_msal import MSALPlugin, ClaimsMapper
def custom_mapper(claims: dict) -> dict:
return {
"id": claims.get("oid"),
"email": claims.get("preferred_username"),
"name": claims.get("name"),
"roles": claims.get("roles", []),
}
MSALPlugin(
...,
claims_mapper=custom_mapper,
)
Token Cache Stores
FileTokenCacheStore
File-based token caching for development:
from pulse_msal import FileTokenCacheStore
FileTokenCacheStore(cache_dir=".token_cache")
RedisTokenCacheStore
Redis-backed caching for production:
from pulse_msal import RedisTokenCacheStore
RedisTokenCacheStore(
redis_url="redis://localhost:6379",
prefix="msal:",
)
Custom Store
Implement the TokenCacheStore protocol:
from pulse_msal import TokenCacheStore
class CustomStore(TokenCacheStore):
async def get(self, key: str) -> bytes | None: ...
async def set(self, key: str, value: bytes) -> None: ...
async def delete(self, key: str) -> None: ...
Main Exports
MSALPlugin- authentication pluginTokenCacheStore- cache protocolFileTokenCacheStore- file-based cacheRedisTokenCacheStore- Redis cacheClaimsMapper- claims transformation typeauth()- get current userlogin()- initiate login flowlogout()- clear session
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
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 pulse_msal-0.1.5.tar.gz.
File metadata
- Download URL: pulse_msal-0.1.5.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
863374f65bdab7ff5220818556a4c961e52fc771d113eaf27dfc4e197264075c
|
|
| MD5 |
5e64ca8a85302e23b2cd6a18bc9aed62
|
|
| BLAKE2b-256 |
bef2ff58489edf0d484ec03d8adcb9bf111d3eb204e590ee4ba422d6577cb81b
|
File details
Details for the file pulse_msal-0.1.5-py3-none-any.whl.
File metadata
- Download URL: pulse_msal-0.1.5-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67a3f63dba24ad33962a9b7de917a2a42bb39fac06c0e4337235860aa9b3a66f
|
|
| MD5 |
dc22cd31d2a7f20c1b469a44c87aa6ae
|
|
| BLAKE2b-256 |
5052068ab694c1d7d2a1ea4bd8575c9860cc5424c06298c4440e37cc21e077c9
|