-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Jiří Čermák edited this page Jun 2, 2022
·
4 revisions
The library handles authentication logic with token based flow.
- automatically refresh access token before it expires
- persisting tokens state in local or session storage (optional)
- automatically fetching an authorized user after successful tokens retrieval from a persistent storage
- simple API for auth state management:
getAuthStateChannel
,withAuthSession
-
authorizable
HOC - render content (a firewall, an authorized content or a loader) based on current auth. state
The library relies on
react
,redux
,react-redux
,redux-saga
andreselect
packages as peer dependencies.
Using yarn:
$ yarn add @ackee/petrus
Using npm:
$ npm i -S @ackee/petrus
import { configure } from '@ackee/petrus';
// 1. Provide authenticate, refreshTokens and getAuthUser methods
const { saga, reducer } = configure({
handlers: {
authenticate,
refreshTokens,
getAuthUser,
},
});
// 2. Add auth reducer
const rootReducer = combineReducers({
auth: reducer
});
// 3. And launch the saga
function*() {
yield all([saga()])
}
To see defaults and available configurations with examples, go here.
Usage with @ackee/antonio
@ackee/petrus
supports following OAuth2 flows:
-
Implicit grant flow
- Matches with the default configuration.
-
origin
property is required
-
Web application flow
- Additionally to the Implicit grant flow, you have to provide the
fetchAccessToken
method.
- Additionally to the Implicit grant flow, you have to provide the
See how to setup @ackee/petrus
for these flows here.