-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
Full Native Auth support #399
Comments
Mentioned it here as well, but auth team will be working on a solution to fix the Google login platform problem. We will probably add a |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Google folks have responded to the nonce PR, which is very encouraging! google/GoogleSignIn-iOS#244 (review) |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Thank you! |
This comment was marked as off-topic.
This comment was marked as off-topic.
I have locked the conversation here to make it a public discussion board instead of a Q&A issue. If you have any question/ comments about native sign in, please post them here #5. |
@bdlukaa @DanMossa @Vinzent03 I have a few things that I would like to discuss and love to hear your opinions on. First of all, a good news 🎉 Supporting multiple Client IDs and multiple bundle IDs is finally landing Supabase, and an official announcement is scheduled to go out Friday morning PST. This means that users can finally add Google login for web, Android, and iOS or add Apple logins on multiple iOS apps. The update to allow users to be able to enter multiple client IDs or bundle IDs as comma separated values in the dashboard is being rolled out soon. With this, we should be able to tick all the check boxes on this issue. Now with this, I want to discuss how to go about implementing native auth methods on supabase_flutter. Currently, we have
The whole reason why I thought adding Native Apple login code 👇import 'package:crypto/crypto.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart' as apple;
final rawNonce = _generateRandomString();
final hashedNonce = sha256.convert(utf8.encode(rawNonce)).toString();
final credential = await apple.SignInWithApple.getAppleIDCredential(
scopes: [
apple.AppleIDAuthorizationScopes.email,
apple.AppleIDAuthorizationScopes.fullName,
],
nonce: hashedNonce,
);
final idToken = credential.identityToken;
if (idToken == null) {
throw AuthException('Could not find ID Token from generated credential.');
}
await signInWithIdToken(
provider: Provider.apple,
idToken: idToken,
nonce: rawNonce,
); However, implementing all native login methods is not very realistic, and I wonder what we should do I think we have a few choices
I personally want to go with option 2 here, but the steps to implement Google login involves quite a bit of boiler plate code. Because google_sign_in library does not allow users to specify nonce, we have to use another method, and the method I was able to find was using this one using flutter_appauth. Native Google login code 👇import 'package:crypto/crypto.dart';
import 'package:flutter_appauth/flutter_appauth.dart';
Future<AuthResponse> signInWithGoogle(String clientId) {
// Just a random string
final rawNonce = _generateRandomString();
final hashedNonce =
sha256.convert(utf8.encode(rawNonce)).toString();
/// bundle ID of the app
const bundleId = 'com.supabase.example';
/// fixed for google login
const redirectUrl = '$bundleId:/google_auth';
/// fixed for google login
const discoveryUrl =
'https://accounts.google.com/.well-known/openid-configuration';
// authorize the user by opening the concent page
final result = await appAuth.authorize(
AuthorizationRequest(
clientId,
redirectUrl,
discoveryUrl: discoveryUrl,
nonce: hashedNonce,
scopes: [
'openid',
'email',
],
),
);
if (result == null) {
throw 'No result';
}
// Request the access and id token to google
final tokenResult = await appAuth.token(
TokenRequest(
clientId,
redirectUrl,
authorizationCode: result.authorizationCode,
discoveryUrl: discoveryUrl,
codeVerifier: result.codeVerifier,
nonce: result.nonce,
scopes: [
'openid',
'email',
],
),
);
final idToken = tokenResult?.idToken;
if (idToken == null) {
throw 'No idToken';
}
return supabase.auth.signInWithIdToken(
provider: Provider.google,
idToken: idToken,
nonce: rawNonce,
);
} Do you think as long as we have detailed instruction on how to implement it, it would be okay to have some long boiler plate code, or should we provide something that makes it easier to implement it? |
I'm a big fan of setting up a simple method with documentation on how to use Apple/Google/etc logins. Like I think we should just have a basic signInWithIdToken with documentation explaining the different fields with examples of how to use Google and Apple. |
@DanMossa So that would be option 2, correct? Right there with you! While we wait for Bruno and Vinzent to drop what they think, I will prepare a PR to update the README.md to include detailed instructions on how to setup Apple login and Google login with |
I kinda like to keep the |
@Vinzent03 Nice! Yeah, it is some unnecessary long code for every developer to copy and paste every single time. Option 3 does take the best of both world off loading the dependency issue and providing better developer experience! Let's also wait for @bdlukaa to hear what he thinks! |
From a maintainer perspective, keeping the But keeping it assembles the question: do we need to create a sign in method for every supported third-party authentication method? Keeping the method would also imply in large bundle size on apps that don't make usage of social login. With that said, I like the second option tho. It should be up to the dev to handle these stuff (like Some methods, such as generating the nonce, could be built-in tho. |
Thanks everyone! It's so nice to discuss this with all of you. Why don't we do this. Let's start out with option 2, where we remove the |
@dshukertjr We can also do something where Example:
signInWithIdToken
I kind of hate this though and would rather just have Option 2. |
@DanMossa Thanks for the suggestion. In that case would the |
Well, for |
Currently in dart these is no union types (see dart-lang/language#83), but it is possible to make it |
But in order to check the type, we would do something like |
I think you are right, because the |
It'd actually look something like the following: just a POC tho // the implementation
import 'package:crypto/crypto.dart';
String getAppleNonce() {
final rawNonce = _generateRandomString();
final hashedNonce = sha256.convert(utf8.encode(rawNonce)).toString();
return hashedNonce;
}
// idToken optional maybe?
void signInWithIdToken(provider, idToken, dynamic credential){
if (credential is AuthorizationCredentialAppleID) {
final idToken = credential.identityToken;
if (idToken == null) {
throw AuthException('Could not find ID Token from generated credential.');
}
} else if (credential is GoogleSignInAccount) {
// impl with the provided info
}
return idToken;
} // the usage
// apple
await signInWithIdToken(
provider: Provider.apple,
idToken: idToken,
dependency: await apple.SignInWithApple.getAppleIDCredential(
scopes: [
apple.AppleIDAuthorizationScopes.email,
apple.AppleIDAuthorizationScopes.fullName,
],
nonce: getAppleNonce(),
),
);
// google
await signInWithIdToken(
provider: Provider.google,
idToken: idToken,
dependency: await GoogleSignIn().signIn(),
); The platform interface for these would work because we only need the data from them. The one responsible for calling the actual platform method (and adding the dependency) is the developer. |
@bdlukaa |
Not really. This would make the sign in with apple feature optional to the developer |
@bdlukaa |
To be honest, I would wait with the removal of the I don't think the semi integration proposed here is future-proof, because that way may not always work in the future or for every other provider. Maybe other providers don't even provide a platform interface package. I would rather make it completely inclusive, like creating a new package that holds these native helpers (solution 3), or doing only documentation (solution 2). |
Yeah, we are in a weird position especially for Google login, because the official Google login package isn't a viable option for us, and we have to go with flutter_appauth package. There are a lot of moving parts here. I said it might be worth exploring, because we are just brain storming possible ideas here and I wanted here to be a safe place to talk about whatever ideas that come to our minds. With the current situations though, the proposal of adding a For the time being though, I've proposed to go with option 2 for now, and see how the community reacts and if there seems to be a huge demand for a simpler way of implementing native auth, we can consider option 3 here, but do we have a strong objection against this route? Also maybe instead of getting rid of |
I am going to close this issue as all the tasks on this issue is complete. |
The criteria for having a successful native authentication process is the ability to do the following:
Sign in on Google working on Android, iOS, and Web
When using sign in with Google, you're currently limited to having sign in with Google on either Android and Web, or iOS. The reason for this is because on GCP, you create credentials and you choose the type of device that the OAuth client is. The web application credentials work for both Android and Web where as for iOS, you're required to use the iOS credentials. Supabase only has a slot for a single client ID/Secret.
This PR is also required for us to pass in a Nonce when using iOS
google/GoogleSignIn-iOS#244
Sign in with Apple working on Android, iOS, and Web
I was able to get iOS working on iPhone, but I'm having trouble getting Sign in with Apple working on the web as well. These are the instructions I'm following but I'll update this when I / others have better luck setting this up
https://pub.dev/packages/sign_in_with_apple
When creating an account with social auth, you can then link your email with it.
When creating an account with Google the user's email address is registered inside the
auth.users
table. A user can then link their accounts by following the forgot password route with the same email.When creating an account with Apple, depending on the user's preferences, either the plain text email or the private email is registered inside
auth.users
. A user can then link their accounts by following the forgot password route with the same email. This is only possible if the user does not use Apples's private email, but Apple users are aware of this.When creating an account with email first, you can then link your social auth to it.
This is not possible at the moment. We can an error back stating there's a duplicate of the email already. I've read that toggling
isSSO
fixes this but I haven't tested it yet.The text was updated successfully, but these errors were encountered: