Coder Social home page Coder Social logo

Comments (4)

cabauman avatar cabauman commented on May 30, 2024

The author may have a more general solution, but I'll go ahead and put in my two cents.

Since you're using Xamarin, you can use the AccountStore in the Xamarin.Auth package:
Github
Docs

When saving, you can add your own properties to the account. For example, I have a CredentialsService class with a property to save the FirebaseAuth json:

public string FirebaseAuthJson
{
    get
    {
        return _account?.Properties["FirebaseAuthJson"];
    }

    set
    {
        if(_account != null)
        {
            _account.Properties["FirebaseAuthJson"] = value;
            AccountStore.Create().Save(_account, SERVICE_ID);
        }
    }
}

So you can set it like this:

string json = JsonConvert.SerializeObject(firebaseAuth);
credentialsService.FirebaseAuthJson = json;

And retrieve like this:

var account = AccountStore.Create().FindAccountsForService(App.AppName).FirstOrDefault();
if(account == null)
{
    SignInAnonymously();
}
else
{
    string json = account.Properties ["FirebaseAuthJson"];
    FirebaseAuth  auth = JsonConvert.DeserializeObject<FirebaseAuth>(json);
    var authProvider = new FirebaseAuthProvider(new FirebaseConfig(Config.ApiKeys.FIREBASE));
    FirebaseAuthLink  authLink = new FirebaseAuthLink(authProvider, auth);
    ...
    // Now you can do some more verification
}

from firebase-authentication-dotnet.

bezysoftware avatar bezysoftware commented on May 30, 2024

That's pretty much what I do - I save the user information into storage (ApplicationDataContainer in UWP) and during startup I check if there is any info there.

from firebase-authentication-dotnet.

EmilAlipiev avatar EmilAlipiev commented on May 30, 2024

thats not a correct approach, i believe. FirebaseToken is a JWT and it contains expiry date information or even though sigin functions have expiry date information. you should verify that it is not expired. if expired refresh token. even though, token can be invalidated for different reason before expiry dates. for example, if user changes, his password or deleting account on other device etc. better to always user verify token function. it doesnt have to be because if token is invalid, other actions like database access will return an exception. but at least do offline expiry date check

from firebase-authentication-dotnet.

cabauman avatar cabauman commented on May 30, 2024

@EmilAlipiev You're correct. My answer was outdated. You have to save the whole FirebaseAuth object because it contains the needed info for refreshing. And yes, it's good to do extra verification after the auth object is retrieved.

I edited my previous reply to reflect these points.

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.