API Documentation ----------------- The documentation for the SwiftyRx can be found at https://acme.swiftyrx.dev/api/ui/ Client Installation ------------------- The clients are not yet published to pub.dev. They will be soon. Example Usage ------------- Authorization ~~~~~~~~~~~~~ .. code-block:: dart :linenos: :caption: custom_auth_manager.dart import 'dart:async'; import 'package:dio/dio.dart'; import 'package:swifty/swifty_oauth_client/api.dart'; import 'package:swifty/swifty_oauth_client/model/token_response.dart'; import 'package:swifty/swifty_oauth_client/model/user_info_response.dart'; import 'package:swifty/utils/api_helpers.dart' if (dart.library.js_interop) 'package:swifty/utils/api_helpers_web.dart'; import '../../swifty_oauth_client/model/get_token_request.dart'; import 'custom_auth_user_provider.dart'; export 'custom_auth_manager.dart'; extension on Response? { get meta => AuthenticatedMeta.fromJson(this?.data['meta'] as Map); } class CustomAuthManager { // Auth session attributes TokenResponse? tokenResponse; UserInfoResponse? userInfoResponse; DateTime? tokenExpiration; Future signOut() async { tokenResponse = null; userInfoResponse = null; } Future signIn(String username, String password, BuildContext context) async { Dio dio = OAuthDioService().dio; final api = Swifty(dio: dio).getOAuthApi(); SwiftyAuthUser authUser = SwiftyAuthUser(loggedIn: false); try { await api.getToken(getTokenRequest: GetTokenRequest(grantType: "password", username: username, password: password)).then((response) { tokenResponse = response.data; tokenExpiration = DateTime.now().add(Duration(seconds: tokenResponse?.expiresIn ?? 300)); if (!kIsWeb) { saveStringPreference("accessToken", tokenResponse?.accessToken ?? ''); saveStringPreference("refreshToken", tokenResponse?.refreshToken ?? ''); } }).onError((error, stackTrace) { if (kDebugMode) { debugPrint("Error when calling /oauth/token: $error"); } throw error ?? "Unknown error"; }); if (tokenResponse != null) { await api.getUserInfo(headers: {"Authorization": "Bearer ${tokenResponse?.accessToken}"}).then((response) { userInfoResponse = response.data; authUser = SwiftyAuthUser(loggedIn: true, tokenResponse: tokenResponse, userInfo: userInfoResponse); if (!context.mounted) { return; } Provider.of(context, listen: false).setUserInfo(userInfoResponse!); }).onError((error, stackTrace) { if (kDebugMode) { debugPrint("Error when calling /oath/userinfo: $error"); } throw error ?? "Unknown error"; }); } } on DioException catch (e) { if (kDebugMode) { debugPrint("Exception when calling OAuth API: $e"); } } finally {} return authUser; } } Full Example ~~~~~~~~~~~~ A more complete example of using the Dart SDK is forthcoming.