private static async Task <string> GetToken()
        {
            _auth = await _auth.GetFreshAuthAsync();

            // Console.WriteLine("Token : {0}", _auth.FirebaseToken);
            return(_auth.FirebaseToken);
        }
Exemple #2
0
 public async Task <string> refreshToken(FirebaseAuthLink auth) //Function returns the authentication token
 {
     if (auth.IsExpired())                                      //Have not tested this part of the code yet as expiry takes 3600 seconds, no thanks
     {
         await auth.GetFreshAuthAsync();
     }
     return(auth.FirebaseToken);
 }
        public async Task <string> GetFreshTokenAsync()
        {
            Console.WriteLine("token before: {0}", LoadAuth().FirebaseToken);
            var auth = new FirebaseAuthLink(authProvider, LoadAuth());

            auth = await auth.GetFreshAuthAsync();

            Console.WriteLine("token after: {0}", auth.FirebaseToken);

            SaveAuth(auth);

            return(auth.FirebaseToken);
        }
Exemple #4
0
        public async Task <string> GetFirebaseAuthToken()
        {
            if (!_didInit)
            {
                InitFirebaseAuth();
                _didInit = true;
            }

            // This will refresh the auth object/token if it's expired.
            _authLink = await _authLink.GetFreshAuthAsync();

            return(_authLink.FirebaseToken);
        }
Exemple #5
0
        public void RefreshAccessToken()
        {
            FirebaseAuthProvider authProvider = new FirebaseAuthProvider(new FirebaseConfig(ApiKey));

            FirebaseAuthLink auth          = authProvider.SignInWithOAuthAsync(FirebaseAuthType.Facebook, FacebookAccessToken).Result;
            string           originalToken = auth.FirebaseToken;

            // simulate the token already expired
            auth.Created = DateTime.MinValue;

            FirebaseAuthLink freshAuth = auth.GetFreshAuthAsync().Result;

            freshAuth.FirebaseToken.Should().NotBe(originalToken);
        }
        public static async Task updateTokenAsync(FirebaseAuthLink res)
        {
            firebase.userLink = res;
            res.RefreshUserDetails().Wait();
            var content = (await res.GetFreshAuthAsync());

            var serilized_content = JsonConvert.SerializeObject(content);

            Preferences.Set("serilizedUser", serilized_content);


            firebase.currentUser = res.User;
            Preferences.Set("email", res.User.Email);
            await firebase.initRealtimeDatabaseAsync(res.FirebaseToken);
        }
Exemple #7
0
        public async Task CreateAccount(string email, string password)
        {
            var authProvider = new FirebaseAuthProvider(new FirebaseConfig(Credentials.FirebaseApiKey));

            try
            {
                // Store and signUp the user with email and password
                FirebaseAuthLink userData = await authProvider.CreateUserWithEmailAndPasswordAsync(email, password);

                // Refresh user token as it needs to be valid always
                await userData.GetFreshAuthAsync();

                IsRegistrationSucceeded = true;
                new MessageDialog("Account created successfully!");
            }
            catch (Exception e)
            {
                IsRegistrationSucceeded = false;
                await new MessageDialog(e.Message).ShowAsync();
            }
        }
Exemple #8
0
        public async Task SignInUser(string email, string password)
        {
            var authProvider = new FirebaseAuthProvider(new FirebaseConfig(Credentials.FirebaseApiKey));

            try
            {
                // Store and sign in user with email and password
                _userData = await authProvider.SignInWithEmailAndPasswordAsync(email, password);

                // Refresh user token as it needs to be valid always
                await _userData.GetFreshAuthAsync();

                // Set signed in state to true
                IsSignedIn = true;
            }
            catch (Exception e)
            {
                // if the user is signed in, then it gets him signed out
                IsSignedIn = false;

                //await new MessageDialog(e.Message).ShowAsync();
            }
        }
 /// <inheritdoc />
 public async Task <string> GetIdTokenAsync(bool forceRefresh)
 {
     return((await _authLink.GetFreshAuthAsync()).FirebaseToken);
 }