Skip to content

Commit

Permalink
add the option to recieve http client from outside in openLoggedInWeb…
Browse files Browse the repository at this point in the history
…Page
  • Loading branch information
ramin-deriv committed Feb 28, 2024
1 parent 1bba495 commit 12e531b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/deriv_web_view/lib/deriv_web_view.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:developer' as dev;

import 'package:deriv_http_client/deriv_http_client.dart';
import 'package:deriv_web_view/helper.dart';
import 'package:deriv_web_view/widgets/in_app_browser/chrome_safari_browser.dart';
import 'package:deriv_web_view/widgets/in_app_browser/in_app_browser.dart';
Expand All @@ -10,6 +11,9 @@ import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:url_launcher/url_launcher_string.dart';

/// A callback to resolve http client
typedef HttpClientPredicate = Future<BaseHttpClient> Function(String url);

/// Opens a url in a browser.
Future<void> openWebPage({
required BuildContext context,
Expand Down Expand Up @@ -149,6 +153,7 @@ Future<void> openLoggedInWebPage({
required bool rootNavigator,
required String appToken,
required String userAgent,
HttpClientPredicate? getHttpClient,
String destinationAppId = '16929',
String? action,
String? code,
Expand All @@ -169,6 +174,7 @@ Future<void> openLoggedInWebPage({
tokenExpiredDialog: tokenExpiredDialog,
rootNavigator: rootNavigator,
appToken: appToken,
getHttpClient: getHttpClient,
action: action,
code: code,
);
Expand Down Expand Up @@ -207,6 +213,7 @@ Future<void> openLoggedInWebPage({
tokenExpiredDialog: tokenExpiredDialog,
rootNavigator: rootNavigator,
appToken: appToken,
getHttpClient: getHttpClient,
action: action,
code: code,
);
Expand Down Expand Up @@ -238,6 +245,7 @@ Future<String?> _fetchOneTimeToken({
required void Function(BuildContext context) loadingDialog,
required bool rootNavigator,
required String appToken,
HttpClientPredicate? getHttpClient,
String? action,
String? code,
}) async {
Expand All @@ -253,6 +261,7 @@ Future<String?> _fetchOneTimeToken({
appToken: appToken,
action: action,
code: code,
getHttpClient: getHttpClient,
);

Navigator.of(context, rootNavigator: rootNavigator).pop();
Expand All @@ -269,6 +278,7 @@ Future<String?> _getOneTimeToken({
required String? refreshToken,
required String? defaultAccount,
required String appToken,
HttpClientPredicate? getHttpClient,
String? action,
String? code,
}) async {
Expand All @@ -283,6 +293,7 @@ Future<String?> _getOneTimeToken({
appToken: appToken,
action: action,
code: code,
getHttpClient: getHttpClient,
);

return token;
Expand All @@ -305,6 +316,7 @@ Future<String?> _validateCredentials({
required Future<void> Function(BuildContext context) tokenExpiredDialog,
required bool rootNavigator,
required String appToken,
HttpClientPredicate? getHttpClient,
String? action,
String? code,
}) async {
Expand All @@ -319,6 +331,7 @@ Future<String?> _validateCredentials({
loadingDialog: loadingDialog,
rootNavigator: rootNavigator,
appToken: appToken,
getHttpClient: getHttpClient,
action: action,
code: code,
);
Expand Down
4 changes: 3 additions & 1 deletion packages/deriv_web_view/lib/helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:developer' as logger;
import 'package:crypto/crypto.dart';

import 'package:deriv_http_client/deriv_http_client.dart';
import 'package:deriv_web_view/deriv_web_view.dart';

import 'package:deriv_web_view/models/app_authorization_challenge_request_model.dart';
import 'package:deriv_web_view/models/app_authorization_challenge_response_model.dart';
Expand All @@ -21,12 +22,13 @@ Future<String?> performPassThroughAuthentication({
required String endpoint,
required String appId,
required String appToken,
HttpClientPredicate? getHttpClient,
String? action,
String? code,
}) async {
final url = getPtaLoginUrl(host: endpoint);

final BaseHttpClient client = ProxyAwareHttpClient(url);
final BaseHttpClient client = await getHttpClient?.call(url) ?? HttpClient();

final String jwtToken = await getJwtToken(
endpoint: endpoint,
Expand Down

0 comments on commit 12e531b

Please sign in to comment.