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

provider.SignInWithOAuth() throws exception. #3

Closed
achabill opened this issue Sep 2, 2016 · 9 comments
Closed

provider.SignInWithOAuth() throws exception. #3

achabill opened this issue Sep 2, 2016 · 9 comments
Labels

Comments

@achabill
Copy link

achabill commented Sep 2, 2016

Exception: "Response status code does not indicate success: 400" when I call SignInWithOAuth
var auth = await provider.SignInWithOAuthAsync(FirebaseAuthType.Facebook, facebookAccessToken);
The facebookAccessToken is generated properly and I use Firebase Browser APIKey for FirebaseConfig
UWP 10.0

Stack trace:
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() at Firebase.Auth.FirebaseAuthProvider.<SignInWithPostContentAsync>d__16.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable``1.ConfiguredTaskAwaiter.GetResult() at Firebase.Auth.FirebaseAuthProvider.<SignInWithOAuthAsync>d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter``1.GetResult() at simple_social_media.MainPage.<mainlogin_Click>d__1.MoveNext()

Could the problem be at my end?

@bezysoftware
Copy link
Collaborator

bezysoftware commented Sep 5, 2016

Can you try the latest version of the package (v2.0.1)? In case of an error it throws a FirebaseAuthException which should contain all information you should need to debug it (target url, post data and most imporantly responseData, which should contain the reason for the error).

@achabill
Copy link
Author

achabill commented Sep 5, 2016

Thank you for the update.

I get "invalid key" as reason in exception.
Here is what I have, don't know where I am going wrong.
Privacy of keys does not matter. It's all for testing purposes.

The first option gets the idtoken from Auth0 and creates the fireabse token with firebaseAuthentication
The second option generates the firebase auth token from Auth0 .

//KEYS AND IDs
const string FirebaseApiKey = "463216751920-ng92hpkvcq6j9jjud8m3ov0tmfov6ou6.apps.googleusercontent.com";
const string FirebaseBaseURL = "https://simplesocialmedia-7a3a2.firebaseio.com/";
const string FirebaseClientId = "463216751920-npspguchren5atatb2f1le7ec0uooqb0.apps.googleusercontent.com";
const string FirebaseSecret = "iAnU0wTbyLU2ZpWSU1IpeDjj";
const string Auth0ClientId = "VWjSXo9F4xPLlAm2KMyrLoK8mWwshXb4";
const string Auth0Domain = "simplesocialmedia.auth0.com";

private async void Auth0Login()
{
    var firebase = new FirebaseClient(FirebaseBaseURL);
    var auth0 = new Auth0Client(Auth0Domain, Auth0ClientId);
    MessageDialog _ms;

    var user = await auth0.LoginAsync();
    /*
     Auth0AccessToken : "mxSKgCo6SbC87CUR"
     IdToken: ""eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3NpbXBsZXNvY2lhbG1lZGlhLmF1dGgwLmNvbS8iLCJzdWIiOiJmYWNlYm9va3wxMzkyNTM5Nzk3NDQyODcwIiwiYXVkIjoiVldqU1hvOUY0eFBMbEFtMktNeXJMb0s4bVd3c2hYYjQiLCJleHAiOjE0NzMxMjMzMTgsImlhdCI6MTQ3MzA4NzMxOH0.wxgoxq1haDtjhS0nJlxN_Rc78fl_C6Ow0jrcxpKThy4"
     Profile: part of it below
     RefreshToken: ""
    */

    var idToken = user.IdToken;             //token for external APIs
    var auth0Token = user.Auth0AccessToken; //token for auth0 APIs

    var profile = user.Profile;
    /*
    {
    "context":{
        "identities": [{ "provider": "facebook",  "user_id": "1392539797442870",   "connection": "facebook",  "isSocial": true    } ]
    }
    */

    var connection = profile["context"]["identities"]["connection"].ToString();

///////////////////////////////////////////////////////////////////////////////////////////

    //gerneate firebase auth token with Firebase.Auth
    var provider = new FirebaseAuthProvider(new FirebaseConfig(FirebaseApiKey));
    FirebaseAuthType authType;
    if (connection == "facebook")
        authType = FirebaseAuthType.Facebook;
    else if (connection == "google")
        authType = FirebaseAuthType.Google;
    else
        return;

    try
    {
        var auth = await provider.SignInWithOAuthAsync(authType, idToken);
        var result = await firebase.Child("users").WithAuth(auth.FirebaseToken).PostAsync(new MyUser { FirstName = "A", LastName = "B" });
        _ms = new MessageDialog(result.Key + "\n");
        await _ms.ShowAsync();
    }
    catch
    {
        //Exception: FirebaseAuthException
        //reason: Invalid key
        //From SignInWithOAuthAsync(...)
        _ms = new MessageDialog("error step 1");
        await _ms.ShowAsync();
    }

///////////////////////////////////////////////////////////////////////////////////////////

    //generate firebase auth token from Auth0
    var token = await auth0.GetDelegationToken("firebase", idToken, user.RefreshToken, Auth0ClientId);
    /*
    {
     {  
      "token_type": "Bearer",  
      "expires_in": 36000,  
      "id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3NpbXBsZXNvY2lhbG1lZGlhLmF1dGgwLmNvbS8iLCJzdWIiOiJmYWNlYm9va3wxMzkyNTM5Nzk3NDQyODcwIiwiYXVkIjoiVldqU1hvOUY0eFBMbEFtMktNeXJMb0s4bVd3c2hYYjQiLCJleHAiOjE0NzMxMjQ1ODIsImlhdCI6MTQ3MzA4ODU4MiwidiI6MCwiZCI6eyJmYl9pZCI6ImZhY2Vib29rfDEzOTI1Mzk3OTc0NDI4NzAifSwiYXpwIjoiVldqU1hvOUY0eFBMbEFtMktNeXJMb0s4bVd3c2hYYjQifQ.Nf2A6TVFzsIsZCZ7-ejiwdeU54oKQZ-gi-tB2FR1xns"
    }
   }
   */
    var firebaseToken = token["id_token"].ToString();
    try
    {
        var _result = await firebase.Child("users").WithAuth(firebaseToken).PostAsync(new MyUser { FirstName = "A", LastName = "B" }); //exception here.
        _ms = new MessageDialog(_result.Key + "\n"); //show result
        await _ms.ShowAsync();
    }
    catch
    {
        //HTTP exception: Response status code does not indicate success: 400
        //From: firebase.Child(..).WidthAuth(...)
        _ms = new MessageDialog("error step 2");
        await _ms.ShowAsync();
    }

} 

//////////////////////////////////////////////////////////////////////////////////////////

public class MyUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

I've also tried generating the access token using winfbsdk (which worked well) before passing in SignInWidthOAuthAsync(). Getting the same results.

I've checked all loose ends. Don't know what is causing this. Maybe I'm not using the tokens or keys correctly.

@bezysoftware
Copy link
Collaborator

bezysoftware commented Sep 11, 2016

I never worked with Auth0 so I'm not sure what kind of tokens it generates. Check out the samples (I just pushed them), they may help.

@ngducnghia
Copy link

ngducnghia commented Sep 26, 2016

I have similar problem.

{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "keyInvalid",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}

var firebase = new FirebaseClient("https://myapp.firebaseio.com/"); var authProvider = new FirebaseAuthProvider(new FirebaseConfig("myFirebaseScerectMechmFmi6")); FirebaseAuthLink authEmail = await authProvider.CreateUserWithEmailAndPasswordAsync(username, password);

@ngducnghia
Copy link

ngducnghia commented Sep 26, 2016

I think the problem is with the Legacy Firebase App, I created another one and it does works for me.
@bezysoftware can you confirm this?

@bezysoftware
Copy link
Collaborator

Can I still create "legacy" app in the current Firebase console?

@ngducnghia
Copy link

Yes I can still create using my current Firebase legacy account, not sure if you can still create new account. It's on https://www.firebase.com/

@stale
Copy link

stale bot commented Oct 3, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 3, 2019
@stale
Copy link

stale bot commented Oct 10, 2019

Closing the issue due to inactivity. Feel free to re-open

@stale stale bot closed this as completed Oct 10, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants