@zhevron/msal-redux
TypeScript icon, indicating that this package has built-in type declarations

0.6.0 • Public • Published

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

Constant Payload Description
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_OUT None Dispatch this action when you want a user to be signed out.

Actions dispatched by the library

Constant Payload Description
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_PROCESSED None Dispatched 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.

Readme

Keywords

none

Package Sidebar

Install

npm i @zhevron/msal-redux

Weekly Downloads

1

Version

0.6.0

License

(MIT OR Apache-2.0)

Unpacked Size

32.9 kB

Total Files

19

Last publish

Collaborators

  • zhevron