@magic-sdk/sso
v0.2.2
Published
Magic Javascript SSO SDK
Downloads
20
Maintainers
Keywords
Readme
Magic SSO Admin Javascript SDK
Magic SSO Admin SDK provides an easy interface for integrating parties to implement SAML/SSO authentication offered by the Magic platform to select vendors.
Installation
This is an experimental SSO implementation using magic intended only for select partners.
npm install --save @magic-sdk/sso
or
yarn add @magic-sdk/sso
Usage
Generating a SAML Project and configuring a provider
const MagicSSO = require('@magic-sdk/sso');
// Create a Magic Admin SSO instance
const magicSSO = new MagicSSO(‘YOUR_DEVELOPER_SECRET_KEY’);
// Login Users
const SAMLConnectionInfo = await magicSSO.addSamlConnection();
await magicSSO.setProvider({
project_id, /* from addSamlConnection */
entity_id, /* from IDP */
redirect_url,
issuer, /* IDP Name ie. auth0 */
sso_url, /* from IDP */
signing_certificate, /* from IDP */
metadata_url,
options,
});
Logging in a SAML user
import express from 'express';
const MagicSSO = require('@magic-sdk/sso');
const app = express();
// Create a Magic Admin SSO instance
const magicSSO = new MagicSSO(‘YOUR_DEVELOPER_SECRET_KEY’);
// Logging Users In
// Authentication endpoint
app.get('/auth', async (req: any, res: any) => {
try {
const { projectID } = req.query;
const authorizationURL = await magicSSO.getAuthorizationUrl(projectID);
res.redirect(authorizationURL);
} catch (err) {
console.error(err);
}
});
// Callback endpoint
app.get('/callback', async (req: any, res: any) => {
try {
const { code } = req.query;
const userInfo = await magicSSO.getProfile(code);
// ... logged in
res.redirect('/');
} catch (err) {
console.error(err);
}
});
Refer to src/node-e2e/app.ts
for reference implementation