public static AuthTicket EnsureAuthTicket(AuthTicket authTicket)
		{
			if (DateTime.UtcNow >= authTicket.AccessTokenExpiration.AddSeconds(-180))
				return RefreshUserAuthTicket(authTicket).AuthTicket;

			return null;
		}
        public static AuthTicket EnsureAuthTicket(AuthTicket authTicket)
        {
            if (DateTime.UtcNow >= authTicket.AccessTokenExpiration.AddSeconds(-180))
            {
                return(RefreshUserAuthTicket(authTicket).AuthTicket);
            }

            return(null);
        }
        public static async Task <AuthTicket> EnsureAuthTicket(AuthTicket authTicket)
        {
            if (DateTime.UtcNow >= authTicket.AccessTokenExpiration.AddSeconds(-180))
            {
                return((await RefreshUserAuthTicket(authTicket).ConfigureAwait(false)).AuthTicket);
            }

            return(null);
        }
        public static void Logout(AuthTicket authTicket)
        {
            var url = GetLogoutUrl(authTicket);
            var client = new HttpClient { BaseAddress = new Uri(AppAuthenticator.Instance.BaseUrl) };

            AppAuthenticator.AddHeader(client);

            var response = client.DeleteAsync(url).Result;
            ResponseHelper.EnsureSuccess(response);
        }
		public static async Task<AuthTicket> EnsureAuthTicketAsync(AuthTicket authTicket)
		{
			if (DateTime.UtcNow >= authTicket.AccessTokenExpiration.AddSeconds(-180))
			{
				var authProfile = await RefreshUserAuthTicketAsync(authTicket);
				return authProfile.AuthTicket;
			}

			return null;
		}
Beispiel #6
0
        public static async Task <AuthTicket> EnsureAuthTicketAsync(AuthTicket authTicket)
        {
            if (DateTime.UtcNow >= authTicket.AccessTokenExpiration.AddSeconds(-180))
            {
                var authProfile = await RefreshUserAuthTicketAsync(authTicket);

                return(authProfile.AuthTicket);
            }

            return(null);
        }
Beispiel #7
0
        public static async Task LogoutAsync(AuthTicket authTicket)
        {
            var url    = GetLogoutUrl(authTicket);
            var client = new HttpClient {
                BaseAddress = new Uri(AppAuthenticator.Instance.BaseUrl)
            };

            AppAuthenticator.AddHeader(client);

            var response = await client.DeleteAsync(url);

            ResponseHelper.EnsureSuccess(response);
        }
Beispiel #8
0
        private static string GetLogoutUrl(AuthTicket ticket)
        {
            switch (ticket.AuthenticationScope)
            {
            case AuthenticationScope.Tenant:
                return(TenantAdminUserAuthTicketUrl.DeleteUserAuthTicketUrl(ticket.RefreshToken).Url);

            case AuthenticationScope.Developer:
                return(DeveloperAdminUserAuthTicketUrl.DeleteUserAuthTicketUrl(ticket.RefreshToken).Url);

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #9
0
        private static string GetResourceRefreshUrl(AuthTicket authTicket, int?id = null)
        {
            switch (authTicket.AuthenticationScope)
            {
            case AuthenticationScope.Tenant:
                return(TenantAdminUserAuthTicketUrl.RefreshAuthTicketUrl(id).Url);

            case AuthenticationScope.Developer:
                return(DeveloperAdminUserAuthTicketUrl.RefreshDeveloperAuthTicketUrl(id).Url);

            default:
                throw new NotImplementedException();
            }
        }
		public static async Task<AuthenticationProfile> RefreshUserAuthTicketAsync(AuthTicket authTicket, int? id = null)
		{

			var resourceUrl = GetResourceRefreshUrl(authTicket, id);

			var client = new HttpClient { BaseAddress = new Uri(AppAuthenticator.Instance.BaseUrl) };
			AppAuthenticator.AddHeader(client);

			if (authTicket.SiteId.HasValue)
				client.DefaultRequestHeaders.Add(Headers.X_VOL_SITE, authTicket.SiteId.Value.ToString());

			var stringContent = JsonConvert.SerializeObject(authTicket);
			var response = client.PutAsync(resourceUrl, new StringContent(stringContent, Encoding.UTF8, "application/json")).Result;
			ResponseHelper.EnsureSuccess(response);

			var userInfo = SetUserAuth(response.Content.ReadAsStringAsync().Result, authTicket.AuthenticationScope);

			return userInfo;
		}
        public static CustomerAuthenticationProfile RefreshUserAuthTicket(AuthTicket authTicket)
        {

            var resourceUrl = CustomerAuthTicketUrl.RefreshUserAuthTicketUrl(authTicket.RefreshToken).Url;

            var client = new HttpClient { BaseAddress = new Uri(GetAuthUrl(authTicket.TenantId.Value)) };
            AppAuthenticator.AddHeader(client);

            if (authTicket.SiteId.HasValue)
                client.DefaultRequestHeaders.Add(Headers.X_VOL_SITE, authTicket.SiteId.Value.ToString());

            var stringContent = JsonConvert.SerializeObject(authTicket);
            var response = client.PutAsync(resourceUrl, new StringContent(stringContent, Encoding.UTF8, "application/json")).Result;
            ResponseHelper.EnsureSuccess(response);

            var userInfo = SetUserAuth(response.Content.ReadAsStringAsync().Result, authTicket.AuthenticationScope, authTicket.TenantId.Value, authTicket.SiteId.Value);

            return userInfo;
        }
        public static CustomerAuthenticationProfile RefreshUserAuthTicket(AuthTicket authTicket)
        {
            var resourceUrl = CustomerAuthTicketUrl.RefreshUserAuthTicketUrl(authTicket.RefreshToken).Url;

            var client = new HttpClient {
                BaseAddress = new Uri(GetAuthUrl(authTicket.TenantId.Value))
            };

            AppAuthenticator.AddHeader(client);

            if (authTicket.SiteId.HasValue)
            {
                client.DefaultRequestHeaders.Add(Headers.X_VOL_SITE, authTicket.SiteId.Value.ToString());
            }

            var stringContent = JsonConvert.SerializeObject(authTicket);
            var response      = client.PutAsync(resourceUrl, new StringContent(stringContent, Encoding.UTF8, "application/json")).Result;

            ResponseHelper.EnsureSuccess(response);

            var userInfo = SetUserAuth(response.Content.ReadAsStringAsync().Result, authTicket.AuthenticationScope, authTicket.TenantId.Value, authTicket.SiteId.Value);

            return(userInfo);
        }
Beispiel #13
0
        public static async Task <AuthenticationProfile> RefreshUserAuthTicketAsync(AuthTicket authTicket, int?id = null)
        {
            var resourceUrl = GetResourceRefreshUrl(authTicket, id);

            var client = new HttpClient {
                BaseAddress = new Uri(AppAuthenticator.Instance.BaseUrl)
            };

            AppAuthenticator.AddHeader(client);

            if (authTicket.SiteId.HasValue)
            {
                client.DefaultRequestHeaders.Add(Headers.X_VOL_SITE, authTicket.SiteId.Value.ToString());
            }

            var stringContent = JsonConvert.SerializeObject(authTicket);
            var response      = client.PutAsync(resourceUrl, new StringContent(stringContent, Encoding.UTF8, "application/json")).Result;

            ResponseHelper.EnsureSuccess(response);

            var userInfo = SetUserAuth(response.Content.ReadAsStringAsync().Result, authTicket.AuthenticationScope);

            return(userInfo);
        }
Beispiel #14
0
 public static AuthenticationProfile SetActiveScope(AuthTicket authTicket, Scope scope)
 {
     return(RefreshUserAuthTicket(authTicket, scope.Id));
 }
Beispiel #15
0
 public static async Task <AuthenticationProfile> SetActiveScopeAsync(AuthTicket authTicket, Scope scope)
 {
     return(await RefreshUserAuthTicketAsync(authTicket, scope.Id));
 }
		public static async Task<AuthenticationProfile> SetActiveScopeAsync(AuthTicket authTicket, Scope scope)
		{
			return await RefreshUserAuthTicketAsync(authTicket, scope.Id);
		}
		public static AuthenticationProfile SetActiveScope(AuthTicket authTicket, Scope scope)
		{
			return RefreshUserAuthTicket(authTicket, scope.Id);
		}
 private static string GetLogoutUrl(AuthTicket ticket)
 {
     switch (ticket.AuthenticationScope)
     {
         case AuthenticationScope.Tenant:
             return TenantAdminUserAuthTicketUrl.DeleteUserAuthTicketUrl(ticket.RefreshToken).Url;
         case AuthenticationScope.Developer:
             return DeveloperAdminUserAuthTicketUrl.DeleteUserAuthTicketUrl(ticket.RefreshToken).Url;
         default:
             throw new NotImplementedException();
     }
 }
 private static string GetResourceRefreshUrl(AuthTicket authTicket, int? id = null)
 {
     switch (authTicket.AuthenticationScope)
     {
         case AuthenticationScope.Tenant:
             return TenantAdminUserAuthTicketUrl.RefreshAuthTicketUrl(id).Url;
         case AuthenticationScope.Developer:
             return DeveloperAdminUserAuthTicketUrl.RefreshDeveloperAuthTicketUrl(id).Url;
         default:
             throw new NotImplementedException();
     }
 }
		public static async Task LogoutAsync(AuthTicket authTicket)
		{
			var url = GetLogoutUrl(authTicket);
			var client = new HttpClient { BaseAddress = new Uri(AppAuthenticator.Instance.BaseUrl) };

			AppAuthenticator.AddHeader(client);

			var response = await client.DeleteAsync(url);
			await ResponseHelper.EnsureSuccessAsync(response);
		}