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

@girder/oauth-client

v0.8.0

Published

A TypeScript library for performing OAuth login to a Girder 4 (Django) server.

Downloads

137

Readme

girder-oauth-client

npm (scoped)

A TypeScript library for performing OAuth login to a Girder 4 (Django) server.

Description

This provides support for authenticating with Girder 4 servers, using the OAuth2.0 Authorization Code Grant with PKCE flow.

Usage

  • Install the library:

    yarn add @girder/oauth-client

    or if you're using npm:

    npm install @girder/oauth-client
  • Instantiate an OauthClient with your application-specific configuration:

    import OauthClient from '@girder/oauth-client';
    
    const oauthClient = new OauthClient(
      new URL(process.env.OAUTH_API_ROOT), // e.g. 'http://localhost:8000/oauth/'
      process.env.OAUTH_CLIENT_ID, // e.g. 'Qir0Aq7AKIsAkMDLQe9MEfORbHEBKsViNhAKJf1A'
    );
  • Call redirectToLogin when it's time to start a login flow:

    document.querySelector('#sign-in-link').addEventListener('click', (event) => {
      event.preventDefault();
      oauthClient.redirectToLogin();
      // This will redirect away from the current page
    });
  • At the start of every page load, unconditionally call maybeRestoreLogin, to attempt to restore a login state; this will no-op if no login is present. Afterwards, get and store HTTP headers for authentication from authHeaders.

    let authHeaders;
    oauthClient.maybeRestoreLogin()
      .then(() => {
        authHeaders = oauthClient.authHeaders;
      });

    or, if using ES6 and async/await:

    await oauthClient.maybeRestoreLogin();
    let { authHeaders } = client;
  • Include these headers with every Ajax API request:

    fetch('http://localhost:8000/api/files', {
      headers: authHeaders,
    });
  • The login state will persist across page refreshes. Call logout to clear any active login:

    document.querySelector('#sign-out-link').addEventListener('click', (event) => {
      event.preventDefault();
      oauthClient.logout()
        .then(() => {
          authHeaders = oauthClient.authHeaders;
        });
    });

Example app

This repository comes bundled with an example application. Run it with:

git clone https://github.com/girder/girder-oauth-client.git
yarn install
yarn build
cd example
yarn install
yarn serve
# Visit http://localhost:1234/

Development

To develop the library using the example app:

# From the root of the repository
yarn link
yarn install
yarn watch

In another terminal:

# From the root of the repository
cd example
yarn link '@girder/oauth-client'
yarn install
yarn serve