mirror of
https://gitlab.com/mysocialportal/relatica
synced 2024-10-18 12:23:31 +00:00
Add timeouts to sign in steps so doesn't block indefinitely
This commit is contained in:
parent
747132625f
commit
10bba23d61
1 changed files with 16 additions and 22 deletions
|
@ -2,11 +2,11 @@ import 'dart:convert';
|
|||
import 'dart:io';
|
||||
|
||||
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:result_monad/result_monad.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../../utils/network_utils.dart';
|
||||
import '../exec_error.dart';
|
||||
import 'credentials_intf.dart';
|
||||
|
||||
|
@ -92,25 +92,22 @@ class OAuthCredentials implements ICredentials {
|
|||
return Result.ok(true);
|
||||
}
|
||||
final idEndpoint = Uri.parse('https://$serverName/api/v1/apps');
|
||||
final response = await http.post(idEndpoint, body: {
|
||||
final response = await postUrl(idEndpoint, {
|
||||
'client_name': 'Relatica',
|
||||
'redirect_uris': redirectUrl,
|
||||
'scopes': 'read write follow push',
|
||||
'website': 'https://myportal.social',
|
||||
});
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
_logger.severe('Error: ${response.statusCode}: ${response.body}');
|
||||
return buildErrorResult(
|
||||
type: ErrorType.serverError,
|
||||
message: 'Error: ${response.statusCode}: ${response.body}',
|
||||
);
|
||||
}
|
||||
response.match(onSuccess: (body) {
|
||||
final json = jsonDecode(body);
|
||||
clientId = json['client_id'];
|
||||
clientSecret = json['client_secret'];
|
||||
}, onError: (error) {
|
||||
_logger.severe('Error logging in: $error');
|
||||
});
|
||||
|
||||
final json = jsonDecode(response.body);
|
||||
clientId = json['client_id'];
|
||||
clientSecret = json['client_secret'];
|
||||
return Result.ok(true);
|
||||
return response.mapValue((_) => true);
|
||||
}
|
||||
|
||||
FutureResult<bool, ExecError> _login() async {
|
||||
|
@ -146,15 +143,12 @@ class OAuthCredentials implements ICredentials {
|
|||
'grant_type': 'authorization_code',
|
||||
'code': code,
|
||||
};
|
||||
final response = await http.post(url2, body: body);
|
||||
if (response.statusCode != 200) {
|
||||
_logger.severe('Error: ${response.statusCode}: ${response.body}');
|
||||
return buildErrorResult(
|
||||
type: ErrorType.serverError,
|
||||
message: 'Error: ${response.statusCode}: ${response.body}',
|
||||
);
|
||||
}
|
||||
accessToken = jsonDecode(response.body)['access_token'];
|
||||
final response = await postUrl(url2, body);
|
||||
response.match(onSuccess: (body) {
|
||||
accessToken = jsonDecode(body)['access_token'];
|
||||
}, onError: (error) {
|
||||
_logger.severe('Error doing OAUth processing: $error');
|
||||
});
|
||||
} catch (e) {
|
||||
_logger.severe('Exception while Doing OAuth Process: $e');
|
||||
return buildErrorResult(
|
||||
|
|
Loading…
Reference in a new issue