Aleksandr
Aleksandr

Reputation: 31

How to add Firebase Google Authentication in .NET MAUI

I am trying to integrate Firebase Authentication to .NET MAUI Application. After creating project in Visual Studio, i create project in Firebase Console and addind SHA-1, which i get with this request in cmd: "keytool -list -v -keystore C:\Users\user.android\debug.keystore -alias androiddebugkey -storepass android -keypass android". I also enable Google in Authentication Methods in Firebase Console. After this i add "goolge-services.json" to my MAUI Project(in Platforms->Android) After this i add to my MAUI app NuGet package "FirebaseAuthentication.net" from "Step Up Labs", here is GitHub link: "https://github.com/step-up-labs/firebase-authentication-dotnet/tree/master". Below you can see my code: In var "coinfig", APIKey i get from FirebaseConsole Project Settings in field "Web API Key", AuthDomain i get from Firebase->Authentications->Authorized Domains. And also you can see var "token", ehich i get from FirebaseConsole->Authentication->AuthenticationMethods->Google->Web SDK configuration->"Web client ID"(i also try "Web client secret"). BUT everytime i get error

Firebase.Auth.FirebaseAuthHttpException: "Exception occured during Firebase Http request. Url: https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?key=myapikey Request Data: {"requestUri":"https://projectname-7fec3.firebaseapp.com","postBody":"access_token=mytoken","returnIdpCredential":true,"returnSecureToken":true} Response: { "error": { "code": 400, "message": "INVALID_IDP_RESPONSE : Unsuccessful check authorization response from Google: {\n "error_description": "Invalid Value"\n}\n", "errors": [ { "message": "INVALID_IDP_RESPONSE : Unsuccessful check authorization response from Google: {\n "error_description": "Invalid Value"\n}\n", "domain": "global", "reason": "invalid" } ] } }

Reason: Unknown

I am pleasure for anyone help. Maybe i missed anything.

  private async void OnCounterClicked(object sender, EventArgs e)
    {
        string token = "myToken.apps.googleusercontent.com";
        var config = new FirebaseAuthConfig
        {
            ApiKey = "myAPIKey",
            AuthDomain = "myDomain.firebaseapp.com",
            Providers = new FirebaseAuthProvider[]
    {
             // Add and configure individual providers
             new GoogleProvider().AddScopes("email"),
             new EmailProvider()
    },
            UserRepository = new FileUserRepository("FirebaseSample")                                                                         
        };
        var client = new FirebaseAuthClient(config);

    var credential = GoogleProvider.GetCredential(token);
    var userCredential = await client.SignInWithCredentialAsync(credential);
}    

Upvotes: 3

Views: 1219

Answers (0)

Related Questions