0.6.0 • Published 5 years ago

@zhevron/msal-redux v0.6.0

Weekly downloads
-
License
(MIT OR Apache-2....
Repository
github
Last release
5 years ago

MSAL for Redux applications

This package attempts to integrate the authentication flow from MSAL into Redux applications.

Installation

npm install @zhevron/msal-redux --save

Note: msal-redux requires redux and redux-saga as peer dependencies. Please install these in your project manually.

Usage

TypeScript

import { IMsalState, msalReducer, msalSaga } from "@zhevron/msal-redux";
import { applyMiddleware, combineReducers, compose, createStore } from "redux";
import createSagaMiddleware from "redux-saga";

const clientId = "<your app id>";
const authority = "https://login.microsoftonline.com/<your tenant id>";

interface IState {
    auth: IMsalState;
}
const reducer = combineReducers<IState>({
    auth: msalReducer
});

const sagaMiddleware = createSagaMiddleware();
const createStoreWithMiddleware = compose(
    applyMiddleware(sagaMiddleware),
)(createStore);
const store = createStoreWithMiddleware(reducer, {});

sagaMiddleware.run(msalSaga, clientId, authority, null);

JavaScript

import { msalReducer, msalSaga } from "@zhevron/msal-redux";
import { applyMiddleware, combineReducers, compose, createStore } from "redux";
import createSagaMiddleware from "redux-saga";

const clientId = "<your app id>";
const authority = "https://login.microsoftonline.com/<your tenant id>";

const reducer = combineReducers({
    auth: msalReducer
});

const sagaMiddleware = createSagaMiddleware();
const createStoreWithMiddleware = compose(
    applyMiddleware(sagaMiddleware),
)(createStore);
const store = createStoreWithMiddleware(reducer, {});

sagaMiddleware.run(msalSaga, clientId, authority, null);

Actions

All actions are constants exported from the main module.

Actions dispatched by the user

ConstantPayloadDescription
MSAL_SIGN_IN{ popup?: boolean; scopes?: string[] }Dispatch this action when you want to require a user to sign in to your application.
MSAL_SIGN_OUTNoneDispatch this action when you want a user to be signed out.

Actions dispatched by the library

ConstantPayloadDescription
MSAL_ACCESS_TOKEN_RECEIVED{ accessToken: string; scopes: string[]; user: User }Dispatched when the user is successfully signed in or the access token is refreshed.
MSAL_CALLBACK_PROCESSEDNoneDispatched after the callback from sign-in has been processed. Useful for removing the hash from the URL.
MSAL_SIGN_IN_FAILURE{ error: string }Dispatched if a sign-in fails.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

0.6.0

5 years ago

0.5.0

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

1.0.0

6 years ago