SDKs

Official libraries

All SDKs talk only to the cloud issuer. Portal never appears as iss.

Go — otrust-go

go get github.com/0TrustCloud/otrust-go
import \"github.com/0TrustCloud/otrust-go/otrust\"

cfg := otrust.FromEnv()
client := otrust.New(cfg)
pkce, _ := otrust.NewPKCE()
state, _ := otrust.RandomState()
nonce, _ := otrust.RandomState()
url, _ := client.AuthCodeURL(state, nonce, &pkce)
// redirect user to url …

tokens, err := client.ExchangeCode(ctx, code, pkce.Verifier)
claims, err := client.ValidateIDToken(ctx, tokens.IDToken, nonce)

JavaScript — @0trust/otrust-js

npm install @0trust/otrust-js
import { OTrustClient, createPKCE, randomState } from \"@0trust/otrust-js\";

const client = OTrustClient.fromEnv();
const pkce = await createPKCE();
const state = await randomState();
const nonce = await randomState();
const url = await client.authCodeUrl({
  state, nonce,
  pkce: { challenge: pkce.challenge, method: \"S256\" },
});
// redirect …

const tokens = await client.exchangeCode(code, pkce.verifier);
const claims = client.assertIdTokenClaims(tokens.id_token, { nonce });

Python — otrust

pip install otrust
from otrust import Config, OTrustClient, new_pkce, random_state

cfg = Config.from_env()
client = OTrustClient(cfg)
pkce = new_pkce()
state, nonce = random_state(), random_state()
url = client.auth_code_url(state=state, nonce=nonce, pkce=pkce)
# redirect …

tokens = client.exchange_code(code, pkce.verifier)
claims = client.validate_id_token(tokens.id_token, nonce=nonce)
print(claims[\"sub\"])

Source in monorepo

sdk/go · sdk/javascript · sdk/python · API endpoints