GithubHelp home page GithubHelp logo

fetch-token-intercept's People

Contributors

definitely-not-vlad avatar dodsky avatar vedrani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fetch-token-intercept's Issues

Store new refresh token in addition to access token

Not all OAuth 2.0 implementations use a single, long-running refresh token or omit a new refresh token from the refresh grant response.

So, this is a placeholder for a feature to (optionally) set a new refresh token in addition to the new access token.

Thanks for a great project, it's saved me a lot of time!

not sending auth when it calls the second time.

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'));
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.