mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-08 11:59:23 +00:00
Remove IoniaTokenService
This commit is contained in:
parent
83d5c17b36
commit
0b60a03e74
2 changed files with 0 additions and 75 deletions
|
@ -141,7 +141,6 @@ import 'package:cake_wallet/entities/template.dart';
|
|||
import 'package:cake_wallet/exchange/exchange_template.dart';
|
||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
import 'package:cake_wallet/src/screens/dashboard/widgets/address_page.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_token_service.dart';
|
||||
import 'package:cake_wallet/anypay/anypay_api.dart';
|
||||
import 'package:cake_wallet/view_model/ionia/ionia_gift_card_details_view_model.dart';
|
||||
import 'package:cake_wallet/src/screens/ionia/cards/ionia_payment_status_page.dart';
|
||||
|
@ -250,8 +249,6 @@ Future setup(
|
|||
getIt.get<KeyService>(),
|
||||
(WalletType type) => getIt.get<WalletService>(param1: type)));
|
||||
|
||||
getIt.registerFactory(() => IoniaTokenService(getIt.get<FlutterSecureStorage>()));
|
||||
|
||||
getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) =>
|
||||
WalletNewVM(getIt.get<AppStore>(),
|
||||
getIt.get<WalletCreationService>(param1: type), _walletInfoSource,
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
import 'dart:convert';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_token_data.dart';
|
||||
import 'package:cake_wallet/.secrets.g.dart';
|
||||
|
||||
String basicAuth(String username, String password) =>
|
||||
'Basic ' + base64Encode(utf8.encode('$username:$password'));
|
||||
|
||||
abstract class TokenService {
|
||||
TokenService(this.flutterSecureStorage);
|
||||
|
||||
String get serviceName;
|
||||
String get oauthUrl;
|
||||
final FlutterSecureStorage flutterSecureStorage;
|
||||
|
||||
String get _storeKey => '${serviceName}_oauth_token';
|
||||
|
||||
Future<IoniaTokenData> getToken() async {
|
||||
final storedTokenJson = await flutterSecureStorage.read(key: _storeKey);
|
||||
IoniaTokenData token;
|
||||
|
||||
if (storedTokenJson != null) {
|
||||
token = IoniaTokenData.fromJson(storedTokenJson);
|
||||
} else {
|
||||
token = await _fetchNewToken();
|
||||
await _storeToken(token);
|
||||
}
|
||||
|
||||
if (token.isExpired) {
|
||||
token = await _fetchNewToken();
|
||||
await _storeToken(token);
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
Future<IoniaTokenData> _fetchNewToken() async {
|
||||
final basic = basicAuth(ioniaClientId, ioniaClientSecret);
|
||||
final body = <String, String>{'grant_type': 'client_credentials', 'scope': 'cake_dev'};
|
||||
final response = await post(
|
||||
oauthUrl,
|
||||
headers: <String, String>{
|
||||
'Authorization': basic,
|
||||
'Content-Type': 'application/x-www-form-urlencoded'},
|
||||
encoding: Encoding.getByName('utf-8'),
|
||||
body: body);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
// throw exception
|
||||
return null;
|
||||
}
|
||||
|
||||
return IoniaTokenData.fromJson(response.body);
|
||||
}
|
||||
|
||||
Future<void> _storeToken(IoniaTokenData token) async {
|
||||
await flutterSecureStorage.write(key: _storeKey, value: token.toJson());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class IoniaTokenService extends TokenService {
|
||||
IoniaTokenService(FlutterSecureStorage flutterSecureStorage)
|
||||
: super(flutterSecureStorage);
|
||||
|
||||
@override
|
||||
String get serviceName => 'Ionia';
|
||||
|
||||
@override
|
||||
String get oauthUrl => 'https://auth.craypay.com/connect/token';
|
||||
}
|
Loading…
Reference in a new issue