refreshAuthenticationWithToken method

  1. @override
Future<MicrosoftAccount?> refreshAuthenticationWithToken(
  1. String refreshToken
)
override

Refreshes authentication using a specific refresh token and returns the Microsoft account profile

This method allows refreshing authentication for any Microsoft account by providing its refresh token, and returns the Microsoft account profile information.

@param refreshToken The Microsoft refresh token to use for the refresh operation @return A Future that resolves to the Microsoft account profile, or null if the refresh operation failed

Implementation

@override
Future<MicrosoftAccount?> refreshAuthenticationWithToken(
  String refreshToken,
) async {
  try {
    // Get Microsoft account profile with refreshed tokens
    final microsoftAccount = await _microsoftAuthService
        .refreshAccessTokenWithProfile(refreshToken);

    if (microsoftAccount == null || microsoftAccount.refreshToken.isEmpty) {
      return null;
    }

    // Update the cached refresh token
    _microsoftRefreshToken = microsoftAccount.refreshToken;

    // Get access token
    _accessToken = await _microsoftAuthService.refreshAccessToken(
      microsoftAccount.refreshToken,
    );
    if (_accessToken == null) {
      return null;
    }

    return microsoftAccount;
  } catch (e) {
    debugPrint('Failed to refresh authentication with token: $e');
    return null;
  }
}