Ulifyi SDK is a JavaScript library that provides a convenient interface for interacting with the Ulifyi API. It allows you to easily integrate Ulifyi authentication and user data retrieval into your applications.
- Authenticate users with Ulifyi using OAuth2.
- Retrieve user data, including self-information and information about other users.
npm install ulifyi-sdk
const UlifyiSdk = require('ulifyi-sdk');
const ulifyi = new UlifyiSdk();
ulifyi.init('YOUR_ACCESS_TOKEN');
try {
const selfUserData = await ulifyi.getUserSelf();
console.log('Self User Data:', selfUserData);
} catch (error) {
console.error('Error fetching self user data:', error.message);
}
const userId = 'TARGET_USER_ID';
try {
const targetUserData = await ulifyi.getUserById(userId);
console.log(`User Data for User ID ${userId}:`, targetUserData);
} catch (error) {
console.error(`Error fetching user data for User ID ${userId}:`, error.message);
}
const clientId = 'YOUR_CLIENT_ID';
const redirectUri = 'YOUR_REDIRECT_URI';
const scopes = 'openid profile email'; // Example scopes
const responseType = 'code';
const state = 'YOUR_STATE';
try {
const authorizationUrl = ulifyi.generateUrl(clientId, redirectUri, scopes, responseType, state);
console.log('OAuth2 Authorization URL:', authorizationUrl);
} catch (error) {
console.error('Error generating OAuth2 authorization URL:', error.message);
}
init(accessToken: string)
: Initializes the SDK with the provided access token.getUserSelf(): Promise<UserData>
: Retrieves the user's self information.getUserById(userId: string): Promise<UserData>
: Retrieves user information by user ID.generateUrl(clientId: string, redirectUri: string, scopes: string, responseType: string, state: string): string
: Generates an OAuth2 authorization URL.
Contributions are welcome! Please feel free to submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.