public async Task Logout() { string token = _identityUser?.Token; if (string.IsNullOrEmpty(token)) { return; } _simpleMemoryCache.Delete(token); await _alfrescoHttpClient.Logout(); }
public async Task <bool> HandleNotAuthenticated() { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(new Uri(_alfrescoConfiguration.Url), "alfresco/api/-default-/public/authentication/versions/1/tickets")); webRequest.Method = "POST"; webRequest.ContentType = MediaTypeNames.Application.Json; try { await CreateRequestBody(webRequest); HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); if (response?.StatusCode != HttpStatusCode.Created) { return(false); } var responseModel = CreateResponse(response); if (responseModel?.Entry?.Id == null) { return(false); } if (_simpleMemoryCache.IsExist(nameof(AdminAuthentification))) { _simpleMemoryCache.Delete(nameof(AdminAuthentification)); } _simpleMemoryCache.Create( nameof(AdminAuthentification), $"Basic {responseModel.Entry.Id.ToAlfrescoAuthentication()}", new MemoryCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(_alfrescoConfiguration.TokenExpire ?? 30) }); return(true); } catch (Exception e) { Log.Error(e, "HandleNotAuthenticated"); return(false); } }