@easecation/iam-client
v1.1.0
Published
IAM V2 client library for EaseCation services
Maintainers
Readme
@easecation/iam-client
IAM V2 client library for EaseCation services. Provides an API wrapper and an Express middleware for validating RS256 access tokens against IAM.
Install
npm install @easecation/iam-clientQuick Start
import { IamClient } from '@easecation/iam-client';
const client = new IamClient({
iamBaseUrl: 'http://localhost:8401',
clientId: '10007',
clientSecret: 'YOUR_CLIENT_SECRET',
});
// Exchange OAuth code for access + refresh tokens
const tokens = await client.exchangeOAuthCode(code, redirectUri);
// Verify access token and fetch permissions
const verify = await client.verifyToken(tokens.access_token);
// Fetch profile + user_data (batch)
const bootstrap = await client.getUserBootstrap(tokens.access_token, [
'group',
'ECID',
'serverAdmin',
'serverAdminDue',
]);
// HR helper
const hrBootstrap = await client.getHrBootstrapData(tokens.access_token);
// Legacy V1 (callback verify)
const valid = await client.verifyIamCallbackToken(iamToken);Express Middleware
import express from 'express';
import { IamClient, createIamAuthMiddleware } from '@easecation/iam-client';
const client = new IamClient({
iamBaseUrl: 'http://localhost:8401',
clientId: '10007',
clientSecret: 'YOUR_CLIENT_SECRET',
});
const iamAuth = createIamAuthMiddleware(client);
const router = express.Router();
router.get('/profile', iamAuth(), (req, res) => {
const iamReq = req as any;
res.json({ uid: iamReq.iamUid, permissions: iamReq.iamPermissions });
});
router.post('/admin', iamAuth(['admin.write']), handler);API Highlights
getAppSessionToken()exchangeOAuthCode(code, redirectUri)verifyToken(accessToken)refreshToken(refreshToken)revokeToken(refreshToken)getUserProfile(accessToken)getUserPermissions(userId, targetApplicationId?)getJwks()
Notes
- App session authentication uses the
X-App-Session-Tokenheader. - Verify results are cached locally with a TTL that never exceeds the access token expiration.
