redux-refresh-token
redux-refresh-token copied to clipboard
How to pass a custom body on token refresh request
Hello!
I have a question about usage this module. My authentication API is using OAuth 2.0 protocol and to refresh a token I need pass some key/value params on the body.
Example:
{
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"grant_type": "refresh_token",
"refresh_token": "A_VERY_BIG_STRING"
}
Code example:
export const attemptTokenRefresh = () => {
return async (dispatch, getState) => {
const state = getState();
dispatch({
[CALL_API]: {
endpoint: '/auth/oauth2_token',
method: 'POST',
body: {
client_id: CLIENT_ID,
client_secret: CLIENT_SECRET,
grant_type: 'refresh_token',
refresh_token: state.auth.refresh_token
},
types: [
ActionTypes.TOKEN_REFRESH_REQUEST,
ActionTypes.TOKEN_REFRESH_SUCCESS,
ActionTypes.TOKEN_REFRESH_FAILURE
]
}
});
};
};
I'm passing this parameters at the attemptTokenRefresh action, but I don't know if it's the best way to do that. What you think?