Introduction to Enersion-OIDC
Enersion-OIDC is a robust OpenID Connect (OIDC) library designed for seamless identity management and authentication in modern web applications. With a suite of powerful APIs, developers can easily integrate secure authentication, manage user sessions, and protect application resources.
API Examples
1. User Authentication
This endpoint facilitates user authentication.
POST /api/auth/login { "username": "john_doe", "password": "securePassword123" }
2. Fetch User Information
Retrieve detailed information about the authenticated user.
GET /api/user/info
3. Refresh Token
Renew an access token using a refresh token.
POST /api/auth/refresh { "refresh_token": "ea9eKtU5ybmP7GhDVCJG7g==" }
4. Log Out
Terminate the user session.
POST /api/auth/logout
Complete App Example
Setting Up An Example Application
Here’s an example of how to set up an application that uses the previously introduced APIs.
// Import necessary libraries import axios from 'axios'; // Base API URL const API_URL = 'https://api.enersion-oidc.com'; // User Login Function async function login(username, password) { const response = await axios.post(\`\${API_URL}/api/auth/login\`, { username, password }); return response.data; } // Get User Info Function async function getUserInfo(token) { const response = await axios.get(\`\${API_URL}/api/user/info\`, { headers: { 'Authorization': \`Bearer \${token}\` } }); return response.data; } // Refresh Token Function async function refreshToken(refreshToken) { const response = await axios.post(\`\${API_URL}/api/auth/refresh\`, { refresh_token: refreshToken }); return response.data; } // User Logout Function async function logout() { const response = await axios.post(\`\${API_URL}/api/auth/logout\`); return response.data; } // Example Usage async function main() { try { // User logs in const { access_token, refresh_token } = await login('john_doe', 'securePassword123'); // Fetch user info const userInfo = await getUserInfo(access_token); console.log('User Info:', userInfo); // Refresh token const newTokens = await refreshToken(refresh_token); console.log('New Tokens:', newTokens); // User logs out await logout(); console.log('User logged out.'); } catch (error) { console.error('An error occurred:', error); } } // Run the example main();
With these examples, developers can quickly integrate Enersion-OIDC into their web applications to ensure secure and efficient authentication processes.
Hash: 39028c76f784022b1868e4aae3e5a57981978721d8cf6e8d514e2fd1aa3cd5f0