shoutem / fetch-token-intercept Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
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!
Hi,
here's whats happening:
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'));
`
Does this project still have an active maintainer? @dodsky ?
I wonder if I can use this library on React Native.
Great job…! It is very fine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.