From 8d096d566f0ea39f37baff9e0d0c573ad82a9c20 Mon Sep 17 00:00:00 2001 From: Garrett Bischof Date: Mon, 30 Dec 2024 21:12:51 -0500 Subject: [PATCH] remove code from _oauthCallback --- lib/thunder/pages/thunder_page.dart | 68 ----------------------------- 1 file changed, 68 deletions(-) diff --git a/lib/thunder/pages/thunder_page.dart b/lib/thunder/pages/thunder_page.dart index c1b668cfd..19ce2314d 100644 --- a/lib/thunder/pages/thunder_page.dart +++ b/lib/thunder/pages/thunder_page.dart @@ -254,76 +254,8 @@ class _ThunderState extends State { } Future _oauthCallback(String link) async { - // TODO: Need to know state, and instance. - try { - String redirectUri = "https://thunderapp.dev/oauth/callback"; debugPrint("_oauthCallback $link"); - // oauthProviderState must match oauthClientState to ensure the response came from the Provider. - String oauthProviderState = Uri.parse(link).queryParameters['state'] ?? "failed"; - if (oauthProviderState == "failed" || oauthClientState != oauthProviderState) { - throw Exception("OAuth state-check failed: oauthProviderState $oauthClientState must match oauthClientState $oauthClientState to ensure the response came from the Provider."); - } - - // Extract the code from the response. - String code = Uri.parse(link).queryParameters['code'] ?? "failed"; - - debugPrint("CODE $code"); - - if (code == "failed") { - throw Exception("OAuth login failed: no code received from provider."); - } - - // TODO: This should use lemmy_api_client. - // Authenthicate to lemmy and get a jwt. - // Durring this step lemmy connects to the Provider to get the user info. - final response = await http.post(Uri.parse('https://$instance/api/v3/oauth/authenticate'), - headers: { - 'Content-Type': 'application/json', - }, - body: json.encode({ - 'code': code, - 'oauth_provider_id': 1, // This id can be found in the site reponse. - 'redirect_uri': redirectUri, - }), - encoding: Encoding.getByName('utf-8')); - - // TODO: Need to add a step to set the account username. - - final accessToken = jsonDecode(response.body)['jwt'] as String; - - debugPrint("JWT $accessToken"); - - GetSiteResponse getSiteResponse = await lemmy.run(GetSite(auth: accessToken)); - - // TODO: Login fails when this is uncommented. Have to get this working. - //if (event.showContentWarning && getSiteResponse.siteView.site.contentWarning?.isNotEmpty == true) { - // return emit(state.copyWith(status: AuthStatus.contentWarning, contentWarning: getSiteResponse.siteView.site.contentWarning)); - //} - - // Create a new account in the database - Account? account = Account( - id: '', - username: getSiteResponse.myUser?.localUserView.person.name, - jwt: accessToken, - instance: instance, - userId: getSiteResponse.myUser?.localUserView.person.id, - index: -1, - ); - - account = await Account.insertAccount(account); - - if (account == null) { - return emit(state.copyWith(status: AuthStatus.failure, account: null, isLoggedIn: false)); - } - - // Set this account as the active account - SharedPreferences prefs = (await UserPreferences.instance).sharedPreferences; - prefs.setString('active_profile_id', account.id); - - bool downvotesEnabled = getSiteResponse.siteView.localSite.enableDownvotes ?? false; - - return emit(state.copyWith(status: AuthStatus.success, account: account, isLoggedIn: true, downvotesEnabled: downvotesEnabled, getSiteResponse: getSiteResponse)); } catch (e) { if (context.mounted) { _showLinkProcessingError(context, AppLocalizations.of(context)!.exceptionProcessingUri, link);