more-sso-sdk
v1.5.8
Published
SSO login
Readme
🔐 more-sso-sdk
The more-sso-sdk provides a simple and consistent way to integrate Single Sign-On (SSO) into your applications.
It supports both Next.js and Vite projects, offering easy initialization, token handling, and logout functionality.
📦 Installation
npm install more-sso-sdkor
yarn add more-sso-sdk📥 Import
import { SSOAuthorization, ENV } from "more-sso-sdk";⚙️ Initialization
Initialize the SDK at the entry point of your application:
SSOAuthorization.init({
env: ENV.DEV, // ENV.DEV or ENV.PROD
redirectUrl: "https://id.dev.more.in/login", // or https://id.more.in/login for PROD
app: "insight", // your project name
idp: "https://api.sso.dev.more.in/",
});🔧 Configuration Options
| Key | Type | Values | Description |
| ------------- | -------- | --------------------------------------------------------------- | --------------------------------------------------- |
| env | ENV | ENV.DEV | ENV.PROD | Environment mode (development or production). |
| redirectUrl | string | https://id.dev.more.in/login https://id.more.in/login | The SSO login page URL. |
| app | string | Any string | The name of your project (used for identification). |
| idp | string | https://api.sso.dev.more.in/ https://api.sso.more.in/ | SSO server API URL |
🔑 Authentication Methods
1. Get Token (Production / Development)
SSOAuthorization.getToken(redirectURL: string): Promise<string>redirectURL: The URL of your app to redirect back after login.
Example:
const currentUrl = window.location.href;
const encodedRedirect = encodeURIComponent(currentUrl);
SSOAuthorization.getToken(encodedRedirect)
.then((token) => {
if (token) {
setAccessToken(token);
}
})
.catch((error) => {
console.error("Token fetch failed", error);
});2. Get Dev Token (Local Development Only)
SSOAuthorization.getDevToken(username: string): Promise<string>username: Developer username / domain ID.
Example:
SSOAuthorization.getDevToken(process.env.NEXT_PUBLIC_USERNAME as string)
.then((token) => {
if (token) {
setAccessToken(token);
}
})
.catch((error) => {
console.error("Dev token fetch failed", error);
});3. Unified Token Fetch (Recommended)
if (process.env.NODE_ENV === "development") {
SSOAuthorization.getDevToken(process.env.NEXT_PUBLIC_USERNAME as string)
.then((result) => {
if (result) {
setAccessToken(result);
}
})
.catch((error) => {
console.error(error);
});
} else {
const currentUrl = window.location.href;
const encodedRedirect = encodeURIComponent(currentUrl);
SSOAuthorization.getToken(encodedRedirect)
.then((result) => {
if (result) {
setAccessToken(result);
}
})
.catch((error) => {
console.error(error);
});
}🚪 Logout
SSOAuthorization.logout(redirectURL: string): Promise<void>Example:
SSOAuthorization.logout("https://myapp.com")
.then(() => {
console.log("Logged out successfully");
})
.catch((error) => {
console.error("Logout failed", error);
});📌 Notes
- Use
ENV.DEVfor development andENV.PRODfor production. - In local development, prefer
getDevTokenfor faster workflow.
📜 License
MIT © More
