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
Metadata
Release files for pulse-msal 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pulse_msal-0.1.5.tar.gz | 5.3 kB | Without provenance | Details for pulse_msal-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pulse_msal-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for pulse_msal-0.1.5-py3-none-any.whl |
Total release size: 11.7 kB
Release files / pulse_msal-0.1.5.tar.gz
| Download URL | pulse_msal-0.1.5.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
863374f65bdab7ff5220818556a4c961e52fc771d113eaf27dfc4e197264075c
|
|
BLAKE2b-256 checksum How to use checksums |
bef2ff58489edf0d484ec03d8adcb9bf111d3eb204e590ee4ba422d6577cb81b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / pulse_msal-0.1.5-py3-none-any.whl
| Download URL | pulse_msal-0.1.5-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
67a3f63dba24ad33962a9b7de917a2a42bb39fac06c0e4337235860aa9b3a66f
|
|
BLAKE2b-256 checksum How to use checksums |
5052068ab694c1d7d2a1ea4bd8575c9860cc5424c06298c4440e37cc21e077c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Security for pulse-msal 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.