SDK Reference
Full API documentation for @networkcoin/sdk
Installation
Terminal
npm install @networkcoin/sdkConstructor
TypeScript
import { NetworkCoinClient } from '@networkcoin/sdk';
const client = new NetworkCoinClient({
clientId: 'your-client-id', // Required
redirectUri: 'http://localhost:3000/callback', // Required
scope: 'openid profile email wallet offline_access subscription',
domain: 'https://id.networkcoin.ai', // Optional (default shown)
});| Property | Type | Required | Description |
|---|---|---|---|
| clientId | string | Yes | From Console > Apps |
| redirectUri | string | Yes | Must match Console config |
| scope | string | No | Space-separated scopes |
| domain | string | No | For self-hosted instances |
Methods
client.login()
Redirects to the NETWORKCOIN.ID login page. Automatically generates PKCE challenge (S256) and state parameter.
await client.login();
// Browser redirects to networkcoin.id/oauth/authorizeclient.handleCallback(url?)
Handles the OAuth callback. Verifies state, exchanges code for tokens, stores them. Call this on your redirect URI page.
const tokens = await client.handleCallback();
// { access_token, id_token, refresh_token, token_type, expires_in, scope }client.getUser(accessToken?)
Fetches user profile from UserInfo endpoint. Auto-refreshes if the token is expired. Includes subscription data if the subscription scope was requested.
const user = await client.getUser();
// { sub, name, email, email_verified, picture,
// wallet_address, subscription }
// Check subscription:
if (user.subscription?.status === 'active') {
console.log('Plan:', user.subscription.plan);
// "Personal", "Business", "Enterprise Plus", etc.
}client.refreshToken(refreshToken?)
Exchanges refresh token for new access + refresh tokens. Automatically stores the new tokens.
const newTokens = await client.refreshToken();client.logout(postLogoutRedirectUri?)
Revokes refresh token, clears local storage, redirects to OIDC logout endpoint.
await client.logout('http://localhost:3000');client.isAuthenticated()
Returns true if a non-expired access token exists.
client.getAccessToken()
Returns the stored access token string for use in API calls, or null.
Type Definitions
TypeScript
interface NetworkCoinConfig {
clientId: string;
redirectUri: string;
scope?: string; // Default: "openid profile email wallet"
domain?: string; // Default: "https://id.networkcoin.ai"
}
interface NetworkCoinSubscription {
plan: string; // "Personal", "Business", etc.
status: 'active' | 'trialing' | 'cancelled' | 'expired';
amount: number; // In cents (e.g. 7900 = $79.00)
interval: 'month' | 'year';
current_period_end: string; // ISO 8601 date
cancelled_at: string | null;
}
interface NetworkCoinUser {
sub: string;
name?: string;
email?: string;
email_verified?: boolean;
picture?: string;
wallet_address?: string;
updated_at?: string;
subscription?: NetworkCoinSubscription | null;
// null = no active subscription
// Requires "subscription" scope
}
interface TokenResponse {
access_token: string;
token_type: string;
expires_in: number;
id_token: string;
refresh_token?: string;
scope: string;
}