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

@crds_npm/crds-client-auth

v2.0.13

Published

Client side library for managing auth

Downloads

34

Readme

Crossroads Auth Typescript Library

crds-client-auth will enable your product to:

  • check authentication status
  • get updates on authentication status changes

Installing

Install via NPM with

npm install --save @crds_npm/crds-client-auth

Create the config objects and create instance of auth service

import { 
CrdsAuthenticationService, 
CrdsLoggerService, 
CrdsAuthConfig, 
CrdsOktaConfig, 
CrdsMpConfig, 
CrdsAuthenticationProviders } from  '@crds_npm/crds-client-auth';
 
let  oktaConfig:  CrdsOktaConfig  = {
	clientId:  'CLIENT_ID',
	issuer:  '{OKTA_URL}/oauth2/default',
	redirectUri: 'REDIRECT_URI', //This one is a bit tricky. There are two parts. 1. This should be the fully qualified base url where your app is hosted. Maybe that's https://int.crossroads.net, https://media.crossroads.net, https://www.crossroads.net. 2. The url must be registered in the okta portal under the application redirectUri settings.
	tokenManager: {
		storage:  'cookie'
	},
}

let  mpConfig:  CrdsMpConfig  = {
	accessTokenCookie:  'ACCESS_TOKEN_COOKIE_NAME',
	refreshTokenCookie:  'REFRESH_TOKEN_COOKIE_NAME',
	issuer: 'MP AUTH ENDPOINT'
}

let  authConfig:  CrdsAuthConfig  = {
	oktaConfig:  oktaConfig,
	mpConfig:  mpConfig,
	logging: false, //Do you want to log debug info to the web console?
	providerPreference: [
		// Put these in the order you want the library to check for auth status
		CrdsAuthenticationProviders.Rock,
		CrdsAuthenticationProviders.Okta,
		CrdsAuthenticationProviders.Mp
	]
}

let authService = new CrdsAuthenticationService(authConfig);

authService.authenticated().subscribe(tokens  => {
	if (tokens) {
		console.log('logged in');
	}
	else {
		console.log('not logged in');
	}
})

API

Documentation


CrdsAuthenticationService


Basic service used to interact with Auth Status

function: authenticated(): Observable<CrdsTokens>

Returns an observable that contains either the tokens for the user (if logged in), or null if not logged in. This function will check the (local) token manager first to see if there is a session, and if there is no local session, it will check the server for an active session, and set it in the (local) token manager if one exists.

authenticated().subscribe((tokens: CrdsTokens) => {
	if (tokens != null) {
		console.log('user logged in', tokens);
	} else {
		console.log('user is NOT logged in');
	}
}

function: signOut(): Observable<boolean>

Returns an observable that contains whether the signout action was successful or not.

signOut().subscribe(success  => {
	if (success) {
		console.log('log out worked')
	} else {
		console.log('log out failed')
	}
});

CrdsTokens


Interface and class for containing tokens.

{
	access_token:  any; // Both will have an access token
	id_token?:  any; // Optional as only Okta auth has id_token
	refresh_token?:  string; // Optional as only Mp auth has refresh token
	provider:  CrdsAuthenticationProviders; // Mp or Okta enum
}

Building

  • npm i
  • npm run build - this will run a build and will watch to rebuild when changes happen

Running the tests

  • npm run test

Deployment

CI/CD is set up through TeamCity Pull requests against the master branch will be built and tested automatically. Merges into master will be built and published to npm. To deploy to npm:

Run Locally

  • run npm link
  • in the local project consuming the this library, run npm link @crds_npm/crds-client-auth
  • this creates a symlink to the dist of the local library