request static method
Implementation
static Future<Result> request(String method, String uri,
[String? body]) async {
var url = Uri.parse(uri);
Map<String, String> headers = {
"x-authing-userpool-id": Authing.sUserPoolId,
"x-authing-app-id": Authing.sAppId,
"x-authing-request-from": "sdk-flutter",
"x-authing-sdk-version": Authing.VERSION,
"content-type": "application/json",
"x-authing-lang": Util.getLangHeader()
};
if (currentUser != null) {
if (currentUser!.mfaToken != null) {
headers.putIfAbsent(
"Authorization", () => "Bearer " + currentUser!.mfaToken!);
} else {
headers.putIfAbsent(
"Authorization", () => "Bearer " + currentUser!.token);
}
} else {
final prefs = await SharedPreferences.getInstance();
final token = prefs.getString(keyToken);
if (token != null) {
headers.putIfAbsent("Authorization", () => "Bearer " + token);
}
}
method = method.toLowerCase();
http.Response? response;
if (method == 'get') {
response = await http.get(url, headers: headers);
} else if (method == 'post') {
response = await http.post(url, headers: headers, body: body);
} else if (method == 'delete') {
response = await http.delete(url, headers: headers, body: body);
}
return parseResponse(response);
}