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.
- OIDC support with Authorization Code Flow (PKCE).
- Retrieve and decode tokens (ID, Access).
- Fetch user profile securely.
npm install fayda-auth-sdkInitialize 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",
});Generate the authorization URL to redirect users for login:
const authUrl = fayda.getAuthorizationUrl("unique-state-value");
console.log(authUrl);
// Redirect the user to this URLAfter 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);Use the access token to securely fetch user profile information:
const userInfo = await fayda.getUserInfo(tokens.access_token);
console.log("User Info:", userInfo);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);