@arv-bedrock/auth-sso
v1.5.0
Published
`@arv-bedrock/auth-sso` is a JavaScript/TypeScript library designed to provide an easy-to-use interface for managing user authentication and account-related functionalities. This library integrates seamlessly with the Bedrock authentication system to stre
Downloads
1,897
Keywords
Readme
Bedrock Auth Library
@arv-bedrock/auth-sso is a JavaScript/TypeScript library designed to provide an easy-to-use interface for managing user authentication and account-related functionalities. This library integrates seamlessly with the Bedrock authentication system to streamline your app's security needs.
Installation
Install the library via npm:
npm install @arv-bedrock/auth-ssoGetting Started
Importing the Library
import * as BedrockAuth from "@arv-bedrock/auth-sso";Initialization
To initialize the authentication system, provide your credentials and configuration options:
import { initBedrockAuth } from "@arv-bedrock/auth-sso";
initBedrockAuth({
authUri: "https://auth.example.com",
clientId: "your-client-id",
clientSecret: "your-client-secret",
userType: "officer", // Optional: officer (default) / citizen
callback: (errorOrData) => {
if (errorOrData instanceof Error) {
console.error("Initialization error:", errorOrData);
} else {
console.log("Initialization successful:", errorOrData);
}
},
});API Reference
Authentication Methods
doLogin(redirectUrl?: string): void
Redirects the user to the login page.
BedrockAuth.doLogin("https://your-app.com/dashboard");doLogout(redirectUrl?: string): Promise<void>
Logs the user out and optionally redirects them to the specified URL.
BedrockAuth.doLogout("https://your-app.com");doRegister(redirectUrl?: string): void
Redirects the user to the registration page.
BedrockAuth.doRegister("https://your-app.com/welcome");verifyToken(): Promise<ResponseData<[]>>
Verifies the validity of the user's token.
const response = await BedrockAuth.verifyToken();
console.log("Response:", response);Profile Management
getProfile(): Promise<ResponseData<AuthServiceResponse> | undefined>
Fetches the current user's profile.
const profile = await BedrockAuth.getProfile();
console.log("User profile:", profile);updateProfile(body: UpdateProfile): Promise<ResponseData<[]>>
Updates the user's profile.
const response = await BedrockAuth.updateProfile({ firstName: "First Name", lastName: "Last Name" title: "Mr.", userId: "User Id" });
console.log("Profile updated.", response);Account Management
doManageAccount(redirectUrl?: string): void
Redirects the user to the account management page.
BedrockAuth.doManageAccount("https://your-app.com/manage-account");disabledAccount(body: DisabledAccount): Promise<ResponseData<[]>>
Disables a user account.
await BedrockAuth.disabledAccount({ userId: "12345", isDisabled: true });
console.log("Account disabled.");Token and Cookie Management
setCookie(code: string): Promise<void>
Sets an authentication cookie.
await BedrockAuth.setCookie("auth-code");clearCookie(): Promise<void>
Clears the authentication cookie.
await BedrockAuth.clearCookie();refreshToken(): Promise<ResponseData<RefreshTokenResponse>>
Refreshes the authentication token.
const newToken = await BedrockAuth.refreshToken();
console.log("New token:", newToken);getCode(): Promise<string>
Retrieves the authentication code.
const code = await BedrockAuth.getCode();
console.log("Auth code:", code);Invites
requestInviting(email: string, duration?: number): Promise<ResponseData<[]>>
Sends an invitation email.
await BedrockAuth.requestInviting("[email protected]", 7);
console.log("Invitation sent.");Import/Update/Delete Users
importUsers(usres: ImportUserType[]): Promise<ResponseData<ImportUserResponse>>
Import users for preregistration
const importUser = await BedrockAuth.importUsers([{
title: "title";
email: "email";
firstName: "firstName";
lastName: "lastName";
phoneNumber: "phoneNumber";
}]);
console.log("ImportUsers", importUser);UpdateImportUsers
updateImportUsers(usres: ImportUserType[]): Promise<ResponseData<ImportUserResponse>>
Update the previously existing and unexpired imported records via email
const updateImportUser = await BedrockAuth.updateImportUsers([{
title: "title";
email: "email";
firstName: "firstName";
lastName: "lastName";
phoneNumber: "phoneNumber";
}]);
console.log("updateImportUser", updateImportUser);DeleteImportUsers
deleteImportUsers(usres: ImportUserType[]): Promise<ResponseData<ImportUserResponse>>
Delete the previously existing and unexpired imported records via email
const deleteImportUser = await BedrockAuth.deleteImportUsers(["[email protected]", "[email protected]"]);
console.log("deleteImportUser", deleteImportUser);Advanced Features
doPortal(): void
Redirects the user to the authentication portal.
BedrockAuth.doPortal();getRedirectUri(): string
Retrieves the current redirect URI.
const redirectUri = BedrockAuth.getRedirectUri();
console.log("Redirect URI:", redirectUri);Type Definitions
AuthProps
Defines the properties required to initialize Bedrock Auth.
export type AuthProps = {
userType?: UserType; // "citizen" | "officer" (default: "officer")
authUri: string;
clientId: string;
clientSecret: string;
callback: (error?: any) => void;
};DisabledAccount
Represents the details needed to disable an account.
export type DisabledAccount = {
userId: string;
isDisabled: boolean;
};UpdateProfile
Defines the structure for updating user profile information.
export type UpdateProfile = {
userId: string;
title: string;
firstName: string;
lastName: string;
picture?: string | undefined | null;
};ImportUserType
Represents the input data required to import a single user into the system.
export type ImportUserType {
title?: string;
email: string;
firstName?: string;
lastName?: string;
phoneNumber?: string;
}ImportUserResponse
The response structure returned after processing a batch import of users. Contains a correlation ID for tracking and a list of per-user results.
export type ImportUserResponse {
correlationId: string;
results: ImportUserResult[];
}ImportUserResult
Detailed result of an individual user import operation, including whether it succeeded and any failure reasons.
export type ImportUserResult {
i: number;
email: string;
success: boolean;
reasons: string[];
code?: string;
title?: string;
firstName?: string;
lastName?: string;
phoneNumber?: string;
expireAt?: string;
}