Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oauth updates #1642

Open
wants to merge 51 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
27a3d02
v0.20.0 api updates
gwbischof Nov 10, 2024
2f60b6a
add oauth2_client package
gwbischof Nov 17, 2024
9905ea0
add flutter_web_auth_2
gwbischof Nov 17, 2024
a9b03cb
Add Privacy Portal Login
gwbischof Nov 17, 2024
b0db713
the privacy portal part is working but, the redirect_uri in unreachable
gwbischof Nov 23, 2024
b24bd74
got the calback working
gwbischof Nov 30, 2024
83d3eab
stuck on the last step of getting the jwt from lemmy
gwbischof Dec 1, 2024
926ec5f
its working
gwbischof Dec 3, 2024
4db929d
touch ups
gwbischof Dec 3, 2024
4b08c9b
make state a random string and check the response from provider
gwbischof Dec 7, 2024
899149a
raise if no code received from provider
gwbischof Dec 7, 2024
c70ce16
Add showContentWarning to OAuthLoginAttempt
gwbischof Dec 11, 2024
11e14c4
Use the provider from the site_response
gwbischof Dec 12, 2024
0a5f43e
Update the login page to display a list of providers
gwbischof Dec 14, 2024
07dd4b6
Dynamically add oauth providers to login screen
gwbischof Dec 14, 2024
8a65626
Touch ups
gwbischof Dec 14, 2024
3b89294
working on macos
gwbischof Dec 21, 2024
f342e2c
working better now
gwbischof Dec 22, 2024
d6cc397
touch ups
gwbischof Dec 22, 2024
401acbd
oauth is working with localhost callback on desktop and mobile, worki…
gwbischof Dec 30, 2024
530cef6
remove code from _oauthCallback
gwbischof Dec 31, 2024
a81682e
split OAuthLoginAttempt into 2 parts
gwbischof Dec 31, 2024
a25d11b
oauth login is working on android
gwbischof Dec 31, 2024
b5a5e07
Clean up
gwbischof Jan 3, 2025
e93ca0c
about to remove WebAuthPackage
gwbischof Jan 3, 2025
320c093
removed flutter_web_auth_2
gwbischof Jan 3, 2025
b8395a1
ios build update
gwbischof Jan 3, 2025
fcb868a
use AuthenticateWithOauth from lemmy_api_client
gwbischof Jan 3, 2025
bd86986
dynamic oauth provider id
gwbischof Jan 3, 2025
414ae72
remove https localhost code
gwbischof Jan 3, 2025
1919ec0
clean up
gwbischof Jan 3, 2025
4df64e5
remove fake certs
gwbischof Jan 3, 2025
2d347f6
cleanup
gwbischof Jan 4, 2025
88b695b
more clean up
gwbischof Jan 4, 2025
9431a6c
trying to get contentWarning to work
gwbischof Jan 4, 2025
64e4825
Added AddAccount to AuthBloc, got contentWarning working for oauth.
gwbischof Jan 4, 2025
8a9d3ab
add a place holder for picking your username with oauth
gwbischof Jan 5, 2025
49004f3
Working on SignUp
gwbischof Jan 5, 2025
b353b8b
Create username is working
gwbischof Jan 5, 2025
c956c5d
omg all of the parts are working
gwbischof Jan 6, 2025
9f6e6be
touch ups
gwbischof Jan 7, 2025
4b71d02
update lemmy_api_client in pubspec
gwbischof Jan 7, 2025
ab98b12
touch up
gwbischof Jan 9, 2025
5950fd9
touch ups
gwbischof Jan 9, 2025
70a1940
reduce some lines of code
gwbischof Jan 11, 2025
5081565
sign up localization
gwbischof Jan 11, 2025
f308012
remvoe extra LogOut
gwbischof Jan 14, 2025
849fadf
Add SSO login heading and spacer between providers
micahmo Jan 14, 2025
f282daf
Get the lemmy api client after changing the base URL for OAuth
micahmo Jan 17, 2025
d8720e4
Fix profile modal staying open after logging into new account
micahmo Jan 21, 2025
95d641c
Merge remote-tracking branch 'origin' into oauth
hjiangsu Feb 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
askForAppToLaunch = "Yes"
launchAutomaticallySubstyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
78 changes: 75 additions & 3 deletions lib/account/pages/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:thunder/core/auth/bloc/auth_bloc.dart';
import 'package:thunder/core/singletons/lemmy_client.dart';
import 'package:thunder/instances.dart';
import 'package:thunder/shared/dialogs.dart';
import 'package:thunder/shared/input_dialogs.dart';
import 'package:thunder/shared/snackbar.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/instance.dart';
Expand Down Expand Up @@ -47,6 +48,7 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
bool instanceValidated = true;
bool instanceAwaitingValidation = true;
String? instanceError;
List<ProviderView> oauthProviders = [];

bool isLoading = false;

Expand Down Expand Up @@ -77,6 +79,7 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
_instanceTextEditingController.addListener(() async {
if (currentInstance != _instanceTextEditingController.text) {
setState(() => instanceIcon = null);
setState(() => oauthProviders = []);
currentInstance = _instanceTextEditingController.text;
}

Expand All @@ -94,6 +97,7 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
await getInstanceInfo(_instanceTextEditingController.text).then((value) {
// Make sure the icon we looked up still matches the text
if (currentInstance == _instanceTextEditingController.text) {
setState(() => oauthProviders = value.oauthProviders ?? []);
setState(() => instanceIcon = value.icon);
}
});
Expand Down Expand Up @@ -152,7 +156,7 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
} else if (state.status == AuthStatus.success && context.read<AuthBloc>().state.isLoggedIn) {
widget.popModal();
showSnackbar(AppLocalizations.of(context)!.loginSucceeded);
} else if (state.status == AuthStatus.contentWarning) {
} else if (state.status == AuthStatus.contentWarning || state.status == AuthStatus.oauthContentWarning) {
bool acceptedContentWarning = false;

await showThunderDialog<void>(
Expand All @@ -170,8 +174,37 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix

if (context.mounted) {
if (acceptedContentWarning) {
// Do another login attempt, this time without the content warning
_handleLogin(showContentWarning: false);
if (state.status == AuthStatus.oauthContentWarning) {
context.read<AuthBloc>().add(const AddAccount());
} else {
// Do another login attempt, this time without the content warning
// TODO: This can be updated to use AddAccount instead of starting the login process over.
_handleLogin(showContentWarning: false);
}
} else {
// Cancel the login
context.read<AuthBloc>().add(const CancelLoginAttempt());
}
}
} else if (state.status == AuthStatus.oauthSignUp) {
bool completedSignUp = false;
String? username;

await showBlockingInputDialog<String>(
context: context,
title: l10n.signUp,
inputLabel: l10n.username,
getSuggestions: (_) => [],
suggestionBuilder: (payload) => Container(),
onSubmitted: ({payload, value}) {
completedSignUp = true;
username = value;
return Future.value(null);
});

if (context.mounted) {
if (completedSignUp) {
context.read<AuthBloc>().add(OAuthLoginAttempt(username: username));
} else {
// Cancel the login
context.read<AuthBloc>().add(const CancelLoginAttempt());
Expand Down Expand Up @@ -435,6 +468,34 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
child: Text(widget.anonymous ? AppLocalizations.of(context)!.add : AppLocalizations.of(context)!.login,
style: theme.textTheme.titleMedium?.copyWith(color: !isLoading && fieldsFilledIn ? theme.colorScheme.onPrimary : theme.colorScheme.primary)),
),
if (oauthProviders.isNotEmpty) ...[
const SizedBox(height: 20.0),
Text(
l10n.orLogInWithSso,
style: theme.textTheme.titleMedium,
),
],
for (final provider in oauthProviders) ...[
const SizedBox(height: 12.0),
ElevatedButton(
style: ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(60),
backgroundColor: theme.colorScheme.primary,
textStyle: theme.textTheme.titleMedium?.copyWith(
color: theme.colorScheme.onPrimary,
),
),
onPressed: (!isLoading && _instanceTextEditingController.text.isNotEmpty)
? () {
_handleOAuthLogin(provider: provider);
}
: (_instanceTextEditingController.text.isNotEmpty && widget.anonymous)
? () => _addAnonymousInstance(context)
: null,
child: Text(provider.displayName,
style: theme.textTheme.titleMedium?.copyWith(color: !isLoading && _instanceTextEditingController.text.isNotEmpty ? theme.colorScheme.onPrimary : theme.colorScheme.primary)),
),
],
const SizedBox(height: 12.0),
TextButton(
style: ElevatedButton.styleFrom(minimumSize: const Size.fromHeight(60)),
Expand Down Expand Up @@ -465,6 +526,17 @@ class _LoginPageState extends State<LoginPage> with SingleTickerProviderStateMix
);
}

void _handleOAuthLogin({required ProviderView provider}) {
TextInput.finishAutofillContext();
// Perform oauth login authentication.
context.read<AuthBloc>().add(
OAuthLoginAttempt(
instance: _instanceTextEditingController.text.trim(),
provider: provider,
),
);
}

void _addAnonymousInstance(BuildContext context) async {
final AppLocalizations l10n = AppLocalizations.of(context)!;

Expand Down
Loading