Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

piral-oauth2

Package Overview
Dependencies
Maintainers
1
Versions
815
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

piral-oauth2

Plugin to integrate OAuth 2.0 authentication in Piral.

  • 0.11.6-pre.1372
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
220
decreased by-37.5%
Maintainers
1
Weekly downloads
 
Created
Source

Piral Logo

Piral OAuth 2.0 · GitHub License npm version tested with jest Gitter Chat

This is a plugin that only has a peer dependency to piral-core. What piral-oauth2 brings to the table is a direct integration with OAuth 2.0 identity providers on basis of the client-oauth2 library that can be used with piral or piral-core.

The set includes the getAccessToken API to retrieve the current user's access token.

By default, these Pilet API extensions are not integrated in piral, so you'd need to add them to your Piral instance.

Documentation

The following functions are brought to the Pilet API.

getAccessToken()

Gets the currently authenticated user's token or undefined if no user is authenticated.

Usage

For authors of pilets

You can use the getAccessToken function from the Pilet API. This returns a promise.

Example use:

import { PiletApi } from '<name-of-piral-instance>';

export async function setup(piral: PiletApi) {
  const userToken = await piral.getAccessToken();
  // do something with userToken
}

Note that this value may change if the Piral instance supports an "on the fly" login (i.e., a login without redirect / reloading of the page).

Setup and Bootstrapping

For Piral instance developers

The provided library only brings API extensions for pilets to a Piral instance.

For the setup of the library itself you'll need to import createOAuth2Api from the piral-oauth2 package.

import { createOAuth2Api } from 'piral-oauth2';

The integration looks like:

import { createOAuth2Api, setupOAuth2Client } from 'piral-oauth2';

const client = setupOAuth2Client({ clientId, ... });

const instance = createInstance({
  // important part
  extendApi: [createOAuth2Api(client)],
  // ...
});

The separation into setupOAuth2Client and createOAuth2Api was done to simplify the standard usage.

Normally, you would want to have different modules here. As an example consider the following code:

// module oauth2.ts
import { setupOAuth2Client } from 'piral-oauth2';

export const client = setupOAuth2Client({ ... });

// app.ts
import { createOAuth2Api } from 'piral-oauth2';
import { client } from './oauth2';

export function render() {
  renderInstance({
    // ...
    extendApi: [createOAuth2Api(client)],
  });
}

// index.ts
import { client } from './oauth2';

if (location.pathname !== '/auth') {
  if (client.account()) {
    import('./app').then(({ render }) => render());
  } else {
    client.login();
  }
}

This way we evaluate the current path and act accordingly. Note that the actually used path may be different for your application.

License

Piral is released using the MIT license. For more information see the license file.

Keywords

FAQs

Package last updated on 03 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc