@myzenkai/sdk
v0.1.0
Published
Official myZenkai OAuth2 PKCE SDK
Readme
@myzenkai/sdk
Official myZenkai SDK for OAuth2 Authorization Code + PKCE in browser apps.
Install
npm install @myzenkai/sdkQuick start
import { createMyZenkaiSdk } from "@myzenkai/sdk";
const sdk = createMyZenkaiSdk({
clientId: "your_client_id",
authorizeEndpoint: "https://europe-west1-myzenkai-c58ee.cloudfunctions.net/oauthAuthorize",
tokenEndpoint: "https://europe-west1-myzenkai-c58ee.cloudfunctions.net/oauthToken",
redirectUri: "https://your-app.example.com/callback",
scope: ["openid", "profile:read"]
});
// Login button
await sdk.startLogin();
// Callback page
const result = await sdk.handleCallback();
if (result.ok) {
console.log("Authenticated", result.session);
}API
startLogin(options?): creates PKCE/state and redirects by default.handleCallback(options?): validates callback and exchanges code for token.getSession(): returns saved session ornull.isAuthenticated(): checks if a non-expired session exists.logout(): clears local session and pending auth context.
Notes
- Reserved OAuth params are protected and cannot be overridden via
defaultAuthorizeParamsorextraParams:client_id,redirect_uri,response_type,scope,state,code_challenge,code_challenge_method. - If
expires_inis missing or invalid, the SDK applies a default session TTL of 3600 seconds. handleCallback()validates both HTTP status and token payload shape (access_tokenandtoken_typeare required).
Full documentation
For detailed guides, troubleshooting, and end-to-end examples, see:
Build
npm run build