getAccessToken method

  1. @override
Future<String> getAccessToken()
override

获取 accessToken

Implementation

@override
Future<String> getAccessToken() async {
  /// 如果正在刷新token,则等待
  if (AuthProvider._refreshAccessTokenFuture != null) {
    await AuthProvider._refreshAccessTokenFuture;
  }

  final String? accessToken = await cache.getStore(cache.accessTokenKey);
  final int? accessTokenExpired =
      await cache.getStore(cache.accessTokenExpireKey);

  if (accessToken != null &&
      accessTokenExpired != null &&
      accessTokenExpired > DateTime.now().millisecondsSinceEpoch) {
    return accessToken;
  }

  /// 如果accessToken无效,则刷新
  await refreshAccessToken();

  return await cache.getStore(cache.accessTokenKey);
}