Comments (2)
Can you share some sample code or a reproduction sample? I'm not sure I fully understand the problem you're facing, thanks!
from fresh.
class TranslateApiClient {
TranslateApiClient({Dio? httpClient})
: _httpClient = (httpClient ?? Dio())
..options.baseUrl = baseUrl
..interceptors.add(_fresh)
..interceptors.add(
LogInterceptor(),
)
..options.followRedirects=false
..options.validateStatus=((status) => status != null && status <= 505);
final Dio _httpClient;
static final _fresh = Fresh.oAuth2(
tokenHeader: (token){
if (token.accessToken == '') {
return {};
}
return {
'Authorization': '${token.tokenType} ${token.accessToken}',
};
},
tokenStorage: CacheTokenMemory(),
refreshToken: (token, client) async {
client.options.headers.addAll(
{
'Authorization': '${token?.tokenType} ${token?.refreshToken}',
},
);
try {
final response = await client.post<dynamic>('/auth/refresh',);
if(response.statusCode != 201 || response.statusCode != 200){
throw RevokeTokenException();
}
final data = response.data as Map<String, dynamic>;
final accessToken = data['access_token'].toString();
final refreshToken = data['refresh_token'].toString();
return OAuth2Token(
accessToken: accessToken,
refreshToken: refreshToken,
);
} on DioError catch(err){
print(err.message);
}
return const OAuth2Token(
accessToken: '',
);
},
);
}
from fresh.
Related Issues (20)
- Auto retry after refresh token? HOT 1
- Request new Feature
- Update example code
- refreshToken not called at all? HOT 1
- Replace graphql dependency with gql_link HOT 3
- not enough examples HOT 2
- token returns null when awaited right after initializing HOT 1
- Move to QueuedInterceptor in Dio
- can't figure out how to use package!
- Updated package to use dio 5.0.0 HOT 7
- [fresh_graphql] shouldRefresh example needed HOT 2
- [fresh_graphql] wrong auth status HOT 1
- [fresh_graphql] wrong Bearer case
- [fresh_grahpql] Multiple request HOT 4
- [fresh_graphql] update http to 1.0.0 HOT 1
- Fresh causes requests to never complete
- [fresh_dio] Recommended way to log refresh and retry requests HOT 1
- How to test fresh_dio with a Mock HttpClientAdapter?
- [ Concurrent API calls ]
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fresh.