Add your description here
Project description
nf_ndc_connect_public
One Logic, Three Platforms. This library provides a unified, secure, and high-performance Identity Provider (IDP) Claims & Authorization helper. It is written in Rust and compiled for:
- Rust (Native Crate)
- Python (via PyO3)
- Node.js / Web (via Wasm-Pack)
It handles JWT validation, Role-Based Access Control (RBAC) checks, and parsing of complex IDP organization trees efficiently by parsing the token once into a context object.
📦 Installation
🦀 Rust
cargo add nf_ndc_connect_public
🐍 Python
pip install nf_ndc_connect_public
📦 Node.js (npm)
npm install @dhilipsiva/nf_ndc_connect_public
🔑 Organization Context & Auto-Resolution
The library uses a Context Object Pattern. You validate the JWT once to get a User object, which holds the parsed state including pre-computed group summaries.
Each summary contains:
org_short_code— The short name of the group (the part after/in a fully-qualified group name likeowner/group_name).role— The role the user holds in that group.permissions— Permissions scoped to that role.
When checking roles or permissions on this User object:
- Explicit Context: If you provide a
group_name(theorg_short_code), checks are performed strictly against that group's summary. - Auto-Resolution: If you omit
group_name(passNone/null):- If the user belongs to exactly one group, that group is used automatically.
- If the user belongs to multiple groups (or zero), the function returns an Error (Ambiguous Context).
🚀 Usage
🐍 Python Example
In Python, helper.validate(jwt) returns a CasdoorUser object. All checks are performed on this object.
from nf_ndc_connect_public import IdpAuthHelper
import json
# 1. Initialize
with open("cert.pem", "r") as f:
public_key = f.read()
helper = IdpAuthHelper(public_key)
raw_jwt = "eyJhbGciOiJ..."
# 2. Parse User Context
try:
user = helper.validate(raw_jwt)
except ValueError as e:
print(f"❌ Validation failed: {e}")
exit(1)
# 3. Check Single Role/Permission (Explicit Context)
# NOTE: Use the org_short_code, not the fully-qualified group name
group_name = "nf-apex"
if user.has_role("nf-apex-adm", group_name):
print("User is Admin!")
# 4. Check Multiple Permissions
# has_permissions = ALL must match (AND)
if user.has_permissions(["read", "write"], group_name):
print("User has full R/W access")
# has_permissions_any = AT LEAST ONE must match (OR)
if user.has_permissions_any(["edit", "admin"], group_name):
print("User has elevated privileges")
# 5. Get full authorization tree
print(json.loads(user.get_auth_summary()))
# 6. Convenience getters
print(user.username) # User's name
print(user.email) # User's email
print(user.dj_id) # User's id_card
print(user.org_short_codes) # All org short codes
📦 Node.js / Web Example
In JavaScript/TypeScript, helper.validate(jwt) returns a CasdoorUser object.
import { IdpAuthHelper } from "@dhilipsiva/nf_ndc_connect_public";
const helper = new IdpAuthHelper(publicKey);
const user = helper.validate(rawJwt);
// NOTE: Use the org_short_code, not the fully-qualified group name
const groupName = "nf-apex";
// 1. Single Check
if (user.hasPermission("write", groupName)) {
console.log("Can write!");
}
// 2. Multiple Permissions (Exhaustive - AND)
// Returns true only if user has BOTH "read" AND "write"
if (user.hasPermissions(["read", "write"], groupName)) {
console.log("Full Access");
}
// 3. Multiple Permissions (Iterative - OR)
// Returns true if user has EITHER "edit" OR "delete"
if (user.hasPermissionsAny(["edit", "delete"], groupName)) {
console.log("Can modify content");
}
// 4. Auto-Resolution (Pass null for group)
try {
user.hasPermissionsAny(["read"], null);
} catch (e) {
console.error("Ambiguous Context:", e.message);
}
// 5. Convenience getters
console.log(user.username);
console.log(user.email);
console.log(user.isAdmin);
🦀 Rust Example
In Rust, helper.parse_user(jwt) returns a CasdoorUser struct.
use nf_ndc_connect_public::AuthHelper;
fn main() {
let helper = AuthHelper::new(public_key).unwrap();
let user = helper.parse_user(jwt).unwrap();
// NOTE: Use the org_short_code, not the fully-qualified group name
let group = Some("nf-apex");
// 1. Single Check
if user.has_permission("read", group).unwrap() {
println!("Can read");
}
// 2. Multiple Checks (Vec<String>)
let required = vec!["read".to_string(), "write".to_string()];
// Check ALL
if user.has_permissions(&required, group).unwrap() {
println!("Has all permissions");
}
// Check ANY
if user.has_permissions_any(&required, group).unwrap() {
println!("Has at least one permission");
}
// 3. Convenience accessors
println!("{}", user.username());
println!("{:?}", user.email());
println!("{}", user.get_org_count());
}
🛠️ Development
This project uses Nix for a reproducible environment and Just for command automation.
Prerequisites
- Install Nix.
- Enable flakes.
Setup
nix develop
Build Commands (via just)
| Command | Description |
|---|---|
just py-dev |
Build Python wheel in debug mode & install to venv |
just py-build |
Build Python wheel for release |
just wasm |
Build the Wasm package for Node.js/Web |
just test |
Run standard Cargo tests |
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 Distributions
Built Distributions
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 nf_ndc_connect_public-0.10.0-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: nf_ndc_connect_public-0.10.0-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9772fb52e088519984c07815703491105e7199b3d82a8443d57ae5c97e1197df
|
|
| MD5 |
8d2f0e7fdda2e274d86b591299920de6
|
|
| BLAKE2b-256 |
d6032a1d5622a05b351bfbb4b33b3b1342711ca095bdf62104abe91cdd9d2cd5
|
Provenance
The following attestation bundles were made for nf_ndc_connect_public-0.10.0-cp314-cp314-macosx_11_0_arm64.whl:
Publisher:
release.yml on NuFlights/nf_ndc_connect_public
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nf_ndc_connect_public-0.10.0-cp314-cp314-macosx_11_0_arm64.whl -
Subject digest:
9772fb52e088519984c07815703491105e7199b3d82a8443d57ae5c97e1197df - Sigstore transparency entry: 1039430101
- Sigstore integration time:
-
Permalink:
NuFlights/nf_ndc_connect_public@40b1fab4d2965593bca270cef5b8160317857c2b -
Branch / Tag:
refs/tags/v0.10.0 - Owner: https://github.com/NuFlights
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@40b1fab4d2965593bca270cef5b8160317857c2b -
Trigger Event:
push
-
Statement type:
File details
Details for the file nf_ndc_connect_public-0.10.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: nf_ndc_connect_public-0.10.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 1.9 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bba682e2cd9a4b92c55d55211fb65be7234d89d92744ecb2926f905bc8863dce
|
|
| MD5 |
51edefe724dd20af786b5f652296d48e
|
|
| BLAKE2b-256 |
710d823f4541485440d1f556cc82d873a476d817fde14017de81ea8ba7f8d9f4
|
Provenance
The following attestation bundles were made for nf_ndc_connect_public-0.10.0-cp312-cp312-win_amd64.whl:
Publisher:
release.yml on NuFlights/nf_ndc_connect_public
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nf_ndc_connect_public-0.10.0-cp312-cp312-win_amd64.whl -
Subject digest:
bba682e2cd9a4b92c55d55211fb65be7234d89d92744ecb2926f905bc8863dce - Sigstore transparency entry: 1039430249
- Sigstore integration time:
-
Permalink:
NuFlights/nf_ndc_connect_public@40b1fab4d2965593bca270cef5b8160317857c2b -
Branch / Tag:
refs/tags/v0.10.0 - Owner: https://github.com/NuFlights
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@40b1fab4d2965593bca270cef5b8160317857c2b -
Trigger Event:
push
-
Statement type:
File details
Details for the file nf_ndc_connect_public-0.10.0-cp312-cp312-manylinux_2_38_x86_64.whl.
File metadata
- Download URL: nf_ndc_connect_public-0.10.0-cp312-cp312-manylinux_2_38_x86_64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.12, manylinux: glibc 2.38+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19e1e79d784ddab5ff0a826176ce719d2c124f7bbda162988f316fa32dc55037
|
|
| MD5 |
f7bcb269810c45ef9b0ab850dc9f1776
|
|
| BLAKE2b-256 |
d3cf4793dc38b7cbd4cc98f5345dc777ca2fc6170255cba94c685738c533a449
|
Provenance
The following attestation bundles were made for nf_ndc_connect_public-0.10.0-cp312-cp312-manylinux_2_38_x86_64.whl:
Publisher:
release.yml on NuFlights/nf_ndc_connect_public
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nf_ndc_connect_public-0.10.0-cp312-cp312-manylinux_2_38_x86_64.whl -
Subject digest:
19e1e79d784ddab5ff0a826176ce719d2c124f7bbda162988f316fa32dc55037 - Sigstore transparency entry: 1039430181
- Sigstore integration time:
-
Permalink:
NuFlights/nf_ndc_connect_public@40b1fab4d2965593bca270cef5b8160317857c2b -
Branch / Tag:
refs/tags/v0.10.0 - Owner: https://github.com/NuFlights
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@40b1fab4d2965593bca270cef5b8160317857c2b -
Trigger Event:
push
-
Statement type: