fresh
डार्ट के लिए एक टोकन रीफ्रेश लाइब्रेरी। यह पैकेज विभिन्न रीफ्रेश टोकन वास्तुकला (आरएसटी, जीराफ़, आदि...) में सामान्य होने वाले मुख्य घटकों को उजागर करता है।
🍋 डार्ट के लिए एक टोकन रीफ्रेश लाइब्रेरी।
डार्ट के लिए एक टोकन रीफ्रेश लाइब्रेरी। यह पैकेज विभिन्न रीफ्रेश टोकन वास्तुकला (आरएसटी, जीराफ़, आदि...) में सामान्य होने वाले मुख्य घटकों को उजागर करता है।
टोकन रिफ्रेश के लिए HTTP इंटरसेप्टर। Fresh, package:dio पर आधारित है और प्रमाणीकरण टोकन को स्वचालित रूप से प्रबंधित करता है।
टोकन रिफ्रेश के लिए एक ग्राफ़फ़ी का लिंक। पैकेज:ग्राफ़फ़ी के ऊपर बनाया गया है और प्रमाणीकरण टोकन को स्वचालित रूप से प्रबंधित करता है।
एक स्वचालित रिफ्रेश करने वाला HTTP क्लाइंट। पैकेज: http पर आधारित है और प्रमाणीकरण टोकन को स्वचालित रूप से प्रबंधित करता है।
यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
build License: MIT GitHub stars
A collection of packages for automatic token refresh in Dart and Flutter. Fresh handles refreshing, caching, and attaching authentication tokens transparently so your API calls just work.
Token-based authentication seems simple until you handle the edge cases: tokens expire mid-session, multiple requests fail at the same time triggering duplicate refreshes, refresh tokens get revoked, and you need to route users to login when auth is lost. Fresh handles all of this so you don't have to.
| Package | Pub |
|---|---|
| fresh | pub package |
| fresh_dio | pub package |
| fresh_graphql | pub package |
| fresh_http | pub package |
authenticationStatus stream for reacting to login/logout eventsTokenStorage - bring your own persistence layerOAuth2Token with expiresAt supportfinal dio = Dio();
dio.interceptors.add(
Fresh.oAuth2(
tokenStorage: InMemoryTokenStorage<OAuth2Token>(),
refreshToken: (token, client) async {
final response = await client.post(
'https://api.example.com/auth/refresh',
data: {'refresh_token': token?.refreshToken},
);
return OAuth2Token(
accessToken: response.data['access_token'],
refreshToken: response.data['refresh_token'],
);
},
),
);
See the fresh_dio README for full documentation.
import 'dart:convert';
final freshLink = FreshLink.oAuth2(
tokenStorage: InMemoryTokenStorage<OAuth2Token>(),
refreshToken: (token, client) async {
final response = await client.post(
Uri.parse('https://api.example.com/auth/refresh'),
body: jsonEncode({'refresh_token': token?.refreshToken}),
);
final body = jsonDecode(response.body) as Map<String, dynamic>;
return OAuth2Token(
accessToken: body['access_token'],
refreshToken: body['refresh_token'],
);
},
shouldRefresh: (response) =>
response.errors?.any((e) => e.message.contains('UNAUTHENTICATED')) ?? false,
);
// HttpLink comes from package:gql_http_link
final link = Link.from([freshLink, HttpLink('https://api.example.com/graphql')]);
See the fresh_graphql README for full documentation.
import 'dart:convert';
final client = Fresh.oAuth2(
tokenStorage: InMemoryTokenStorage<OAuth2Token>(),
refreshToken: (token, client) async {
final response = await client.post(
Uri.parse('https://api.example.com/auth/refresh'),
body: jsonEncode({'refresh_token': token?.refreshToken}),
);
final body = jsonDecode(response.body) as Map<String, dynamic>;
return OAuth2Token(
accessToken: body['access_token'],
refreshToken: body['refresh_token'],
);
},
);
See the fresh_http README for full documentation.