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

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

example/main.dart

import 'package:fresh/fresh.dart';

class InMemoryTokenStorage implements TokenStorage<OAuth2Token> {
  OAuth2Token? _token;

  @override
  Future<void> delete() async {
    _token = null;
  }

  @override
  Future<OAuth2Token?> read() async {
    return _token;
  }

  @override
  Future<void> write(OAuth2Token token) async {
    _token = token;
  }
}

void main() {
  // Configure appropriate fresh client using `TokenStorage` implementation.
  // For example using [fresh_dio](https://pub.dev/packages/fresh_dio)...
  /// ```dart
  /// final dio = Dio()
  ///   ..interceptors.add(
  ///     Fresh<OAuth2Token>(
  ///       tokenStorage: InMemoryTokenStorage(),
  ///       refreshToken: (token, client) {
  ///         // Perform refresh and return new token
  ///       },
  ///     ),
  ///   );
  // ```
}
141
likes
160
pub points
80%
popularity

Publisher

verified publisherfelangel.dev

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

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

MIT (license)

More

Packages that depend on fresh