π’ unaiverse.networking.node.tokens
What this module does π’
Verifies JWT authorization tokens used to authenticate peers joining worlds and pools, decoding and validating claims for connection authorization.
tokens
¶
βββββ βββββ ββββββ βββββ βββββ βββββ βββββ ββββββββββ βββββββββββ βββββββββ ββββββββββ
βββββ βββββ ββββββββ βββββ βββββ βββββ βββββ ββββββββββββββββββββββββ ββββββββββββββββββββββ
ββββ ββββ ββββββββ ββββ ββββββ ββββ ββββ ββββ ββββ β β ββββ ββββ ββββ βββ ββββ β β
ββββ ββββ βββββββββββββ ββββββββ ββββ ββββ ββββ βββββββ βββββββββββ βββββββββββ βββββββ
ββββ ββββ ββββ ββββββββ βββββββ ββββ βββββ βββ βββββββ ββββββββββββ βββββββββββ βββββββ
ββββ ββββ ββββ βββββββ ββββββββ ββββ βββββββββ ββββ β β ββββ ββββ βββ ββββ ββββ β β
ββββββββββ βββββ βββββββββββββββββ βββββ βββββ ββββββββββ βββββ ββββββββββββββββ ββββββββββ
ββββββββ βββββ βββββ ββββββββ βββββ βββ ββββββββββ βββββ βββββ βββββββββ ββββββββββ
A Collectionless AI Project (https://collectionless.ai)
Registration/Login: https://unaiverse.io
Code Repositories: https://github.com/collectionlessai/
Main Developers: Stefano Melacci (Project Leader), Christian Di Maio, Tommaso Guidi
TokenVerifier
¶
JWT verifier for UNaIVERSE node tokens signed with RS256.
Wraps the PyJWT library to decode and validate JSON Web Tokens that are
issued by the UNaIVERSE platform as node credentials. Verification uses
RS256 (RSA + SHA-256) asymmetric signing: the platform signs tokens with its
private key and nodes verify them with the corresponding public key stored in
this instance.
The optional keyword arguments of verify_token allow callers to enforce
that specific claims in the token payload match known values, making it
possible to bind a token to a particular network identity (node ID, IP
address, hostname, port, or P2P peer list).
Attributes:
| Name | Type | Description |
|---|---|---|
public_key |
The RSA public key used to verify token signatures. Stored
exactly as supplied at construction time ( |
Initialize the verifier with an RSA public key.
The supplied key must be the RSA public key that corresponds to the
private key used by the UNaIVERSE platform to sign node JWTs. It is
stored as-is and passed directly to jwt.decode on every call to
verify_token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
public_key
|
str | bytes
|
The RSA public key for RS256 signature verification. Accepted as either a PEM-encoded string or raw bytes. |
required |
Source code in unaiverse/networking/node/tokens.py
verify_token
¶
verify_token(token: str | bytes, node_id: str | None = None, ip: str | None = None, hostname: str | None = None, port: int | None = None, p2p_peer: str | None = None)
Decode and verify a UNaIVERSE node JWT against optional claim constraints.
The token is decoded with RS256 using the public key supplied at
construction. If decoding fails or the token has expired, (None, None)
is returned immediately. When decoding succeeds, each non-None keyword
argument is matched against the corresponding claim in the payload; the
first mismatch causes an early (None, None) return. Only when all
supplied constraints are satisfied does the method return the identity
values extracted from the payload.
The p2p_peer check tests membership in the payload's p2p_peers
list rather than equality, so a single token may authorise multiple peers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str | bytes
|
The JWT to verify, provided as a string or bytes object. |
required |
node_id
|
str | None
|
If not |
None
|
ip
|
str | None
|
If not |
None
|
hostname
|
str | None
|
If not |
None
|
port
|
int | None
|
If not |
None
|
p2p_peer
|
str | None
|
If not |
None
|
Returns:
| Type | Description |
|---|---|
|
A two-element tuple |
|
|
payload when all checks pass. Both elements are |
|
|
cannot be decoded, has expired, or fails any supplied constraint check. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the payload is valid but is missing the |