kopia lustrzana https://gitlab.com/mysocialportal/relatica
Add timeouts to sign in steps so doesn't block indefinitely
rodzic
747132625f
commit
10bba23d61
|
@ -2,11 +2,11 @@ import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter_web_auth_2/flutter_web_auth_2.dart';
|
import 'package:flutter_web_auth_2/flutter_web_auth_2.dart';
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:result_monad/result_monad.dart';
|
import 'package:result_monad/result_monad.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
|
import '../../utils/network_utils.dart';
|
||||||
import '../exec_error.dart';
|
import '../exec_error.dart';
|
||||||
import 'credentials_intf.dart';
|
import 'credentials_intf.dart';
|
||||||
|
|
||||||
|
@ -92,25 +92,22 @@ class OAuthCredentials implements ICredentials {
|
||||||
return Result.ok(true);
|
return Result.ok(true);
|
||||||
}
|
}
|
||||||
final idEndpoint = Uri.parse('https://$serverName/api/v1/apps');
|
final idEndpoint = Uri.parse('https://$serverName/api/v1/apps');
|
||||||
final response = await http.post(idEndpoint, body: {
|
final response = await postUrl(idEndpoint, {
|
||||||
'client_name': 'Relatica',
|
'client_name': 'Relatica',
|
||||||
'redirect_uris': redirectUrl,
|
'redirect_uris': redirectUrl,
|
||||||
'scopes': 'read write follow push',
|
'scopes': 'read write follow push',
|
||||||
'website': 'https://myportal.social',
|
'website': 'https://myportal.social',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
response.match(onSuccess: (body) {
|
||||||
_logger.severe('Error: ${response.statusCode}: ${response.body}');
|
final json = jsonDecode(body);
|
||||||
return buildErrorResult(
|
clientId = json['client_id'];
|
||||||
type: ErrorType.serverError,
|
clientSecret = json['client_secret'];
|
||||||
message: 'Error: ${response.statusCode}: ${response.body}',
|
}, onError: (error) {
|
||||||
);
|
_logger.severe('Error logging in: $error');
|
||||||
}
|
});
|
||||||
|
|
||||||
final json = jsonDecode(response.body);
|
return response.mapValue((_) => true);
|
||||||
clientId = json['client_id'];
|
|
||||||
clientSecret = json['client_secret'];
|
|
||||||
return Result.ok(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureResult<bool, ExecError> _login() async {
|
FutureResult<bool, ExecError> _login() async {
|
||||||
|
@ -146,15 +143,12 @@ class OAuthCredentials implements ICredentials {
|
||||||
'grant_type': 'authorization_code',
|
'grant_type': 'authorization_code',
|
||||||
'code': code,
|
'code': code,
|
||||||
};
|
};
|
||||||
final response = await http.post(url2, body: body);
|
final response = await postUrl(url2, body);
|
||||||
if (response.statusCode != 200) {
|
response.match(onSuccess: (body) {
|
||||||
_logger.severe('Error: ${response.statusCode}: ${response.body}');
|
accessToken = jsonDecode(body)['access_token'];
|
||||||
return buildErrorResult(
|
}, onError: (error) {
|
||||||
type: ErrorType.serverError,
|
_logger.severe('Error doing OAUth processing: $error');
|
||||||
message: 'Error: ${response.statusCode}: ${response.body}',
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
accessToken = jsonDecode(response.body)['access_token'];
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_logger.severe('Exception while Doing OAuth Process: $e');
|
_logger.severe('Exception while Doing OAuth Process: $e');
|
||||||
return buildErrorResult(
|
return buildErrorResult(
|
||||||
|
|
Ładowanie…
Reference in New Issue