diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..a8f2f8e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "OpenMediaStation.FE.MovieTV", + "request": "launch", + "type": "dart", + "args": ["-d", "chrome","--web-port", "8000"] + }, + { + "name": "OpenMediaStation.FE.MovieTV (profile mode)", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "OpenMediaStation.FE.MovieTV (release mode)", + "request": "launch", + "type": "dart", + "flutterMode": "release" + } + ] +} \ No newline at end of file diff --git a/assets/OMS logo 16.png b/assets/OMS logo 16.png new file mode 100644 index 0000000..3f62cab Binary files /dev/null and b/assets/OMS logo 16.png differ diff --git a/assets/OMS logo 512.png b/assets/OMS logo 512.png new file mode 100644 index 0000000..f2b80d7 Binary files /dev/null and b/assets/OMS logo 512.png differ diff --git a/lib/auth/auth_globals.dart b/lib/auth/auth_globals.dart new file mode 100644 index 0000000..9e9e7e5 --- /dev/null +++ b/lib/auth/auth_globals.dart @@ -0,0 +1,13 @@ +import 'package:flutter/foundation.dart'; +import 'package:open_media_server_app/globals.dart'; + +class AuthGlobals { + static String get redirectUriWeb { + if (kDebugMode) { + return "http://localhost:8000/redirect.html"; + } else { + return "https://${Globals.BaseUrl}/redirect.html"; + } + } + static String? appLoginCodeRoute; +} \ No newline at end of file diff --git a/lib/auth/login_manager.dart b/lib/auth/login_manager.dart index 5d18baf..ce793d4 100644 --- a/lib/auth/login_manager.dart +++ b/lib/auth/login_manager.dart @@ -1,6 +1,6 @@ -// import 'package:fedodo_general/globals/preferences.dart'; -// import 'package:fedodo_general/widgets/auth/oauth_handler/custom_web_base_dummy.dart' -// if (dart.library.html) '../oauth_handler/custom_web_base.dart'; +import 'package:open_media_server_app/auth/auth_globals.dart'; +import 'package:open_media_server_app/auth/oauth_handler/custom_web_base_dummy.dart' + if (dart.library.html) './oauth_handler/custom_web_base.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:oauth2_client/access_token_response.dart'; @@ -27,27 +27,26 @@ class LoginManager { redirectUri: "my.test.app:/oauth2redirect", // TODO customUriScheme: "my.test.app", ); - } else { - // client = OAuth2Client( - // authorizeUrl: - // "https://auth.${Preferences.prefs!.getString("DomainName")}/oauth/authorize", - // tokenUrl: - // "https://auth.${Preferences.prefs!.getString("DomainName")}/oauth/token", - // redirectUri: AuthGlobals.redirectUriWeb, - // // refreshUrl: "https://auth.${GlobalSettings.domainName}/oauth/token", - // customUriScheme: Uri.parse(AuthGlobals.redirectUriWeb).authority, - // ); + } else if (Globals.isWeb) { + client = OAuth2Client( + authorizeUrl: authInfo.authorizeUrl, + tokenUrl: authInfo.tokenUrl, + redirectUri: AuthGlobals.redirectUriWeb, + // refreshUrl: "https://auth.${GlobalSettings.domainName}/oauth/token", + customUriScheme: Uri.parse(AuthGlobals.redirectUriWeb).authority, + ); } - // if (kIsWeb) { - // baseWebAuth = CustomWebBase(); - // } + if (kIsWeb) { + baseWebAuth = CustomWebBase(); + } } Future login(AuthInfo authInfo, BuildContext context) async { if (Globals.isTv) { DeviceCode deviceCode = DeviceCode(); - var token = await deviceCode.authenticateUser(authInfo, "offline_access", authInfo.deviceCodeUrl, context); + var token = await deviceCode.authenticateUser( + authInfo, "offline_access", authInfo.deviceCodeUrl, context); Preferences.prefs?.setString("AccessToken", token!); diff --git a/lib/auth/oauth_handler/custom_web_base.dart b/lib/auth/oauth_handler/custom_web_base.dart new file mode 100644 index 0000000..c73d5a4 --- /dev/null +++ b/lib/auth/oauth_handler/custom_web_base.dart @@ -0,0 +1,39 @@ +import 'package:oauth2_client/interfaces.dart'; +import 'package:open_media_server_app/auth/auth_globals.dart'; +// ignore: avoid_web_libraries_in_flutter +import 'dart:html' as html; + +import 'package:open_media_server_app/helpers/Preferences.dart'; + +class CustomWebBase implements BaseWebAuth { + @override + Future authenticate({ + required String callbackUrlScheme, + required String url, + required String redirectUrl, + Map? opts, + }) async { + + if(AuthGlobals.appLoginCodeRoute == null){ + Uri uri = Uri.parse(url); + + String state = uri.queryParameters["state"]!; + + Preferences.prefs?.setString("OAuth_State", state); + + html.window.open(url, "_self"); + + await Future.delayed(const Duration(seconds: 10)); + + return ""; + }else{ + Preferences.prefs?.remove("OAuth_State"); + var temp = AuthGlobals.appLoginCodeRoute; + AuthGlobals.appLoginCodeRoute = null; + + return html.window.origin! + temp.toString(); + } + + + } +} \ No newline at end of file diff --git a/lib/auth/oauth_handler/custom_web_base_dummy.dart b/lib/auth/oauth_handler/custom_web_base_dummy.dart new file mode 100644 index 0000000..4a6cfde --- /dev/null +++ b/lib/auth/oauth_handler/custom_web_base_dummy.dart @@ -0,0 +1,13 @@ +import 'package:oauth2_client/interfaces.dart'; + +class CustomWebBase implements BaseWebAuth { + @override + Future authenticate({ + required String callbackUrlScheme, + required String url, + required String redirectUrl, + Map? opts, + }) { + throw UnimplementedError(); + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 7f6b10c..0036350 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:media_kit/media_kit.dart'; import 'package:open_media_server_app/apis/auth_info_api.dart'; +import 'package:open_media_server_app/auth/auth_globals.dart'; import 'package:open_media_server_app/auth/login_manager.dart'; import 'package:open_media_server_app/gallery.dart'; import 'package:open_media_server_app/globals.dart'; @@ -46,6 +47,13 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( + onGenerateRoute: (settings) { + if (settings.name?.contains("code") ?? false) { + AuthGlobals.appLoginCodeRoute = settings.name; + } + + return null; + }, title: Globals.Title, theme: ThemeData( colorScheme: ColorScheme.fromSeed( diff --git a/web/favicon.png b/web/favicon.png index 8aaa46a..3f62cab 100644 Binary files a/web/favicon.png and b/web/favicon.png differ diff --git a/web/icons/Icon-192.png b/web/icons/Icon-192.png index b749bfe..4bdb8fc 100644 Binary files a/web/icons/Icon-192.png and b/web/icons/Icon-192.png differ diff --git a/web/icons/Icon-512.png b/web/icons/Icon-512.png index 88cfd48..f2b80d7 100644 Binary files a/web/icons/Icon-512.png and b/web/icons/Icon-512.png differ diff --git a/web/icons/Icon-maskable-192.png b/web/icons/Icon-maskable-192.png index eb9b4d7..4bdb8fc 100644 Binary files a/web/icons/Icon-maskable-192.png and b/web/icons/Icon-maskable-192.png differ diff --git a/web/icons/Icon-maskable-512.png b/web/icons/Icon-maskable-512.png index d69c566..f2b80d7 100644 Binary files a/web/icons/Icon-maskable-512.png and b/web/icons/Icon-maskable-512.png differ diff --git a/web/redirect.html b/web/redirect.html new file mode 100644 index 0000000..5f5e2fb --- /dev/null +++ b/web/redirect.html @@ -0,0 +1,10 @@ + \ No newline at end of file