Skip to content

Fix tokens not refreshing when calling RefreshToken() or RetrieveSessionAsync() #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pBlackCreek
Copy link

What kind of change does this PR introduce?

Removed the expiry checks from RefreshToken() and RetrieveSessionAsync() to fix tokens not refreshing when access token is expired.

What is the current behavior?

When RetrieveSessionAsync() is called the expiry is checked and assumes that the session is invalid.
The same check happens in RefreshToken() before actually trying to refresh it, causing it to never properly try to refresh the tokens.

What is the new behavior?

If the access token has expired and AutoRefreshToken is enabled RetrieveSessionAsync() wil try to refresh the tokens.
And when manually calling RefreshToken() the method will continue to refresh the token

Additional context

It seems like it was assumed that the expiry was for the whole session, but it is specifically for the access token.

This would close issue #108 and PR #106

@mcombalia
Copy link

I think there is also a problem in the TokenRefresh, were the client signsout the user in the refresh token function, by checking the access token expiry date instead:


private void CreateNewTimer()
		{
			if (_client.CurrentSession == null || _client.CurrentSession.ExpiresIn == default)
			{
				if (Debug)
					_client.Debug($"No session, refresh timer not started");
				return;
			}

			if (_client.CurrentSession.Expired())
			{
				if (Debug)
					_client.Debug($"Token expired, signing out");
				// TODO: CHECK THIS COULD BE WRONG
				// _client.NotifyAuthStateChange(SignedOut);
				return;
			}

			try
			{
				TimeSpan interval = GetInterval();
				_refreshTimer?.Dispose();
				_refreshTimer = new Timer(HandleRefreshTimerTick, null, interval, Timeout.InfiniteTimeSpan);

				if (Debug)
					_client.Debug($"Refresh timer scheduled {interval.TotalMinutes} minutes");
			}
			catch (Exception e)
			{
				if (Debug)
					_client.Debug($"Failed to initialize refresh timer", e);
			}
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants