2
votes

I am using Microsoft.WindowsAzure.MobileServices.MobileServiceClient to authenticate users with their Google accounts and Xamarin.Auth.AccountStore to store tokens. When app runs for first time, AccountStore is empty. User loggs in using MobileServiceClient.LoginAsync method.

    client.LoginAsync(_mainActivity, 
 MobileServiceAuthenticationProvider.Google, "myjobdiary", new Dictionary<string, string>
            {
                { "access_type", "offline" }
            });

Everything works fine, user is authorized and token stored using method..

        public void StoreTokenInSecureStore(MobileServiceUser user)
    {
        var account = new Account(user.UserId);
        account.Properties.Add("token", user.MobileServiceAuthenticationToken);
        _accountStore.Save(account, "myjobdiary");
    }

Now i restart my app and rerieve user from account store using method..

        public MobileServiceUser RetrieveTokenFromSecureStore()
    {
        var accounts = _accountStore.FindAccountsForService("myjobdiary");
        if (accounts != null)
        {
            foreach (var acct in accounts)
            {
                if (acct.Properties.TryGetValue("token", out string token))
                {
                    return new MobileServiceUser(acct.Username)
                    {
                        MobileServiceAuthenticationToken = token
                    };
                }
            }
        }
        return null;
    }

Retrieved user is set to used MobileServiceClient. Now I want to refresh token using MobileServiceClient.RefreshUserAsync method. Exception 'Refresh failed with a 403 Forbidden error. The refresh token was revoked or expired.' occured. mobile apps with azure, refresh tokens

1
when i call .auth/me i am able to see refresh_token. What am I supposed to do with it ?Erik Parso

1 Answers

0
votes
return await client.LoginAsync(
            _mainActivity, MobileServiceAuthenticationProvider.Google, "myjobdiary", new Dictionary<string, string>
            {
                { "access_type", "offline" },
                { "prompt", "consent" }
            });