Git Product home page Git Product logo

eve-sso-pkce's Introduction

eve-sso-pkce

An Eve Online SSO library for browser that uses the PKCE method.

I created this project because I couldn't find an existing package. This library implements the OAuth 2.0 for Mobile or Desktop Applications for EVE Online SSO.

I use this package for authetnication in browser-only SPAs, where it is not possible to keep the Secret Key a secret.

Docs

Auto-generated documentation is available

Examples

This package provides the API to manage the authetnication workflow with EVE Online SSO. It is the implementor's responsibility to manage the clients part of the workflow. Here is an example of how to use this package:

  1. import and create the EveAuthSSO object. The clientId and redirectUri are accessible from the developer portal
import { createSSO } from 'eve-sso-pkce'
const sso = createSSO({
  clientId: 'MY-CLIENT-ID',
  redirectUri: 'https://my.callback.uri/path'
})
  1. get the auth URI and redirect the client there
// get the uri for the required scopes
const ssoUri = await sso.getUri(['esi-location.read_location.v1')

// redirect the browser to the uri
window.location.assign(ssoUri.uri)
  1. listen for the response on the callback uri and then get the access token
// get the response from the auth server. I use Vue Router to redirect to a component
import { useRoute } from 'vue-router'
const route = useRoute()

// get the query parameters
const state = route.query.state?.toString()
const code = route.query.code?.toString() 

// check the state is right
if(ssoUri.state !== state) {
  throw new Error('state should match')
}

// request the access token
const token = await sso.getAccessToken(code, ssoUri.codeVerifier)

// You can then use token.accessToken for esi service calls (sold seperately! :lol: )
  1. refresh token when required
// get a new access token when the last one expired
const newToken = await sso.refreshToken(token.refreshToken)
  1. revoke the token - best to do when the user logs out
sso.revokeRefreshToken(newToken.refreshToken)

eve-sso-pkce's People

Contributors

ballsten avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.