npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ssofy/javascript-sdk

v1.2.0

Published

Official SSOfy Javascript SDK.

Downloads

268

Readme

SSOfy Javascript SDK

Official SSOfy Javascript SDK.

Built for use in browsers and Node.js applications.

Read the full documentation at SSOfy Knowledge Base.

Installation

CDN

<script src="https://cdn.jsdelivr.net/gh/ssofy/javascript-sdk/dist/ssofy.min.js"></script>

<!-- UMD Version -->
<script src="https://cdn.jsdelivr.net/gh/ssofy/javascript-sdk/dist/ssofy.umd.min.js"></script>

Installing via NPM

npm i @ssofy/javascript-sdk -S

Installing via YARN

yarn add @ssofy/javascript-sdk

Usage

Client Configuration

Browser:

const client = new SSOfy.OAuth2Client({
    url: 'https://YOUR-SSO-DOMAIN',
    clientId: 'sandbox',
    redirectUri: 'https://CURRENT-DOMAIN/callback'
    scopes: ['*'],
    locale: 'en',
    // state: '', //optional
    stateStore: new SSOfy.LocalStorage(),
    stateTtl: 30 * 24 * 60 * 60,
});

ES6 / Typescript:

import { OAuth2Config, OAuth2Client, Storage, FileStorage } from "@ssofy/javascript-sdk";
import fs from "fs";

const storagePath = fs.mkdtempSync('/tmp/');
const stateStore = new FileStorage(storagePath);

const config = new OAuth2Config({
    url: 'https://YOUR-SSO-DOMAIN',
    clientId: 'sandbox',
    clientSecret: 'sandbox',
    redirectUri: 'https://CURRENT-DOMAIN/callback'
    pkceVerification: true,
    scopes: ['*'],
    locale: 'en',
    // state: '', //optional
    stateStore: <Storage>stateStore,
    stateTtl: 30 * 24 * 60 * 60,
});

const client = new OAuth2Client(config);

Generate Login Url

Auth Code Flow

const customAuthorizationUrl = null; // optional
const nextUri = null; // optional

const stateData = await client.initAuthCodeFlow(customAuthorizationUrl, nextUri);

// redirect to the login page
window.location.href = stateData.authorizationUri;

Implicit Flow

const customAuthorizationUrl = null; // optional
const nextUri = null; // optional

const stateData = await client.initImplicitFlow(customAuthorizationUrl, nextUri);

// redirect to the login page
window.location.href = stateData.authorizationUri;

Handling Callbacks

// create json payload from url parameters
const parameters = SSOfy.UrlHelper.getParameters(window.location.href);

// handle the callback
const stateData = await client.handleCallback(parameters);

// store the last login state identifier somewhere for future use
localStorage.setItem('state', stateData.state);

if (stateData.nextUri) {
    // Hint: /optional-uri-to-redirect-next
    window.location.href = stateData.nextUri;
}

Get Access Token

const state = localStorage.getItem('state');

const accessToken = await client.getAccessToken(state);

Renew Access Token

In most cases, it's not necessary to call this method as getAccessToken() refreshes the token automatically upon expiration. However, should you require an earlier token refresh, this method can be used in such instances.

const state = localStorage.getItem('state');

const accessToken = await client.renewAccessToken(state);

Logout Locally

await client.destroy(state);

Logout Globally (SLO)

await client.destroy(state);

// logout from this device
window.location.href = config.logoutUrl('URI-TO-REDIRECT-AFTER-LOGOUT')

// logout from all devices (SLO)
window.location.href = config.logoutEverywhereUrl('URI-TO-REDIRECT-AFTER-LOGOUT')

Get User Info

const state = localStorage.getItem('state');

const user = await client.getUserInfo(state);

Support

Feel free to reach support with any questions regarding the integration or reporting issues. Our technical experts are available around the clock to conduct investigations and provide the highest quality product and service support as quickly as possible.

Author

SSOfy and derivatives are by Cubelet Ltd.

License

The MIT License (MIT). Please see License File for more information.