diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-02-24 13:38:47 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-02-24 13:38:47 +0200 |
| commit | 64b768178dc9e64293a52c1b6d2631709af9502a (patch) | |
| tree | 6b7782fdbbbab4f734a1cb499cca03728c4f8f69 /Software/Visual_Studio/Tango.Web | |
| parent | 028ab0e5cc2699ceec3e04b1eeab5f56b9b38083 (diff) | |
| download | Tango-64b768178dc9e64293a52c1b6d2631709af9502a.tar.gz Tango-64b768178dc9e64293a52c1b6d2631709af9502a.zip | |
Removed all refresh tokens use :/
Diffstat (limited to 'Software/Visual_Studio/Tango.Web')
8 files changed, 33 insertions, 92 deletions
diff --git a/Software/Visual_Studio/Tango.Web/ExtensionMethods/CloudTableExtensions.cs b/Software/Visual_Studio/Tango.Web/ExtensionMethods/CloudTableExtensions.cs index 43c4804d3..ffffe6950 100644 --- a/Software/Visual_Studio/Tango.Web/ExtensionMethods/CloudTableExtensions.cs +++ b/Software/Visual_Studio/Tango.Web/ExtensionMethods/CloudTableExtensions.cs @@ -15,10 +15,10 @@ public static class CloudTableExtensions /// <param name="partitionKey">Partition key - i.e., last name</param> /// <param name="rowKey">Row key - i.e., first name</param> /// <returns>A Task object</returns> - public static async Task<T> GetEntityAsync<T>(this CloudTable table, string partitionKey, string rowKey) where T : class, ITableEntity + public static T GetEntity<T>(this CloudTable table, string partitionKey, string rowKey) where T : class, ITableEntity { TableOperation retrieveOperation = TableOperation.Retrieve<T>(partitionKey, rowKey); - TableResult result = await table.ExecuteAsync(retrieveOperation); + TableResult result = table.Execute(retrieveOperation); T customer = result.Result as T; return customer; } @@ -33,7 +33,7 @@ public static class CloudTableExtensions /// <param name="table">The sample table name</param> /// <param name="entity">The entity to insert or merge</param> /// <returns>A Task object</returns> - public static async Task<T> InsertOrUpdateEntityAsync<T>(this CloudTable table, T entity) where T : class, ITableEntity + public static T InsertOrUpdateEntity<T>(this CloudTable table, T entity) where T : class, ITableEntity { if (entity == null) { @@ -41,10 +41,10 @@ public static class CloudTableExtensions } // Create the InsertOrReplace table operation - TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entity); + TableOperation insertOrMergeOperation = TableOperation.InsertOrReplace(entity); // Execute the operation. - TableResult result = await table.ExecuteAsync(insertOrMergeOperation); + TableResult result = table.Execute(insertOrMergeOperation); T insertedCustomer = result.Result as T; return insertedCustomer; @@ -56,7 +56,7 @@ public static class CloudTableExtensions /// <param name="table">Sample table name</param> /// <param name="deleteEntity">Entity to delete</param> /// <returns>A Task object</returns> - public static async Task DeleteEntityAsync<T>(this CloudTable table, T deleteEntity) where T : class, ITableEntity + public static void DeleteEntity<T>(this CloudTable table, T deleteEntity) where T : class, ITableEntity { if (deleteEntity == null) { @@ -64,6 +64,6 @@ public static class CloudTableExtensions } TableOperation deleteOperation = TableOperation.Delete(deleteEntity); - await table.ExecuteAsync(deleteOperation); + table.Execute(deleteOperation); } } diff --git a/Software/Visual_Studio/Tango.Web/Security/RefreshTokenEntity.cs b/Software/Visual_Studio/Tango.Web/Security/RefreshTokenEntity.cs deleted file mode 100644 index 839027ca1..000000000 --- a/Software/Visual_Studio/Tango.Web/Security/RefreshTokenEntity.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Microsoft.WindowsAzure.Storage.Table; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Web.Security -{ - public class RefreshTokenEntity : TableEntity - { - /// <summary> - /// Initializes a new instance of the <see cref="RefreshTokenEntity"/> class. - /// </summary> - public RefreshTokenEntity() - { - - } - - public String RefreshToken { get; set; } - public String AccessToken { get; set; } - public DateTime Expiration { get; set; } - } -} diff --git a/Software/Visual_Studio/Tango.Web/Security/RenewTokenRequest.cs b/Software/Visual_Studio/Tango.Web/Security/RenewTokenRequest.cs deleted file mode 100644 index 213cd3afd..000000000 --- a/Software/Visual_Studio/Tango.Web/Security/RenewTokenRequest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.Web.Security -{ - public class RenewTokenRequest : WebRequestMessage - { - public String RefreshToken { get; set; } - } -} diff --git a/Software/Visual_Studio/Tango.Web/Security/RenewTokenResponse.cs b/Software/Visual_Studio/Tango.Web/Security/RenewTokenResponse.cs deleted file mode 100644 index 76c381852..000000000 --- a/Software/Visual_Studio/Tango.Web/Security/RenewTokenResponse.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.Web.Security -{ - public class RenewTokenResponse : WebTokenResponse - { - - } -} diff --git a/Software/Visual_Studio/Tango.Web/Security/WebToken.cs b/Software/Visual_Studio/Tango.Web/Security/WebToken.cs index 006ed9de7..7aa4860ab 100644 --- a/Software/Visual_Studio/Tango.Web/Security/WebToken.cs +++ b/Software/Visual_Studio/Tango.Web/Security/WebToken.cs @@ -38,12 +38,15 @@ namespace Tango.Web.Security builder = builder.ExpirationTime(expiration.Value); } + String refreshToken = Guid.NewGuid().ToString(); + builder = builder.AddClaim("object", null); + builder = builder.AddClaim("refresh-token", refreshToken); return new WebToken() { AccessToken = builder.Build(), - RefreshToken = Guid.NewGuid().ToString(), + RefreshToken = refreshToken, Expiration = expiration, Issued = issued, }; @@ -65,11 +68,10 @@ namespace Tango.Web.Security .Decode(AccessToken); } - public WebToken Renew(String secret, String token) + public WebToken Renew(String secret) { - WebToken webToken = WebToken.FromToken(token); - var newToken = CreateNew(secret, DateTime.UtcNow.Add(webToken.Expiration.Value - webToken.Issued)); - newToken.RefreshToken = webToken.RefreshToken; + var newToken = CreateNew(secret, DateTime.UtcNow.Add(Expiration.Value - Issued)); + newToken.RefreshToken = RefreshToken; return newToken; } @@ -95,6 +97,11 @@ namespace Tango.Web.Security webToken.Issued = ConvertEpochToDateTime(iat); } + if (payload.ContainsKey("refresh-token")) + { + webToken.RefreshToken = payload["refresh-token"].ToString(); + } + return webToken; } @@ -128,12 +135,15 @@ namespace Tango.Web.Security builder = builder.ExpirationTime(expiration.Value); } + String refreshToken = Guid.NewGuid().ToString(); + builder = builder.AddClaim("object", obj); + builder = builder.AddClaim("refresh-token", refreshToken); return new WebToken<T>() { AccessToken = builder.Build(), - RefreshToken = Guid.NewGuid().ToString(), + RefreshToken = refreshToken, Expiration = expiration, Issued = issued, Object = obj, @@ -162,16 +172,20 @@ namespace Tango.Web.Security webToken.Issued = ConvertEpochToDateTime(iat); } + if (payload.ContainsKey("refresh-token")) + { + webToken.RefreshToken = payload["refresh-token"].ToString(); + } + webToken.Object = JsonConvert.DeserializeObject<T>(payload["object"].ToString()); return webToken; } - public new WebToken<T> Renew(String secret, String token) + public new WebToken<T> Renew(String secret) { - WebToken<T> webToken = WebToken<T>.FromToken(token); - var newToken = WebToken<T>.CreateNew(secret, webToken.Object, DateTime.UtcNow.Add(webToken.Expiration.Value - webToken.Issued)); - newToken.RefreshToken = webToken.RefreshToken; + var newToken = WebToken<T>.CreateNew(secret, Object, DateTime.UtcNow.Add(Expiration.Value - Issued)); + newToken.RefreshToken = RefreshToken; return newToken; } } diff --git a/Software/Visual_Studio/Tango.Web/Security/WebTokenResponse.cs b/Software/Visual_Studio/Tango.Web/Security/WebTokenResponse.cs index 8c8f2f096..e68305fbb 100644 --- a/Software/Visual_Studio/Tango.Web/Security/WebTokenResponse.cs +++ b/Software/Visual_Studio/Tango.Web/Security/WebTokenResponse.cs @@ -10,6 +10,5 @@ namespace Tango.Web.Security public class WebTokenResponse : WebResponseMessage { public String AccessToken { get; set; } - public String RefreshToken { get; set; } } } diff --git a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj index 621014496..b16473a96 100644 --- a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj +++ b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj @@ -248,9 +248,6 @@ <Link>GlobalVersionInfo.cs</Link> </Compile> <Compile Include="ActiveDirectory\ActiveDirectoryManager.cs" /> - <Compile Include="Security\RefreshTokenEntity.cs" /> - <Compile Include="Security\RenewTokenResponse.cs" /> - <Compile Include="Security\RenewTokenRequest.cs" /> <Compile Include="Security\WebTokenResponse.cs" /> <Compile Include="Security\TokensManager.cs" /> <Compile Include="Security\WebToken.cs" /> diff --git a/Software/Visual_Studio/Tango.Web/TangoWebClient.cs b/Software/Visual_Studio/Tango.Web/TangoWebClient.cs index 08fc19099..1d2f9fc8e 100644 --- a/Software/Visual_Studio/Tango.Web/TangoWebClient.cs +++ b/Software/Visual_Studio/Tango.Web/TangoWebClient.cs @@ -70,29 +70,13 @@ 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 Renew(); - //await Login(_lastLoginRequest); + await Login(_lastLoginRequest); } } @@ -105,8 +89,7 @@ namespace Tango.Web { try { - //await Login(_lastLoginRequest); - await Renew(); + await Login(_lastLoginRequest); var response = await _client.PostJson<TRequest, TResponse>(GetActionAddress(action), request); return response; } |
