Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

zhevron/msal-redux

Repository files navigation

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.

About

MSAL for Redux applications.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published