Giter Club home page Giter Club logo

electron-oauth2's Introduction

A library to handle OAuth2 authentication for your Electron app.

Install

$ npm install --save electron-oauth

Usage

const electronOauth = require('electron-oauth');

var config = {
    clientId: 'CLIENT_ID',
    clientSecret: 'CLIENT_SECRET',
    authorizationUrl: 'AUTHORIZATION_URL',
    tokenUrl: 'TOKEN_URL',
    useBasicAuthorizationHeader: false,
    redirectUri: 'http://localhost'
};

app.on('ready', () => {
  const windowParams = {
    alwaysOnTop: true,
    autoHideMenuBar: true,
    webPreferences: {
        nodeIntegration: false
    }
  }

  const options = {
    scope: 'SCOPE',
    accessType: 'ACCESS_TYPE'
  };

  const myApiOauth = electronOauth(config, windowParams);

  myApiOauth.getAccessToken(options)
    .then(token => {
      // use your token.access_token

      myApiOauth.refreshToken(token.refresh_token)
        .then(newToken => {
          //use your new token
        });
    });
});

API

electronOauth(config, windowParams)

config

Type: Object

Fields
authorizationUrl

Type: String The URL for the authorization request.

tokenUrl

Type: String The URL for the access token request.

clientId

Type: String The OAuth2 client id.

clientSecret

Type: String The OAuth2 client secret.

useBasicAuthorizationHeader

Type: bool If set to true, token requests will be made using a Basic authentication header instead of passing the client id and secret in the body.

redirectUri (optional)

Type: String Sets a custom redirect_uri that can be required by some OAuth2 clients. Default: urn:ietf:wg:oauth:2.0:oob

windowParams

Type: Object

An object that will be used to create the BrowserWindow. Details: Electron BrowserWindow documention

Methods

getAccessToken(options)

Returns a Promise that gets resolved with the retrieved access token object if the authentication succeeds.

options: optional
scopes

Type: String The optional OAuth2 scopes.

accessType

Type: String The optional OAuth2 access type.

additionalTokenRequestData

Type: Object The optional additional parameters to pass to the server in the body of the token request.

getAuthorizationCode(options)

Returns a Promise that gets resolved with the authorization code of the OAuth2 authorization request.

options
scope

Type: String The optional OAuth2 scope.

accessType

Type: String The optional OAuth2 access type.

refreshToken(token)

Returns a Promise that gets resolved with the refreshed token object.

token

Type: String An OAuth2 refresh token.

License

MIT © [Vishal Isharani]

electron-oauth2's People

Contributors

hashtegner avatar hsar avatar ircnelson avatar javikr avatar jeffheifetz avatar johnf avatar jvitor83 avatar leviathan5 avatar mawie81 avatar program247365 avatar vishal-isharani avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

govi2010

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.