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

studiokit-auth-js

v3.0.2

Published

Authentication flow for Studio apps at Purdue

Downloads

50

Readme

studiokit-auth-js

Coverage Status

studiokit-auth-js is an expansion on the studiokit-net-js library, adding authentication methods.

  1. Installation
  2. Usage
  3. Development

Installation

Install this library and redux-saga as a dependency

  1. yarn add studiokit-auth-js
  2. Follow the setup instructions from studiokit-net-js
  3. Add the authReducer into your reducers.js module
    import { combineReducers } from 'redux'
    import { reducers as authReducers } from 'studiokit-auth-js'
    
    export default combineReducers({
    	auth: authReducers.authReducer
    })
  4. Create services for tokenPersistenceService, ticketProviderService, and codeProviderService. The defaults do not return any results, but your services should most likely target AsyncStorage or LocalStorage and the window.location.search property. See src/services.ts for reference.
  5. Update your rootSaga module to add authSaga with your OAuth client credentials and services, merge your app's endpointMappings with authEndpointMappings, and pass getOAuthToken into fetchSaga.
    import { all } from 'redux-saga/effects'
    import { sagas as netSagas } from 'studiokit-net-js'
    import {
    	sagas as authSagas,
    	endpointMappings as authEndpointMappings,
    	getOAuthToken,
    	AUTH_ACTION
    } from 'studiokit-auth-js'
    import endpointMappings from 'endpointMappings'
    
    export default function* rootSaga() {
    	yield all({
    		fetchSaga: netSagas.fetchSaga(
    			_.merge(authEndpointMappings, endpointMappings),
    			'https://yourapp.com',
    			getOAuthToken
    		),
    		loginFlow: authSagas.authSaga(
    			{
    				client_id: 'id',
    				client_secret: 'secret'
    			},
    			tokenPersistenceService,
    			ticketProviderService,
    			codeProviderService
    		)
    	})
    }

Usage

Providers

Once you have the above steps completed, auth will be enabled. The ticketProviderService and codeProviderService should will used to handle auth redirects containing code or ticket query params.

Store

Once the auth is completed, it will live in the redux store at the auth key, i.e.

auth: {
	isInitialized: false,
	isAuthenticating: false,
	isAuthenticated: false,
	didFail: false
}

Initialization

The AUTH_INITIALIZED signal is sent when the authSaga has completed initialization and handled one of the following cases:

  1. Loaded a saved token using the tokenPersistenceService
  2. Exchanged a ticket for a token
  3. Exchanged a code for a token
  4. Initialized without a token, ready for an auth action to trigger

At the time of initialization, use the value in redux at auth.isAuthenticated to determine if a token was loaded or exchanged.

Manual Login

Alternately, you can dispatch manual auth actions to the store for login forms.

import { dispatchAction } from 'services/actionService'
import { AUTH_ACTION } from 'studiokit-auth-js'
.
.
.
dispatchAction(AUTH_ACTION.LOCAL_LOGIN_REQUESTED, {
	payload: {
		Username: 'joe',
		Password: 'joeRocks1!'
	}
})

Development

During development of this library, you can clone this project and use

yarn link

to make the module available to another project's node_modules on the same computer without having to publish to a repo and pull to the other project. In the other folder, you can use

yarn link studiokit-auth-js

to add studiokit-auth-js to the consuming project's node_modules

Build

Because this is a module, the source has to be transpiled to ES5 since the consuming project won't transpile anything in node_modules

yarn build

will transpile everything in /src to /lib. /lib/index.js is the entry point indicated in package.json

During development, you can run

yarn build:watch

and babel will rebuild the /lib folder when any file in /src changes.

When you commit, a commit hook will automatically regenerate /lib

Deploy

This packaged is deployed via the npm repository. Until we add commit hooks for deployment, it must be published via yarn publish