aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authorGravatar hunteraraujo <hunter_araujo@msn.com> 2023-10-05 22:07:32 -0700
committerGravatar GitHub <noreply@github.com> 2023-10-05 22:07:32 -0700
commit35efc897dfea837506643028435a5166a042c428 (patch)
treef6c7821047276be6b5566de9b4d1cc81ffc5b050 /frontend
parentbigman entering the arena (#5540) (diff)
downloadAuto-GPT-35efc897dfea837506643028435a5166a042c428.tar.gz
Auto-GPT-35efc897dfea837506643028435a5166a042c428.tar.bz2
Auto-GPT-35efc897dfea837506643028435a5166a042c428.zip
Enhanced OAuth 2.0 Implementation with Dynamic Redirect URIs and Popup Authentication (#5566)
* Set custom parameter redirect URI * Red border * Blue border
Diffstat (limited to 'frontend')
-rw-r--r--frontend/lib/services/auth_service.dart49
1 files changed, 43 insertions, 6 deletions
diff --git a/frontend/lib/services/auth_service.dart b/frontend/lib/services/auth_service.dart
index 3cbb3b9c7..62941e31b 100644
--- a/frontend/lib/services/auth_service.dart
+++ b/frontend/lib/services/auth_service.dart
@@ -7,24 +7,61 @@ class AuthService {
clientId:
"387936576242-iejdacrjljds7hf99q0p6eqna8rju3sb.apps.googleusercontent.com");
-// Sign in with Google using redirect
+// Sign in with Google using popup
Future<UserCredential?> signInWithGoogle() async {
try {
final GoogleAuthProvider googleProvider = GoogleAuthProvider();
- await _auth.signInWithRedirect(googleProvider);
- return await _auth.getRedirectResult();
+
+ // Step 1: Detect the current hostname
+ String hostname = Uri.base.host;
+
+ // Step 2: Determine the redirect URI
+ String redirectUri;
+ if (hostname.contains('github.dev')) {
+ // If running in Github Codespaces
+ redirectUri = Uri.base.toString();
+ } else {
+ // For local development or other environments, set accordingly
+ redirectUri = 'http://localhost:8000'; // Example for local development
+ }
+
+ // Step 3: Update OAuth 2.0 provider configuration dynamically
+ googleProvider.setCustomParameters({'redirect_uri': redirectUri});
+
+ // Use signInWithPopup instead of signInWithRedirect
+ final result = await _auth.signInWithPopup(googleProvider);
+ print(result);
+ return result;
} catch (e) {
print("Error during Google Sign-In: $e");
return null;
}
}
-// Sign in with GitHub using redirect
+// Sign in with GitHub using popup
Future<UserCredential?> signInWithGitHub() async {
try {
final GithubAuthProvider githubProvider = GithubAuthProvider();
- await _auth.signInWithRedirect(githubProvider);
- return await _auth.getRedirectResult();
+
+ // Step 1: Detect the current hostname
+ String hostname = Uri.base.host;
+
+ // Step 2: Determine the redirect URI
+ String redirectUri;
+ if (hostname.contains('github.dev')) {
+ // If running in Github Codespaces
+ redirectUri = Uri.base.toString();
+ } else {
+ // For local development or other environments, set accordingly
+ redirectUri = 'http://localhost:8000'; // Example for local development
+ }
+
+ // Step 3: Update OAuth 2.0 provider configuration dynamically
+ githubProvider.setCustomParameters({'redirect_uri': redirectUri});
+
+ // Use signInWithPopup instead of signInWithRedirect
+ final result = await _auth.signInWithPopup(githubProvider);
+ return result;
} catch (e) {
print("Error during GitHub Sign-In: $e");
return null;