Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not sending auth when it calls the second time. #13

Open
ghost opened this issue May 7, 2020 · 0 comments
Open

not sending auth when it calls the second time. #13

ghost opened this issue May 7, 2020 · 0 comments

Comments

@ghost
Copy link

ghost commented May 7, 2020

Hi,

here's whats happening:

  1. Calls my API (fails with 401)
  2. Calls the refresh token api (success with new token)
  3. 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'));
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants