diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-02-24 00:57:14 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-02-24 00:57:14 +0200 |
| commit | 0adea9eb464a3f2d5d73b2c8c26d32e0d1a3874b (patch) | |
| tree | bb5e4055020aa4417e1f7703a611353ce44689d6 /Software/Visual_Studio/Tango.Web/TangoWebClient.cs | |
| parent | 17612c08da93c75d4c941a643bc7602c18f351d8 (diff) | |
| download | Tango-0adea9eb464a3f2d5d73b2c8c26d32e0d1a3874b.tar.gz Tango-0adea9eb464a3f2d5d73b2c8c26d32e0d1a3874b.zip | |
Working on refresh tokens...
Diffstat (limited to 'Software/Visual_Studio/Tango.Web/TangoWebClient.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Web/TangoWebClient.cs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/Software/Visual_Studio/Tango.Web/TangoWebClient.cs b/Software/Visual_Studio/Tango.Web/TangoWebClient.cs index 42a9d801c..08fc19099 100644 --- a/Software/Visual_Studio/Tango.Web/TangoWebClient.cs +++ b/Software/Visual_Studio/Tango.Web/TangoWebClient.cs @@ -5,7 +5,7 @@ using System.Security.Authentication; using System.Text; using System.Threading.Tasks; using Tango.Transport.Web; -using Tango.Web.Authentication; +using Tango.Web.Security; namespace Tango.Web { @@ -70,13 +70,29 @@ namespace Tango.Web return response; } + private async Task Renew() + { + var response = await _client.PostJson<RenewTokenRequest, RenewTokenResponse>(GetActionAddress("Renew"), new RenewTokenRequest() + { + RefreshToken = WebToken.RefreshToken, + }); + + Token = response.AccessToken; + _client.AuthenticationToken = Token; + + WebToken = WebToken.FromToken(Token); + + IsAuthenticated = true; + } + protected virtual async Task<TResponse> Post<TRequest, TResponse>(String action, TRequest request) where TRequest : class, IWebRequestMessage where TResponse : class, IWebResponseMessage { if (IsAuthenticated) { if (DateTime.UtcNow >= WebToken.Expiration) { - await Login(_lastLoginRequest); + await Renew(); + //await Login(_lastLoginRequest); } } @@ -89,7 +105,8 @@ namespace Tango.Web { try { - await Login(_lastLoginRequest); + //await Login(_lastLoginRequest); + await Renew(); var response = await _client.PostJson<TRequest, TResponse>(GetActionAddress(action), request); return response; } |
