refreshIDToken method

Future<void> refreshIDToken()

Implementation

Future<void> refreshIDToken() async {
  if (shouldRefreshAccessToken) {
    await refreshAccessToken();
  }

  String? deviceSecret = await _sharedStorage.getDeviceSecret(name);

  final tokenRequest = OIDCTokenRequest(
    grantType: GrantType.idToken,
    clientID: clientID,
    accessToken: accessToken,
    deviceSecret: deviceSecret,
  );

  try {
    final tokenResponse = await _apiClient.sendTokenRequest(tokenRequest,
        includeAccessToken: true);
    final idToken = tokenResponse.idToken;
    if (idToken != null) {
      _idToken = idToken;
      await _sharedStorage.setIDToken(name, idToken);
    }

    final deviceSecret = tokenResponse.deviceSecret;
    if (deviceSecret != null) {
      await _sharedStorage.setDeviceSecret(name, deviceSecret);
    }
  } catch (e) {
    _handleInvalidGrantException(e);
    rethrow;
  }
}