From 6fd4a3b721544f11564f18363575991364520d5a Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Fri, 27 Sep 2024 11:11:02 -0500 Subject: [PATCH] Remove webview auth approach --- waydowntown_app/lib/developer_tools.dart | 11 --- waydowntown_app/lib/tools/auth_webview.dart | 90 ------------------- .../Flutter/GeneratedPluginRegistrant.swift | 2 - waydowntown_app/pubspec.lock | 42 +-------- waydowntown_app/pubspec.yaml | 2 - 5 files changed, 1 insertion(+), 146 deletions(-) delete mode 100644 waydowntown_app/lib/tools/auth_webview.dart diff --git a/waydowntown_app/lib/developer_tools.dart b/waydowntown_app/lib/developer_tools.dart index fd168487..8442c7bb 100644 --- a/waydowntown_app/lib/developer_tools.dart +++ b/waydowntown_app/lib/developer_tools.dart @@ -1,9 +1,7 @@ import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:talker_flutter/talker_flutter.dart'; import 'package:waydowntown/app.dart'; -import 'package:waydowntown/tools/auth_webview.dart'; import 'package:waydowntown/tools/bluetooth_scanner_route.dart'; import 'package:waydowntown/tools/map_route.dart'; import 'package:waydowntown/tools/motion_sensors_route.dart'; @@ -24,7 +22,6 @@ class DeveloperTools extends StatelessWidget { _buildFlexibleButtonGrid( context, [ - ('Auth', 'auth_webview'), ('Bluetooth\nScanner', 'bluetooth_scanner'), ('Map', 'map'), ('Motion\nSensors', 'motion_sensors'), @@ -51,14 +48,6 @@ class DeveloperTools extends StatelessWidget { MaterialPageRoute( builder: (context) => const MotionSensorsRoute())); break; - case 'auth_webview': - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => AuthWebView( - apiBaseUrl: dotenv.env['API_ROOT']!, - dio: dio))); - break; case 'logs': Navigator.push( context, diff --git a/waydowntown_app/lib/tools/auth_webview.dart b/waydowntown_app/lib/tools/auth_webview.dart deleted file mode 100644 index 29e5c320..00000000 --- a/waydowntown_app/lib/tools/auth_webview.dart +++ /dev/null @@ -1,90 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:webview_cookie_manager/webview_cookie_manager.dart'; -import 'package:webview_flutter/webview_flutter.dart'; - -class AuthWebView extends StatefulWidget { - final String apiBaseUrl; - final Dio dio; - - const AuthWebView({ - super.key, - required this.apiBaseUrl, - required this.dio, - }); - - @override - _AuthWebViewState createState() => _AuthWebViewState(); -} - -class _AuthWebViewState extends State { - late WebViewController _controller; - final cookieManager = WebviewCookieManager(); - String? _email; - - @override - void initState() { - super.initState(); - _controller = WebViewController() - ..setUserAgent( - 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1') - ..setJavaScriptMode(JavaScriptMode.unrestricted) - ..setNavigationDelegate( - NavigationDelegate( - onPageFinished: (String url) { - if (url.endsWith('/details')) { - _getSession(); - } - }, - ), - ) - ..loadRequest(Uri.parse('${widget.apiBaseUrl}/session/new')); - } - - void _getSession() async { - final cookies = await cookieManager.getCookies(widget.apiBaseUrl); - final cookieString = cookies.map((c) => '${c.name}=${c.value}').join('; '); - - try { - final response = await widget.dio.get( - '/fixme/session', - options: Options(headers: {'Cookie': cookieString}), - ); - - if (response.statusCode == 200) { - final email = response.data['data']['attributes']['email']; - setState(() { - _email = email; - }); - - final preferences = await SharedPreferences.getInstance(); - await preferences.setString('auth_cookie', cookieString); - } - } catch (error) { - print('Error fetching session: $error'); - // Handle error (e.g., show an error message) - } - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Login'), - ), - body: Column( - children: [ - Expanded( - child: WebViewWidget(controller: _controller), - ), - if (_email != null) - Padding( - padding: const EdgeInsets.all(16.0), - child: Text('Logged in as: $_email'), - ), - ], - ), - ); - } -} diff --git a/waydowntown_app/macos/Flutter/GeneratedPluginRegistrant.swift b/waydowntown_app/macos/Flutter/GeneratedPluginRegistrant.swift index a4ce85f3..44c679bc 100644 --- a/waydowntown_app/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/waydowntown_app/macos/Flutter/GeneratedPluginRegistrant.swift @@ -14,7 +14,6 @@ import sentry_flutter import share_plus import shared_preferences_foundation import sqlite3_flutter_libs -import webview_flutter_wkwebview func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FlutterBluePlusPlugin.register(with: registry.registrar(forPlugin: "FlutterBluePlusPlugin")) @@ -26,5 +25,4 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin")) - FLTWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "FLTWebViewFlutterPlugin")) } diff --git a/waydowntown_app/pubspec.lock b/waydowntown_app/pubspec.lock index e5dc17fb..eb4f7962 100644 --- a/waydowntown_app/pubspec.lock +++ b/waydowntown_app/pubspec.lock @@ -1338,46 +1338,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.3" - webview_cookie_manager: - dependency: "direct main" - description: - name: webview_cookie_manager - sha256: "425a9feac5cd2cb62a71da3dda5ac2eaf9ece5481ee8d79f3868dc5ba8223ad3" - url: "https://pub.dev" - source: hosted - version: "2.0.6" - webview_flutter: - dependency: "direct main" - description: - name: webview_flutter - sha256: ec81f57aa1611f8ebecf1d2259da4ef052281cb5ad624131c93546c79ccc7736 - url: "https://pub.dev" - source: hosted - version: "4.9.0" - webview_flutter_android: - dependency: transitive - description: - name: webview_flutter_android - sha256: "6e64fcb1c19d92024da8f33503aaeeda35825d77142c01d0ea2aa32edc79fdc8" - url: "https://pub.dev" - source: hosted - version: "3.16.7" - webview_flutter_platform_interface: - dependency: transitive - description: - name: webview_flutter_platform_interface - sha256: d937581d6e558908d7ae3dc1989c4f87b786891ab47bb9df7de548a151779d8d - url: "https://pub.dev" - source: hosted - version: "2.10.0" - webview_flutter_wkwebview: - dependency: transitive - description: - name: webview_flutter_wkwebview - sha256: "1942a12224ab31e9508cf00c0c6347b931b023b8a4f0811e5dec3b06f94f117d" - url: "https://pub.dev" - source: hosted - version: "3.15.0" win32: dependency: transitive description: @@ -1420,4 +1380,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.5.0 <4.0.0" - flutter: ">=3.24.0" + flutter: ">=3.22.0" diff --git a/waydowntown_app/pubspec.yaml b/waydowntown_app/pubspec.yaml index 492b0933..b3e17aaa 100644 --- a/waydowntown_app/pubspec.yaml +++ b/waydowntown_app/pubspec.yaml @@ -66,8 +66,6 @@ dependencies: geolocator: ^11.1.0 sqlite3_flutter_libs: ^0.5.24 flutter_lucide: ^1.4.0 - webview_flutter: ^4.9.0 - webview_cookie_manager: ^2.0.6 flutter_flavorizr: ^2.2.3 shared_preferences: ^2.3.2 talker: ^4.4.1