Skip to content

kalebalebachew/fayda-auth-sdk

Repository files navigation

Fayda Auth SDK

npm

Fayda Auth SDK simplifies integration with the Fayda eSignet platform using OpenID Connect (OIDC). Quickly set up secure authentication and access user data in your applications.

Features

  • OIDC support with Authorization Code Flow (PKCE).
  • Retrieve and decode tokens (ID, Access).
  • Fetch user profile securely.

Installation

npm install fayda-auth-sdk

Usage Guide

1. Initialize FaydaOIDC

Initialize the FaydaOIDC instance with your credentials and endpoint URLs:

import { FaydaOIDC } from "fayda-auth-sdk";

const fayda = new FaydaOIDC({
  clientId: "your-client-id",
  redirectUri: "https://yourapp.com/callback",
  authorizationEndpoint: "https://esignet.authorization.endpoint",
  tokenEndpoint: "https://esignet.token.endpoint",
  userInfoEndpoint: "https://esignet.userinfo.endpoint",
});

2. Get Authorization URL

Generate the authorization URL to redirect users for login:

const authUrl = fayda.getAuthorizationUrl("unique-state-value");
console.log(authUrl);
// Redirect the user to this URL

3. Exchange Authorization Code for Tokens

After the user logs in, exchange the authorization_code received in your callback for tokens:

const tokens = await fayda.exchangeCodeForTokens("authorization-code");
console.log("ID Token:", tokens.id_token);
console.log("Access Token:", tokens.access_token);

4. Retrieve User Information

Use the access token to securely fetch user profile information:

const userInfo = await fayda.getUserInfo(tokens.access_token);
console.log("User Info:", userInfo);

5. Decode ID Token

Decode the ID Token to extract user claims such as name and email:

const userClaims = fayda.decodeIdToken(tokens.id_token);
console.log("User Claims:", userClaims);

About

This is a NodeJs SDK for Fayda's National ID Identity Verification Using Open Id Connect

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published