aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-10-16 17:31:51 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-10-16 17:31:51 +0300
commit4954a924b8a5b8fd7a213a444027e74b936359be (patch)
treed91859a5fadf3d21b7fca106a000b30365f78a1b /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs
parent583d3716e37a9be80c8bb248215f343ed4fcd2d1 (diff)
downloadTango-4954a924b8a5b8fd7a213a444027e74b936359be.tar.gz
Tango-4954a924b8a5b8fd7a213a444027e74b936359be.zip
Added support for token authentication from MS to DB.
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();
}
}
}