GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Searching for packages
  • Package scoring and pub points
  • Using packages
  • Developing packages and plugins
  • Publishing a package
  • Using packages

This view

  • Original page
  • New address

GeezerVison is showing pub.dev — fresh | Dart package

fresh 0.7.0 copy "fresh: ^0.7.0" to clipboard
fresh: ^0.7.0 copied to clipboard

Published 17 days ago • verified publisherfelangel.dev
SDKDartFlutter
PlatformAndroidiOSLinuxmacOSwebWindows
157
→

Metadata

An token refresh library for dart. This package exposes the core components that are common to various refresh token implementations (REST, GraphQL, etc...).

More...

  • Readme
  • Changelog
  • Example
  • Installing
  • Versions
  • Scores

fresh 🍋 #

Pub build coverage License: MIT GitHub stars


An token refresh library for dart. This package exposes the core components that are common to various refresh token implementations (REST, GraphQL, etc...).

Most users should use one of the integration packages instead:

Package For
fresh_dio dio HTTP client
fresh_graphql gql_link GraphQL
fresh_http http HTTP client

Use package:fresh directly only if you are building a custom integration.

What's Included #

  • FreshMixin<T> - Mixin providing token lifecycle management and single-flight refresh coordination
  • TokenStorage<T> - Interface for reading, writing, and deleting tokens
  • InMemoryTokenStorage<T> - Simple in-memory storage implementation
  • Token / OAuth2Token - Base token class and standard OAuth2 token with expiresAt support
  • AuthenticationStatus - Stream-based auth state (initial, authenticated, unauthenticated)
  • RevokeTokenException - Throw from performTokenRefresh to clear the token and signal logout

Building a Custom Integration #

Implement performTokenRefresh on a class using FreshMixin:

class MyHttpFresh extends MyHttpClient with FreshMixin<OAuth2Token> {
  MyHttpFresh({required TokenStorage<OAuth2Token> tokenStorage}) {
    this.tokenStorage = tokenStorage;
  }

  @override
  Future<OAuth2Token> performTokenRefresh(OAuth2Token? token) async {
    final response = await post('/auth/refresh', body: {'refresh_token': token?.refreshToken});
    return OAuth2Token(
      accessToken: response['access_token'],
      refreshToken: response['refresh_token'],
    );
  }

  Future<Response> authenticatedRequest(String path) async {
    var currentToken = await token;

    final response = await get(path, headers: {'Authorization': 'Bearer ${currentToken?.accessToken}'});

    if (response.statusCode == 401) {
      final refreshed = await refreshToken(tokenUsedForRequest: currentToken);
      return get(path, headers: {'Authorization': 'Bearer ${refreshed.accessToken}'});
    }

    return response;
  }
}

refreshToken() handles deduplication automatically - concurrent calls share a single in-flight refresh.

157
likes
160
points
96.2k
downloads

Documentation

API reference

Publisher

verified publisherfelangel.dev

Weekly Downloads

Metadata

An token refresh library for dart. This package exposes the core components that are common to various refresh token implementations (REST, GraphQL, etc...).

Repository (GitHub)
View/report issues

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

meta

More

Packages that depend on fresh

← Metadata

157
likes
160
points
96.2k
downloads

Documentation

API reference

Publisher

verified publisherfelangel.dev

Weekly Downloads

Metadata

An token refresh library for dart. This package exposes the core components that are common to various refresh token implementations (REST, GraphQL, etc...).

Repository (GitHub)
View/report issues

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

meta

More

Packages that depend on fresh

Back

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.