GithubHelp home page GithubHelp logo

mattmazzola / react-simple-auth Goto Github PK

View Code? Open in Web Editor NEW
56.0 5.0 15.0 232 KB

Authentication library for React based on Ember-Simple-Auth

License: MIT License

TypeScript 95.44% HTML 4.56%
react typescript authentication oauth2 openid-connect

react-simple-auth's Introduction

React-Simple-Auth

styled with prettier Greenkeeper badge Travis Coveralls Dev Dependencies Donate

Simple Authentication for React

Resources

Technical Docs:
https://mattmazzola.github.io/react-simple-auth/

Getting started

Installation

npm i react-simple-auth

Copy file from /node_modules/react-simple-auth/dist/redirect.html into folder that will service static files. E.g. If you are using create-react-app this will be the public folder. Ensure your OAuth provider is configured to redirect to this html page instead of your normal application / index page.

Create a provider

You would have to look at each OAuth provider's developer documentation for details.

Create a javascript object implementing the IProvider interface.

See the sample for Microsoft AAD v2 OpenID-Connect from the sample project:
https://github.com/mattmazzola/react-simple-auth-sample/blob/master/src/providers/microsoft.ts

Based on these docs:
https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols

Call the various methods from the auth service

Import:

import RSA from 'react-simple-auth'
import facebookProvider from './providers/facebook'

Somewhere inside the component:

// Open login window and wait for user to sign in
const session = await RSA.acquireTokenAsync(facebookProvider)

// Invoke Redux login action dispatcher
login(session.userId, session.userName)

react-simple-auth's People

Contributors

mattmazzola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-simple-auth's Issues

facebook changes window.name

I checked how it works and found that the script uses window.name as requestKey to communicate via local
storage to set url in it.
There is an issue with login with facebook in case you are not logged in.
Facebook changes window.name on load the page so once you logged in it redirects you to redirect url but it has already different window.name and we set wrong item.
I suggest to use window.opener to communicate between windows.
As a workaround I update url in window.opener, close the window and then update session key in localStorage with url and just get access token without async

Support Authorization Code Grant

Thanks for the great work. I have a Feature Request - I don't think it would take too much to support Authorization Code Grant with a Public Client (no client secret). This seems to be recommended more these days over implicit for Single Page Apps. Also, it would give the opportunity to implement a refresh token. Thanks

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.