Name: redux-implicit-oauth2
Owner: University of Washington Clinical Informatics Research Group
Description: OAuth 2.0 Implicit Grant Flow with Redux
Forked from: danilobuerger/redux-implicit-oauth2
Created: 2018-02-21 17:13:30.0
Updated: 2018-02-21 17:13:32.0
Pushed: 2017-10-31 13:41:32.0
Size: 94
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
OAuth 2.0 Implicit Grant Flow with Redux.
The following example displays either a login or logout button depending on the state. Set the config object according to your OAuth 2.0 server parameters. The redirect callback page should be on the same site as the rest of your app.
rt React from 'react'
rt PropTypes from 'prop-types'
rt { connect } from 'react-redux'
rt { login, logout } from 'redux-implicit-oauth2'
t config = {
l: "https://example.com/authorize",
ient: "some_client_id",
direct: "https://example.com/callback.html",
ope: "some_scope",
dth: 400, // Width (in pixels) of login popup window. Optional, default: 400
ight: 400 // Height (in pixels) of login popup window. Optional, default: 400
t Login = ({ isLoggedIn, login, logout }) => {
(isLoggedIn) {
return <button type='button' onClick={logout}>Logout</button>
else {
return <button type='button' onClick={login}>Login</button>
n.propTypes = {
LoggedIn: PropTypes.bool.isRequired,
gin: PropTypes.func.isRequired,
gout: PropTypes.func.isRequired
t mapStateToProps = ({ auth }) => ({
LoggedIn: auth.isLoggedIn
t mapDispatchToProps = {
gin: () => login(config),
gout
rt default connect(mapStateToProps, mapDispatchToProps)(Login)
Don't forget to add the reducer and middleware to your Redux store:
rt { createStore, combineReducers, applyMiddleware } from 'redux'
rt { authMiddleware, authReducer as auth } from 'redux-implicit-oauth2'
t configureStore = (initialState) =>
eateStore(
combineReducers({
// other reducers
auth
}),
initialState,
applyMiddleware(
// other middleware
authMiddleware
)
rt default configureStore