oauth2_refresher 1.0.0 copy "oauth2_refresher: ^1.0.0" to clipboard
oauth2_refresher: ^1.0.0 copied to clipboard

A Dart library for managing OAuth2 token refreshing with easy integration and support for Dio and JWT decoding.

example/lib/main.dart

import 'package:oauth2_refresher/oauth2_refresher.dart';
import 'dart:async';

import 'repository/auth_repository.dart';


Future<void> main() async {
  /// Log in user
  final res = await AuthRepository.logIn(
    login: 'login',
    password: 'password',
  );
  await res.fold((left) async {
    /// Do something with error
  }, (right) async {
    /// add tokens to the handler
    await TokenHandler().saveTokens(
      authToken: right.accessToken,
      refreshToken: right.refreshToken,
    );
  });

  /// and use multiple jre single requests
  final results = await Future.wait([
    AuthRepository.example(),
    AuthRepository.example(),
    AuthRepository.example(),
  ]);

  for (var i = 0; i < results.length; i++) {
    results[i].fold(
          (error) => print('Request ${i + 1} failed: $error'),
          (_) => print('Request ${i + 1} succeeded'),
    );
  }
}
1
likes
0
points
34
downloads

Publisher

verified publisherdart-weider.top

Weekly Downloads

A Dart library for managing OAuth2 token refreshing with easy integration and support for Dio and JWT decoding.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio, jwt_decoder, shared_preferences

More

Packages that depend on oauth2_refresher