Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace nUnit_RestTests.Utils
- {
- class TokenProvider
- {
- private static string token = null;
- private static DateTime tokenRenewTime = DateTime.MinValue;
- private static TimeSpan maxTimespan = new TimeSpan(5, 0, 0);
- public static string getToken()
- {
- if (token != null)
- {
- if ((DateTime.Now - tokenRenewTime) > maxTimespan)
- renewToken();
- }
- else
- {
- renewToken();
- }
- return token;
- }
- private static void renewToken()
- {
- if ((String.IsNullOrEmpty(TestRunner.configReader.Login)) || (String.IsNullOrEmpty(TestRunner.configReader.Password)) || (String.IsNullOrEmpty(TestRunner.configReader.AuthURL))) {
- token = null;
- return;
- }
- string authRequest = string.Format("{0}rest/Authentication?request=getToken&username={1}&password={2}&f=HTML", TestRunner.configReader.AuthURL, TestRunner.configReader.Login, TestRunner.configReader.Password);
- token = TestRunner.getSynchronous(authRequest);
- tokenRenewTime = DateTime.Now;
- }
- }
- }
Add Comment
Please, Sign In to add comment