supabase-community / supabase-csharp

A C# Client library for Supabase
https://github.com/supabase-community/supabase-csharp/wiki
MIT License
499 stars 50 forks source link

OAuth + Supabase + Native Android(MAUI, Xamarin Forms, Xamarin Android) #99

Closed Phantom-KNA closed 1 year ago

Phantom-KNA commented 1 year ago

I have implemented authentication with Google in Android, I am using SignInWithIdToken passing Google's response IdToken or RequestIdToken as a parameter but it gives an error, that I am missing.

{"error":"invalid request","error_description":"Bad ID token"}

Phantom-KNA commented 1 year ago

Well i found the problem. If is possible when i can create a new documentation for new user. This is the example for Xamarin Android, Xamarin Forms, or MAUI.

`string identityToken = Encoding.UTF8.GetString(System.Text.Encoding.UTF8.GetBytes(GoogleOrAppleIdToken), 0, GoogleOrAppleIdToken.Length);

var user = await Supabase.Auth.SignInWithIdToken(Provider.Google, identityToken);`

@acupofjose @rhuanbarros

Phantom-KNA commented 1 year ago

Well this method SignInWithIdToken only work for existing user. Any comment for New User with OAuth Native Android?

wiverson commented 1 year ago

Double check to make sure Project Settings -> Auth -> User Signups is turned on. Other than that not sure off the cuff, possible something isn't quite right in the choreography hitting the server and getting the session back. If you have the cycles right now you can try checking with a debugger to see if the API from the server is returning a response or not...

https://github.com/supabase-community/gotrue-csharp/blob/f3695d5abbf35e4f0b59ef744e42f664cfb535cb/Gotrue/Client.cs#L200

wiverson commented 1 year ago

Also btw I've used that method for the native Sign in with Apple flow but not the OAuth flow, very interesting to doc that flow...

string identityToken = Encoding.UTF8.GetString(System.Text.Encoding.UTF8.GetBytes(GoogleOrAppleIdToken), 0, GoogleOrAppleIdToken.Length);

Phantom-KNA commented 1 year ago

Double check to make sure Project Settings -> Auth -> User Signups is turned on. Other than that not sure off the cuff, possible something isn't quite right in the choreography hitting the server and getting the session back. If you have the cycles right now you can try checking with a debugger to see if the API from the server is returning a response or not...

https://github.com/supabase-community/gotrue-csharp/blob/f3695d5abbf35e4f0b59ef744e42f664cfb535cb/Gotrue/Client.cs#L200

{"error":"server_error","error_description":"Internal Server Error"} This is a error, i used other log info but nothing.

This Exception helps: Console.WriteLine(ex.HelpLink); Console.WriteLine(ex.InnerException); Console.WriteLine(ex.Message); Console.WriteLine(ex.Source);

Phantom-KNA commented 1 year ago

Also btw I've used that method for the native Sign in with Apple flow but not the OAuth flow, very interesting to doc that flow...

string identityToken = Encoding.UTF8.GetString(System.Text.Encoding.UTF8.GetBytes(GoogleOrAppleIdToken), 0, GoogleOrAppleIdToken.Length);

Well i used your example with little fix for Google, THX to you.

wiverson commented 1 year ago

If you attach a debugger it's possible that there is more info in the base response, but maybe not.

If it works for existing user but not a new user not sure. If you create a user via sign in with email for the same address first does that work? Any other logic (eg creating a user profile via trigger) that could be affecting things?

If it's straight up a server challenge might check the server logs for info and/or open a support ticket?

Phantom-KNA commented 1 year ago

Hey bro thank you soo much i enable the doubletap User Signups Allow new users to sign up and work fine. I dont know why is disabled.

If you attach a debugger it's possible that there is more info in the base response, but maybe not.

If it works for existing user but not a new user not sure. If you create a user via sign in with email for the same address first does that work? Any other logic (eg creating a user profile via trigger) that could be affecting things?

If it's straight up a server challenge might check the server logs for info and/or open a support ticket?

Hey bro thank yu soo much i enable the doubletap User Signups Allow new users to sign up and work fine. I dont know why is disabled. How can create a new documentation for new user? This problem a tried to work on my app one day of work. P.D: Sorry for my English

wiverson commented 1 year ago

Woot! Glad you got it working!

RE: adding docs, easy mode: you can just write up docs in Markdown and post as a public gist and add an issue to add to the repo. Alternatively you can send in a PR if you are feeling fancy.

Phantom-KNA commented 1 year ago

Woot! Glad you got it working!

RE: adding docs, easy mode: you can just write up docs in Markdown and post as a public gist and add an issue to add to the repo. Alternatively you can send in a PR if you are feeling fancy.

OAuth(Google) + Supabase + Native Android(MAUI, Xamarin Forms, Xamarin Android)

wiverson commented 1 year ago

https://gist.github.com/Phantom-KNA/9096bf443beaab0dd45cca5e9eaf4ccc

acupofjose commented 1 year ago

Thank y'all for the work debugging/troubleshooting this! Documentation is now available on the wiki for it here