aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2019-10-30 17:55:39 +0200
committerAvi Levkovich <avi@twine-s.com>2019-10-30 17:55:39 +0200
commit3e22430905c4c247672237a6d64425f3f958626e (patch)
treea0fbf053a2ddf1fefc9f0ae3281fb06e70e5e52e /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
parentcc657620eac3b626cf0790802c2a5ae3196c396b (diff)
parent43113f6b264c8d334393c6116e1858eeec7ca5c6 (diff)
downloadTango-3e22430905c4c247672237a6d64425f3f958626e.tar.gz
Tango-3e22430905c4c247672237a6d64425f3f958626e.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs29
1 files changed, 29 insertions, 0 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
index 7fe1ae36a..3cc5e8b49 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
@@ -18,6 +18,7 @@ using Tango.Core.Helpers;
using Tango.MachineStudio.Common.Web;
using Tango.BL.Builders;
using System.Data.Entity.Core;
+using System.Windows.Threading;
namespace Tango.MachineStudio.UI.Authentication
{
@@ -29,6 +30,7 @@ namespace Tango.MachineStudio.UI.Authentication
public class DefaultAuthenticationProvider : ExtendedObject, IAuthenticationProvider
{
private MachineStudioWebClient _client;
+ private DispatcherTimer _refreshTokenTimer;
private User _currentUser;
/// <summary>
@@ -57,6 +59,28 @@ namespace Tango.MachineStudio.UI.Authentication
public DefaultAuthenticationProvider(MachineStudioWebClient machineStudioWebClient)
{
_client = machineStudioWebClient;
+
+ _refreshTokenTimer = new DispatcherTimer();
+ _refreshTokenTimer.Interval = TimeSpan.FromMinutes(30);
+ _refreshTokenTimer.Tick += _refreshTokenTimer_Tick;
+ _refreshTokenTimer.Stop();
+ }
+
+ private async void _refreshTokenTimer_Tick(object sender, EventArgs e)
+ {
+ if (ObservablesContext.GetActualDataSource().Type == DataSourceType.AccessToken)
+ {
+ try
+ {
+ LogManager.Log("Refreshing database access token...");
+ var response = await _client.RefreshToken(new RefreshTokenRequest());
+ ObservablesContext.UpdateAccessToken(response.AccessToken, response.Expiration);
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error occurred while trying to refresh the database access token.");
+ }
+ }
}
/// <summary>
@@ -68,6 +92,8 @@ namespace Tango.MachineStudio.UI.Authentication
/// <exception cref="AuthenticationException">Login failed for user " + email</exception>
public AuthenticationLoginResult Login(string email, string password, bool bypassVersionCheck = false)
{
+ _refreshTokenTimer.Stop();
+
var settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>();
_client.Environment = settings.DeploymentSlot;
@@ -135,6 +161,8 @@ namespace Tango.MachineStudio.UI.Authentication
CurrentUser = user;
+ _refreshTokenTimer.Start();
+
return new AuthenticationLoginResult()
{
User = user,
@@ -149,6 +177,7 @@ namespace Tango.MachineStudio.UI.Authentication
public void Logout()
{
CurrentUser = null;
+ _refreshTokenTimer.Stop();
}
}
}