Giter Site home page Giter Site logo

inoicouldalwaysturn2u / oauth2-redux-implicit-authcode Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 228 KB

OAuth 2 Redux focused Implicit and Authorization Code grant type library.

JavaScript 100.00%
oauth2 oauth2-authentication implicit-flow authorization-code-grant redux redux-middleware react serverless

oauth2-redux-implicit-authcode's Introduction

ReadMe

Front-end (mostly) library for OAuth 2 implicit granting. Also can handle authorization code however it requires your own intermediary endpoint. It is described below.

TODO: Refresh token

Uses Redux and redux-promise-middleware. To have it set up with your Redux store, first include combinedOauthReducerHash function with service name argument as a reducer. Then for configuring the store, import combinedOauthStateHash helper function for the initial states which come from Local Storage. Include the oauth2Middleware middleware. Include redux-promise-middleware. Example code:

// Reducer File
import { combinedOauthReducerHash } from 'oauth2-redux';
export default rootReducer = combineReducers( {
  ...combinedOauthReducerHash( 'serviceOne' ), 
  ...combinedOauthReducerHash( 'serviceTwo' ) 
} );
// Configure Store file
import promise from 'redux-promise-middleware';
import { oauth2Middleware, combinedOauthStateHash } from 'oauth2-redux';
const middlewares = [ promise, oauth2Middleware ];
const initialState = {
  ...combinedOauthStateHash( 'serviceOne' ), 
  ...combinedOauthStateHash( 'serviceTwo' ) 
};

// Pass initialState as second argument to createStore.
// Pass middlewares as third, last argument with applyMiddlewares

There's a barebones React component example using the library and the calling of the React component in the examples folder.

Authorization Code

This requires your own endpoint. Have to send the second step url with the code to get an access token as a POST request to a url defined in config as "backend_url". Example serverless code is at https://github.com/inoicouldalwaysturn2u/netlify-express, specifically https://github.com/inoicouldalwaysturn2u/netlify-express/blob/master/express/server.js. The specific endpoint code is as follows and cors is used as well:

router.post( '/auth-code', ( req, res ) => {
  Axios.post( req.body.url )
    .then( response => {
      res.json( { status: response.status, ...response.data } ) 
    } )
} );

You can use the given default endpoint of https://atsexpress.atextbooksituation.com/.netlify/functions/server/auth-code or use the code of the forked netlify-express at https://github.com/inoicouldalwaysturn2u/netlify-express. It has a deploy to Netlify button for convenience that is below as well.

oauth2-redux-implicit-authcode's People

Contributors

ssaadh avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.