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

eve-oauth2-client

v1.0.0

Published

A client side only library to login using the oAuth2 EVE Online SSO

Downloads

7

Readme

eve-oauth2-client

This client-side module is able to handle the authentication process for the oAuth2 EVE Online login system, without the need of a backend.


Install

Register your application to https://developers.eveonline.com/ specifying the callback url of your application, and the scopes you'll ask for.
The page will provide you a "client ID" that will be needed for handling the authentication.

To install the module:

npm install --save eve-oauth2-client

Usage

Import the package:

import SsoProvider from 'eve-oauth2-client';

Login

The first step is creating the login button with the url that will allow to start the authentication process:

// Client ID of your application on developers.eveonline.com
let sso = new SsoProvider(clientID);

// The scopes needed by your application,
// for a complete list visit esi.evetech.net
let scopes = [
  'esi-location.read_location.v1',
  'esi-location.read_ship_type.v1',
  'esi-location.read_online.v1'
];

// url       - what your login button will link to.
// state     - a parameter you'll need to save and will be needed
//             when handling the callback.
// clearCode - another paramter to save needed for the callback.
let { url, state, clearCode } = sso.getLogin(callbackUrl, scopes);

// as an example, we can store the state and clearCode on localstorage
window.localStorage.setItem('state', state);
window.localStorage.setItem('clearCode', clearCode);

Callback

On your callback page you'll need to call the asyncronous handleCallback method of the sso instance, providing the current window url, and the previously saved state and clear code.

let sso = new SsoProvider(clientID);
let windowUrl = window.location.href;

// using localstorage as the previous example
let state = window.localStorage.getItem('state');
let clearCode = window.localStorage.getItem('clearCode');

let result = sso.handleCallback(windowUrl, state, clearCode);

If the authentication succeeded, the handleCallback method should return an object with the following properties:

  • accessToken
  • refreshToken
  • expiresIn - seconds left before the accessToken expiration
  • scopes - the array of previously requested scopes
  • owner
  • characterName
  • characterID
  • raw.token - the raw access token json received
  • raw.jwt - the raw decoded jwt json received
result
    .then(data => console.log(data.characterName))
    .catch(e => console.error(e));

// -> My Awesome Character Name

Refresh

When the access token will need to be refreshed, you can call the refresh method of the sso instance, providing the previous refresh token, the return object should have those properties:

  • accessToken
  • refreshToken
  • expiresIn
  • raw.token - the raw token json object
let sso = new SsoProvider(clientID);

sso.refresh(previouslySavedRefreshToken)
    .then(data => console.log(data.expiresIn))
    .catch(e => console.error(e));

// -> 1200