refreshTokens static method

Future<AzureTokenResponse?> refreshTokens({
  1. required String refreshToken,
  2. required String tenant,
  3. required String policy,
  4. required String clientId,
})

Refresh token: This method also returns a new refresh token AzureTokenResponse

Implementation

static Future<AzureTokenResponse?> refreshTokens({
  required String refreshToken,
  required String tenant,
  required String policy,
  required String clientId,
}) async {
  final uri = Uri.parse(
      "https://$tenant.b2clogin.com/$tenant.onmicrosoft.com/$policy/${Constants.userGetTokenUrlEnding}");

  final response = await http.post(uri, body: {
    'grant_type': Constants.refreshToken,
    'scope': Constants.defaultScopes,
    'client_id': clientId,
    'refresh_token': refreshToken,
  }, headers: {
    "Content-Type": _formUrlEncodedContentType
  });

  if (response.statusCode == 200 && response.body.isNotEmpty) {
    final body = jsonDecode(response.body);
    return AzureTokenResponse.fromJson(body);
  } else {
    return null;
  }
}