Coder Social home page Coder Social logo

Comments (9)

bezysoftware avatar bezysoftware commented on May 31, 2024 1

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).

from firebase-authentication-dotnet.

achabill avatar achabill commented on May 31, 2024

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.

from firebase-authentication-dotnet.

bezysoftware avatar bezysoftware commented on May 31, 2024

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.

from firebase-authentication-dotnet.

ngducnghia avatar ngducnghia commented on May 31, 2024

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);

from firebase-authentication-dotnet.

ngducnghia avatar ngducnghia commented on May 31, 2024

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?

from firebase-authentication-dotnet.

bezysoftware avatar bezysoftware commented on May 31, 2024

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

from firebase-authentication-dotnet.

ngducnghia avatar ngducnghia commented on May 31, 2024

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/

from firebase-authentication-dotnet.

stale avatar stale commented on May 31, 2024

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.

from firebase-authentication-dotnet.

stale avatar stale commented on May 31, 2024

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

from firebase-authentication-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.