Skip to content

Commit

Permalink
Session class - set StartTime and TimeOfDeath in SessionRefresh method,
Browse files Browse the repository at this point in the history
fixes #253
  • Loading branch information
wsmelton committed Nov 17, 2021
1 parent 4196aa4 commit 2b0d11f
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions src/Thycotic.SecretServer/classes/authentication/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,6 @@

namespace Thycotic.PowerShell.Authentication
{
public class Request
{
public static IRestResponse AccessToken(string SecretServerHost, string Username, string Password, string ProxyServer, int Timeout = 0)
{
var client = new RestClient(SecretServerHost + "/oauth2/token");
client.Timeout = Timeout;
if (string.IsNullOrEmpty(ProxyServer))
{
client.Proxy = new WebProxy(ProxyServer);
}
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("username", Username);
request.AddParameter("password", Password);
request.AddParameter("grant_type", "password");
IRestResponse response = client.Execute(request);
return response;
}

public static IRestResponse RefreshToken(string SecretServerHost, string TokenValue, string ProxyServer, int Timeout = 0)
{
var client = new RestClient(SecretServerHost + "/oauth2/token");
client.Timeout = Timeout;
if (string.IsNullOrEmpty(ProxyServer))
{
client.Proxy = new WebProxy(ProxyServer);
}
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("refresh_token", TokenValue);
request.AddParameter("grant_type", "refresh_token");
IRestResponse response = client.Execute(request);
return response;
}
}

public class Session
{
public string SecretServer { get; set; }
Expand Down Expand Up @@ -151,6 +115,8 @@ public bool SessionRefresh()
this.RefreshToken = jsonObj.refresh_token;
this.ExpiresIn = jsonObj.expires_in;
this.TokenType = jsonObj.token_type;
this.StartTime = DateTime.Now;
this.TimeOfDeath = DateTime.Now.Add(TimeSpan.FromSeconds(jsonObj.expires_in));
return true;
}
catch
Expand All @@ -167,4 +133,40 @@ private class ApiTokenResponse
public int expires_in { get; set; }
}
}
public class Request
{
public static IRestResponse AccessToken(string SecretServerHost, string Username, string Password, string ProxyServer, int Timeout = 0)
{
var client = new RestClient(SecretServerHost + "/oauth2/token");
client.Timeout = Timeout;
if (string.IsNullOrEmpty(ProxyServer))
{
client.Proxy = new WebProxy(ProxyServer);
}
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("username", Username);
request.AddParameter("password", Password);
request.AddParameter("grant_type", "password");
IRestResponse response = client.Execute(request);
return response;
}

public static IRestResponse RefreshToken(string SecretServerHost, string TokenValue, string ProxyServer, int Timeout = 0)
{
var client = new RestClient(SecretServerHost + "/oauth2/token");
client.Timeout = Timeout;
if (string.IsNullOrEmpty(ProxyServer))
{
client.Proxy = new WebProxy(ProxyServer);
}
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("refresh_token", TokenValue);
request.AddParameter("grant_type", "refresh_token");
IRestResponse response = client.Execute(request);
return response;
}
}

}

0 comments on commit 2b0d11f

Please sign in to comment.