Skip to main content

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 like owner/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 (the org_short_code), checks are performed strictly against that group's summary.
  • Auto-Resolution: If you omit group_name (pass None / 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

  1. Install Nix.
  2. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nf_ndc_connect_public-0.17.0.tar.gz (46.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nf_ndc_connect_public-0.17.0-cp313-cp313-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.13Windows x86-64

nf_ndc_connect_public-0.17.0-cp313-cp313-manylinux_2_38_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ x86-64

nf_ndc_connect_public-0.17.0-cp313-cp313-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

nf_ndc_connect_public-0.17.0-cp312-cp312-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.12Windows x86-64

nf_ndc_connect_public-0.17.0-cp312-cp312-manylinux_2_38_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

nf_ndc_connect_public-0.17.0-cp312-cp312-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nf_ndc_connect_public-0.17.0-cp311-cp311-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.11Windows x86-64

nf_ndc_connect_public-0.17.0-cp311-cp311-manylinux_2_38_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ x86-64

nf_ndc_connect_public-0.17.0-cp311-cp311-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

nf_ndc_connect_public-0.17.0-cp310-cp310-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10Windows x86-64

nf_ndc_connect_public-0.17.0-cp310-cp310-manylinux_2_38_x86_64.whl (4.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ x86-64

nf_ndc_connect_public-0.17.0-cp310-cp310-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file nf_ndc_connect_public-0.17.0.tar.gz.

File metadata

  • Download URL: nf_ndc_connect_public-0.17.0.tar.gz
  • Upload date:
  • Size: 46.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nf_ndc_connect_public-0.17.0.tar.gz
Algorithm Hash digest
SHA256 5c80aeefc0156dc45e9c78685122e5c4eeeb4821956bbd04bbca871cd21bdb74
MD5 dfb8e83a09427c06547eecdf487605ee
BLAKE2b-256 adfc234845ada2915f53ad4f65dcef282b65c36cd1177535617a5157a2ab2043

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0.tar.gz:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nf_ndc_connect_public-0.17.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for nf_ndc_connect_public-0.17.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 45d2d249a55b5b2ec6ca1d04b773770f30c29cb32c3d2c71adad473ffa2bad91
MD5 40db0adec873e7a549dcb985cf1c89c3
BLAKE2b-256 640e33152c4953179baa33b9eabb25427c2c9d5ac54311913cbfb0a8a6ffff5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0-cp313-cp313-win_amd64.whl:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nf_ndc_connect_public-0.17.0-cp313-cp313-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for nf_ndc_connect_public-0.17.0-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 ee07e65f845e992a03e9e2a490e88704dd51e88e27913d58fe8726c2f10cbf38
MD5 6ab960a0806633489056162c2b8caf5a
BLAKE2b-256 6953178499a7db20c5e73bf0ced74febb74465745f9ba826aec119e61d3e5c2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0-cp313-cp313-manylinux_2_38_x86_64.whl:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nf_ndc_connect_public-0.17.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nf_ndc_connect_public-0.17.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d3051525e455dcf0e4b9d384bceecaf5f920ddaa569d67e0cc3720c86d9846e4
MD5 908386bf4c87d522e7af967134f586f7
BLAKE2b-256 957e9947964069ab9ce8927e8c6fbc56b5de67130d46882208417ec088066094

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nf_ndc_connect_public-0.17.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for nf_ndc_connect_public-0.17.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 99c76f379075efcf7189e4d3b7aae5963f65dc2c97bff38f464154b60267de8b
MD5 13ed5bfa1dff595b092e6ce3123fd10d
BLAKE2b-256 2ba3bef6a635ef2b07e9f049adf5802313808b8974985a391052e56ef6135a16

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nf_ndc_connect_public-0.17.0-cp312-cp312-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for nf_ndc_connect_public-0.17.0-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 d1c06bae66dbbfefa4dbef1b9f9945236468fb1895e59a112865c8408dfca848
MD5 6bb9649c844c71ec969abc2f6b0249fb
BLAKE2b-256 6e205fdbf7156647fd2c7575774fdc4cde0b1c5ddf4a9ff1ce7e4551cc9a1ac9

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0-cp312-cp312-manylinux_2_38_x86_64.whl:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nf_ndc_connect_public-0.17.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nf_ndc_connect_public-0.17.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0418e20b6969500c6cf267334d74718d5e1a47f8a2e5a694363a7e45a52216a2
MD5 6652320cbe703ccfb372483b1089d163
BLAKE2b-256 0074e7cfb44f71b0d8270a77ae43523effcb99a8b7315e7ee0dd36b21cd9a5b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nf_ndc_connect_public-0.17.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for nf_ndc_connect_public-0.17.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 adc00cc702335bee5c5c69f02d6b593d7cca7f86281bb8490d165c2faf80842b
MD5 e2aa72df9dbf788d2a18581c25dacc1a
BLAKE2b-256 b78b3584366c6fea557c54b0e145eead5656fc1791072f8c46c5ee6bec8dcaa2

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0-cp311-cp311-win_amd64.whl:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nf_ndc_connect_public-0.17.0-cp311-cp311-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for nf_ndc_connect_public-0.17.0-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 563c831770bff9000c4adc6670720dd5b9fdd745a5da6c98337195ba65935510
MD5 796967eb89132a16a5d7aa895c3cdb83
BLAKE2b-256 4723d3dbf8dbbc0937dc1532624722c3802efea2fc93921c743632056a9bf3d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0-cp311-cp311-manylinux_2_38_x86_64.whl:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nf_ndc_connect_public-0.17.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nf_ndc_connect_public-0.17.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 335b886ba620833b13f73e34973a881e0e670f127d5ed7eab73eff38c7fb0965
MD5 107b91332e497506bbb766c233455000
BLAKE2b-256 f0a4b10a89b714a1ad09300cf56aa49aef8bd0116cce0a78a56cb0244f6642fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nf_ndc_connect_public-0.17.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for nf_ndc_connect_public-0.17.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 893d894c3a0945ecdad9e36e73552acc883f7f9d640ec12a2d68d9d9ba8f9e78
MD5 79726997f50156146b2837579d555aa7
BLAKE2b-256 be8143eef054f264a8049df0b29de38c8e6969aa9ed999207c390593adc7bb7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0-cp310-cp310-win_amd64.whl:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nf_ndc_connect_public-0.17.0-cp310-cp310-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for nf_ndc_connect_public-0.17.0-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 6a330635209ffa917607f18147ea72cb037edaeda1fa73f4ffed4044bffd2d2c
MD5 028840b5f995959d94cb2e047e6859df
BLAKE2b-256 9faae10abe430cb8da1b8256d6775e3b4f382941bb978b32647885f54a94d5eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0-cp310-cp310-manylinux_2_38_x86_64.whl:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nf_ndc_connect_public-0.17.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nf_ndc_connect_public-0.17.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6e508af61e2b7e386a533f8d563cb783793b6c3f2e4b9028969cb9dcf80a2f90
MD5 56e5a3609903f23dae4603877f535efd
BLAKE2b-256 23538b1535c0364791bf580ebc97ef910dc031350b4f7bf2d6140013310cb53e

See more details on using hashes here.

Provenance

The following attestation bundles were made for nf_ndc_connect_public-0.17.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release.yml on NuFlights/nf_ndc_connect_public

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page