-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Hi,
here's whats happening:
- Calls my API (fails with 401)
- Calls the refresh token api (success with new token)
- Calls my API again (fails because no new auth token sent)
I have enabled "authorizeRequest" - same as the example on medium.com
here's my config:
let config = { // (Required) Prepare fetch request for renewing new access token createAccessTokenRequest: (refreshToken) => { let refrehfd = new FormData(); refrehfd.append("refresh", refreshToken) return new Request(${DJ_API_URL}/project/refresh`, {
method: 'POST',
body:refrehfd
})
},
// (Required) Parses access token from access token response
parseAccessToken: (json) => {
return json.json().then(json => json.access)
.then(json => console.log("access",json.access))
.then(json => localStorage.setItem("access",json.access));
},
// (Required) Defines whether interceptor will intercept this request or just let it pass through
shouldIntercept: (request) => true,
// (Required) Defines whether access token will be invalidated after this response
shouldInvalidateAccessToken: (response) => true,
// When set, response which invalidates token will be resolved after the token has been renewed
// in effect, token will be loaded in sync with response, otherwise renew will run async to response
shouldWaitForTokenRenewal: true,
// Checks if response should be considered unauthorized (by default only 401 responses are
// considered unauthorized). Override this method if you need to trigger token renewal for
// other response statuses. Check API reference for helper method which defines default behaviour
isResponseUnauthorized: (response) => true,
// (Required) Adds authorization for intercepted requests
authorizeRequest: (request, access) => {
request.headers.set('Authorization', Bearer ${access});
return request;
},
// Number of retries after initial request was unauthorized
fetchRetryCount: 1,
// Event invoked when access token has changed
onAccessTokenChange: null,
// Event invoked when response is resolved
onResponse: null,
}
configure(config);
// here you provide tokens obtained from your Authorization Server
authorize(localStorage.getItem('refresh'), localStorage.getItem('access'));
`