marcedivault-sdk
v1.0.8
Published
Official Node.js SDK for integrating with MarcediVault's OAuth system.
Maintainers
Readme
MarcediVault SDK
Official Node.js SDK for securely integrating with the MarcediVault OAuth System by Xentrius.
This SDK enables third-party apps to:
- Exchange authorization codes for tokens
- Refresh access tokens
- Verify and decode JWT access tokens
- Protect routes with JWT middleware
- (Optionally) Fetch authenticated user info
🔧 Installation
npm install marcedivault-sdk
⚙️ SDK Setup
Before using any features, initialize the SDK with your credentials:
import { init } from 'marcedivault-sdk';
init({
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
jwtSecret: 'your-jwt-verification-secret-or-public-key'
});
✨ Features
🔐 Exchange Authorization Code
import { exchangeToken } from 'marcedivault-sdk';
const { access_token, refresh_token, expires_in } = await exchangeToken({
code: 'auth_code_from_redirect',
redirectUri: 'https://your-app.com/callback'
});
♻️ Refresh Access Token
import { refreshToken } from 'marcedivault-sdk';
const newTokens = await refreshToken('your-refresh-token');
✅ Verify Access Token
js
Copy code
import { verifyAccessToken } from 'marcedivault-sdk';
try {
const user = verifyAccessToken('access-token');
console.log(user); // JWT payload (e.g. sub, email, etc.)
} catch (err) {
console.error('Token is invalid:', err.message);
}
🛡️ Secure Express Routes
js
Copy code
import express from 'express';
import { authMiddleware } from 'marcedivault-sdk';
const app = express();
app.get('/profile', authMiddleware(), (req, res) => {
res.json({ user: req.user });
});
👤 Fetch User Info (Optional)
js
Copy code
import { getUserInfo } from 'marcedivault-sdk';
const user = await getUserInfo('access-token');
console.log(user);
📘 Example Usage
js
Copy code
import {
init,
exchangeToken,
refreshToken,
verifyAccessToken,
authMiddleware,
getUserInfo
} from 'marcedivault-sdk';
init({
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
jwtSecret: 'your-verification-key'
});
// Use in Express app
app.get('/dashboard', authMiddleware(), (req, res) => {
res.json({ message: 'Secure route', user: req.user });
});
🔐 Security
This SDK:
Only transmits data over HTTPS
Does not store any tokens internally
Requires JWT secret or public key for verification
Can be extended with encryption (e.g. via ZeroSight Protocol)
🧠 Requirements
Node.js v16+
Uses ES Modules (type: "module")