getAllTokens method

Future<AzureTokenResponse?> getAllTokens({
  1. required String redirectUri,
  2. required String clientId,
  3. required String authCode,
  4. required String providedScopes,
  5. required String userFlowName,
  6. required String tenantBaseUrl,
  7. String grantType = Constants.defaultGrantType,
})

Get Access, Id and refresh token, check its response: AzureTokenResponse

Implementation

Future<AzureTokenResponse?> getAllTokens({
  required String redirectUri,
  required String clientId,
  required String authCode,
  required String providedScopes,
  required String userFlowName,
  required String tenantBaseUrl,
  String grantType = Constants.defaultGrantType,
}) async {
  final uri = Uri.parse(
      "$tenantBaseUrl/$userFlowName/${Constants.userGetTokenUrlEnding}");
  final response = await http.post(uri, body: {
    'scope': providedScopes,
    'grant_type': grantType,
    'code': authCode,
    'client_id': clientId,
    'code_verifier': pkcePair.codeVerifier,
    'redirect_uri': redirectUri,
  }, headers: {
    "Content-Type": _formUrlEncodedContentType
  });

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