Пример #1
0
        /// <inheritdoc/>
        public async Task <Instance> UpdateSubstatus(int instanceOwnerPartyId, Guid instanceGuid, Substatus substatus)
        {
            string apiUrl = $"instances/{instanceOwnerPartyId}/{instanceGuid}/substatus";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            HttpResponseMessage response = await _client.PutAsync(token, apiUrl, new StringContent(JsonConvert.SerializeObject(substatus), Encoding.UTF8, "application/json"));

            if (response.StatusCode == HttpStatusCode.OK)
            {
                string instanceData = await response.Content.ReadAsStringAsync();

                Instance instance = JsonConvert.DeserializeObject <Instance>(instanceData);
                return(instance);
            }

            throw await PlatformHttpException.CreateAsync(response);
        }
Пример #2
0
        /// <inheritdoc />
        public async Task <string> RefreshToken()
        {
            string endpointUrl           = $"refresh";
            string token                 = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, Constants.General.RuntimeCookieName);
            HttpResponseMessage response = await _client.GetAsync(token, endpointUrl);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                string refreshedToken = await response.Content.ReadAsStringAsync();

                refreshedToken = refreshedToken.Replace('"', ' ').Trim();
                return(refreshedToken);
            }

            _logger.LogError($"Refreshing JwtToken failed with status code {response.StatusCode}");
            return(string.Empty);
        }
Пример #3
0
        /// <inheritdoc />
        public async Task <DataElement> Update(Instance instance, DataElement dataElement)
        {
            string apiUrl = $"{_platformSettings.ApiStorageEndpoint}instances/{instance.Id}/dataelements/{dataElement.Id}";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            StringContent       jsonString = new StringContent(JsonConvert.SerializeObject(dataElement), Encoding.UTF8, "application/json");
            HttpResponseMessage response   = await _client.PutAsync(token, apiUrl, jsonString);

            if (response.IsSuccessStatusCode)
            {
                DataElement result = JsonConvert.DeserializeObject <DataElement>(await response.Content.ReadAsStringAsync());

                return(result);
            }

            throw await PlatformHttpException.CreateAsync(response);
        }
Пример #4
0
        /// <inheritdoc/>
        public async Task <Instance> AddCompleteConfirmation(int instanceOwnerPartyId, Guid instanceGuid)
        {
            string apiUrl = $"instances/{instanceOwnerPartyId}/{instanceGuid}/complete";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            HttpResponseMessage response = await _client.PostAsync(token, apiUrl, new StringContent(string.Empty));

            if (response.StatusCode == HttpStatusCode.OK)
            {
                string instanceData = await response.Content.ReadAsStringAsync();

                Instance instance = JsonConvert.DeserializeObject <Instance>(instanceData);
                return(instance);
            }

            throw await PlatformHttpException.CreateAsync(response);
        }
Пример #5
0
        /// <inheritdoc />
        public Task <Stream> GetBinaryData(string org, string app, int instanceOwnerId, Guid instanceGuid, Guid dataId)
        {
            string instanceIdentifier = $"{instanceOwnerId}/{instanceGuid}";
            string apiUrl             = $"instances/{instanceIdentifier}/data/{dataId}";
            string token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _cookieOptions.Cookie.Name);

            JwtTokenUtil.AddTokenToRequestHeader(_client, token);

            HttpResponseMessage response = _client.GetAsync(apiUrl).Result;

            if (response.IsSuccessStatusCode)
            {
                return(response.Content.ReadAsStreamAsync());
            }

            return(null);
        }
Пример #6
0
        /// <inheritdoc/>
        public async Task <Instance> GetInstance(int instanceOwnerId, Guid instanceGuid)
        {
            string token = JwtTokenUtil.GetTokenFromContext(_contextAccessor.HttpContext, "AltinnStudioRuntime");

            string url = $"instances/{instanceOwnerId}/{instanceGuid}";

            HttpResponseMessage response = await _client.GetAsync(token, url);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                Instance instance = await response.Content.ReadAsAsync <Instance>();

                return(instance);
            }

            throw new PlatformHttpException(response);
        }
Пример #7
0
        /// <inheritdoc/>
        public async Task <string> AddEvent(string eventType, Instance instance)
        {
            string alternativeSubject = null;

            if (!string.IsNullOrWhiteSpace(instance.InstanceOwner.OrganisationNumber))
            {
                alternativeSubject = $"/org/{instance.InstanceOwner.OrganisationNumber}";
            }

            if (!string.IsNullOrWhiteSpace(instance.InstanceOwner.PersonNumber))
            {
                alternativeSubject = $"/person/{instance.InstanceOwner.PersonNumber}";
            }

            CloudEvent cloudEvent = new CloudEvent
            {
                Subject            = $"/party/{instance.InstanceOwner.PartyId}",
                Type               = eventType,
                AlternativeSubject = alternativeSubject,
                Time               = DateTime.UtcNow,
                SpecVersion        = "1.0",
                Source             = new Uri($"https://{instance.Org}.apps.{_generalSettings.HostName}/{instance.AppId}/instances/{instance.Id}")
            };

            string accessToken = _accessTokenGenerator.GenerateAccessToken(_appResources.GetApplication().Org, _appResources.GetApplication().Id.Split("/")[1]);

            string token =
                JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            string serializedCloudEvent = JsonSerializer.Serialize(cloudEvent);

            HttpResponseMessage response = await _client.PostAsync(
                token,
                "app",
                new StringContent(serializedCloudEvent, Encoding.UTF8, "application/json"),
                accessToken);

            if (response.IsSuccessStatusCode)
            {
                string eventId = await response.Content.ReadAsStringAsync();

                return(eventId);
            }

            throw await PlatformHttpException.CreateAsync(response);
        }
Пример #8
0
        private async Task <DataElement> InsertBinaryDataFromStreamContent(string org, string app, int instanceOwnerId, Guid instanceGuid, string elementType, string attachmentName, StreamContent content)
        {
            string   instanceIdentifier = $"{instanceOwnerId}/{instanceGuid}";
            string   apiUrl             = $"{_platformSettings.GetApiStorageEndpoint}instances/{instanceIdentifier}/data?elementType={elementType}";
            string   token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _cookieOptions.Cookie.Name);
            Instance instance;

            FileExtensionContentTypeProvider provider = new FileExtensionContentTypeProvider();

            provider.TryGetContentType(attachmentName, out string contentType);

            // Waiting for the instance and subsequently locking it.
            SemaphoreSlim instanceLock = _instanceLocks.GetOrAdd(instanceGuid, k => new SemaphoreSlim(1, 1));
            await instanceLock.WaitAsync();

            try
            {
                JwtTokenUtil.AddTokenToRequestHeader(_client, token);

                HttpResponseMessage response = await _client.PostAsync(apiUrl, content);

                if (response.IsSuccessStatusCode)
                {
                    string instancedata = await response.Content.ReadAsStringAsync();

                    instance = JsonConvert.DeserializeObject <Instance>(instancedata);

                    return(instance.Data.Find(m => m.ElementType.Equals(elementType)));
                }
                else
                {
                    _logger.LogError($"Storing attachment {attachmentName} for instance {instanceGuid} failed with status code {response.StatusCode}");
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"Storing attachment {attachmentName} for instance {instanceGuid} failed. Exception message: {e.Message}");
            }
            finally
            {
                instanceLock.Release();
            }

            return(null);
        }
Пример #9
0
        /// <inheritdoc/>
        public async Task <Instance> CreateInstance(string org, string app, Instance instanceTemplate)
        {
            string apiUrl = $"instances?appId={org}/{app}";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            StringContent       content  = new StringContent(JsonConvert.SerializeObject(instanceTemplate), Encoding.UTF8, "application/json");
            HttpResponseMessage response = await _client.PostAsync(token, apiUrl, content);

            if (response.IsSuccessStatusCode)
            {
                Instance createdInstance = JsonConvert.DeserializeObject <Instance>(await response.Content.ReadAsStringAsync());

                return(createdInstance);
            }

            _logger.LogError($"Unable to create instance {response.StatusCode} - {await response.Content.ReadAsStringAsync()}");
            throw await PlatformHttpException.CreateAsync(response);
        }
Пример #10
0
        /// <inheritdoc/>
        public async Task <Instance> UpdateReadStatus(int instanceOwnerPartyId, Guid instanceGuid, string readStatus)
        {
            string apiUrl = $"instances/{instanceOwnerPartyId}/{instanceGuid}/readstatus?status={readStatus}";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            HttpResponseMessage response = await _client.PutAsync(token, apiUrl, new StringContent(string.Empty));

            if (response.StatusCode == HttpStatusCode.OK)
            {
                string instanceData = await response.Content.ReadAsStringAsync();

                Instance instance = JsonConvert.DeserializeObject <Instance>(instanceData);
                return(instance);
            }

            _logger.LogError($"Could not update read status for instance {instanceOwnerPartyId}/{instanceGuid}. Request failed with status code {response.StatusCode}");
            return(null);
        }
Пример #11
0
        /// <inheritdoc />
        public async Task <bool> DeleteBinaryData(string org, string app, int instanceOwnerId, Guid instanceGuid, Guid dataGuid)
        {
            string instanceIdentifier = $"{instanceOwnerId}/{instanceGuid}";
            string apiUrl             = $"instances/{instanceIdentifier}/data/{dataGuid}";
            string token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            JwtTokenUtil.AddTokenToRequestHeader(_client, token);

            HttpResponseMessage response = await _client.DeleteAsync(apiUrl);

            if (response.IsSuccessStatusCode)
            {
                return(true);
            }

            _logger.LogError($"Deleting form attachment {dataGuid} for instance {instanceGuid} failed with status code {response.StatusCode}");
            throw new PlatformHttpException(response);
        }
Пример #12
0
        public async Task <ProcessHistoryList> GetProcessHistory(string instanceGuid, string instanceOwnerPartyId)
        {
            string apiUrl = $"instances/{instanceOwnerPartyId}/{instanceGuid}/process/history";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _appSettings.RuntimeCookieName);

            HttpResponseMessage response = await _client.GetAsync(token, apiUrl);

            if (response.IsSuccessStatusCode)
            {
                string eventData = await response.Content.ReadAsStringAsync();

                ProcessHistoryList processHistoryList = JsonConvert.DeserializeObject <ProcessHistoryList>(eventData);

                return(processHistoryList);
            }

            throw await PlatformHttpException.CreateAsync(response);
        }
Пример #13
0
        /// <inheritdoc />
        public async Task <DataElement> Update(Instance instance, DataElement dataElement)
        {
            string apiUrl = $"{_platformSettings.ApiStorageEndpoint}instances/{instance.Id}/dataelements/{dataElement.Id}";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            JwtTokenUtil.AddTokenToRequestHeader(_client, token);

            HttpResponseMessage response = await _client.PutAsync(apiUrl, dataElement.AsJson());

            if (response.IsSuccessStatusCode)
            {
                DataElement result = JsonConvert.DeserializeObject <DataElement>(await response.Content.ReadAsStringAsync());

                return(result);
            }

            throw new PlatformHttpException(response);
        }
Пример #14
0
        /// <inheritdoc />
        public async Task <Stream> GetBinaryData(string org, string app, int instanceOwnerId, Guid instanceGuid, Guid dataId)
        {
            string instanceIdentifier = $"{instanceOwnerId}/{instanceGuid}";
            string apiUrl             = $"instances/{instanceIdentifier}/data/{dataId}";
            string token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            HttpResponseMessage response = await _client.GetAsync(token, apiUrl);

            if (response.IsSuccessStatusCode)
            {
                return(await response.Content.ReadAsStreamAsync());
            }
            else if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }

            throw await PlatformHttpException.CreateAsync(response);
        }
Пример #15
0
        /// <inheritdoc />
        public async Task <HttpResponseMessage> RefreshToken()
        {
            string endpointUrl = $"refresh";
            string token       = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, "AltinnStudioRuntime");

            JwtTokenUtil.AddTokenToRequestHeader(_client, token);
            HttpResponseMessage response = await _client.GetAsync(endpointUrl);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                string refreshedToken      = GetCookieValueFromResponse(response, Constants.General.RuntimeCookieName);
                HttpResponseMessage result = new HttpResponseMessage(response.StatusCode);
                result.Content = new StringContent(refreshedToken);
                return(result);
            }

            _logger.LogError($"Refreshing JwtToken failed with status code {response.StatusCode}");
            return(new HttpResponseMessage(response.StatusCode));
        }
Пример #16
0
 public OkObjectResult GetJWT([FromBody] UserInfo user)
 {
     if (user.Name == "admin" && user.Password == "12345")
     {
         JwtTokenUtil jwtTokenUtil = new JwtTokenUtil(_configuration);
         string       token        = jwtTokenUtil.GetToken(user); //生成token
         return(Ok(new JsonBase()
         {
             IsSuccess = true, Message = "登录成功", Token = token
         }));
     }
     else
     {
         return(Ok(new JsonBase()
         {
             IsSuccess = false, Message = "登陆失败"
         }));
     }
 }
Пример #17
0
        /// <inheritdoc/>
        public async Task <Party> GetParty(int partyId)
        {
            Party party = null;

            string endpointUrl           = $"parties/{partyId}";
            string token                 = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);
            HttpResponseMessage response = await _client.GetAsync(token, endpointUrl, _accessTokenGenerator.GenerateAccessToken(_appResources.GetApplication().Org, _appResources.GetApplication().Id));

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                party = await response.Content.ReadAsAsync <Party>();
            }
            else
            {
                _logger.LogError($"// Getting party with partyID {partyId} failed with statuscode {response.StatusCode}");
            }

            return(party);
        }
Пример #18
0
        /// <inheritdoc />
        public async Task <DataElement> UpdateBinaryData(string org, string app, int instanceOwnerId, Guid instanceGuid, Guid dataGuid, HttpRequest request)
        {
            string   instanceIdentifier = $"{instanceOwnerId}/{instanceGuid}";
            string   apiUrl             = $"{_platformSettings.GetApiStorageEndpoint}instances/{instanceIdentifier}/data/{dataGuid}";
            string   token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _cookieOptions.Cookie.Name);
            Instance instance;

            // Waiting for the instance and subsequently locking it.
            SemaphoreSlim instanceLock = _instanceLocks.GetOrAdd(instanceGuid, k => new SemaphoreSlim(1, 1));
            await instanceLock.WaitAsync();

            try
            {
                StreamContent content = CreateContentStream(request);

                JwtTokenUtil.AddTokenToRequestHeader(_client, token);

                HttpResponseMessage response = await _client.PutAsync(apiUrl, content);

                if (response.IsSuccessStatusCode)
                {
                    string instancedata = response.Content.ReadAsStringAsync().Result;
                    instance = JsonConvert.DeserializeObject <Instance>(instancedata);

                    return(instance.Data.Find(d => d.Id.Equals(dataGuid.ToString())));
                }
                else
                {
                    _logger.LogError($"Updating attachment {dataGuid} for instance {instanceGuid} failed with status code {response.StatusCode}");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Updating attachment {dataGuid} for instance {instanceGuid} failed. Exception message: {ex.Message}");
            }
            finally
            {
                instanceLock.Release();
            }

            return(null);
        }
Пример #19
0
        /// <inheritdoc />
        public async Task <Organization> GetOrganization(string OrgNr)
        {
            Organization organization = null;

            string endpointUrl = $"organizations/{OrgNr}";
            string token       = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            HttpResponseMessage response = await _client.GetAsync(token, endpointUrl);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                organization = await response.Content.ReadAsAsync <Organization>();
            }
            else
            {
                _logger.LogError($"Getting organisation with orgnr {OrgNr} failed with statuscode {response.StatusCode}");
            }

            return(organization);
        }
Пример #20
0
        /// <inheritdoc/>
        public async Task <Instance> CreateInstance(string org, string app, Instance instanceTemplate)
        {
            string apiUrl = $"instances?appId={org}/{app}";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            JwtTokenUtil.AddTokenToRequestHeader(_client, token);

            StringContent       content  = instanceTemplate.AsJson();
            HttpResponseMessage response = await _client.PostAsync(apiUrl, content);

            if (response.IsSuccessStatusCode)
            {
                Instance createdInstance = JsonConvert.DeserializeObject <Instance>(await response.Content.ReadAsStringAsync());

                return(createdInstance);
            }

            _logger.LogError($"Unable to create instance {response.StatusCode} - {response.Content?.ReadAsStringAsync().Result}");
            throw new PlatformHttpException(response);
        }
Пример #21
0
        /// <inheritdoc />
        public async Task <UserProfile> GetUserProfile(int userId)
        {
            UserProfile userProfile = null;

            string endpointUrl = $"users/{userId}";
            string token       = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            HttpResponseMessage response = await _client.GetAsync(token, endpointUrl, _accessTokenGenerator.GenerateAccessToken(_appResources.GetApplication().Org, _appResources.GetApplication().Id));

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                userProfile = await response.Content.ReadAsAsync <UserProfile>();
            }
            else
            {
                _logger.LogError($"Getting user profile with userId {userId} failed with statuscode {response.StatusCode}");
            }

            return(userProfile);
        }
Пример #22
0
        /// <inheritdoc />
        public async Task <Instance> UpdateInstance(Instance instance)
        {
            string apiUrl = $"instances/{instance.Id}";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            StringContent       httpContent = new StringContent(instance.ToString(), Encoding.UTF8, "application/json");
            HttpResponseMessage response    = await _client.PutAsync(token, apiUrl, httpContent);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                string instanceData = await response.Content.ReadAsStringAsync();

                Instance updatedInstance = JsonConvert.DeserializeObject <Instance>(instanceData);

                return(updatedInstance);
            }

            _logger.LogError($"Unable to update instance with instance id {instance.Id}");
            throw await PlatformHttpException.CreateAsync(response);
        }
Пример #23
0
        /// <inheritdoc/>
        public async Task <string> SaveInstanceEvent(object dataToSerialize, string org, string app)
        {
            InstanceEvent instanceEvent = (InstanceEvent)dataToSerialize;

            instanceEvent.Created = DateTime.UtcNow;
            string apiUrl = $"instances/{instanceEvent.InstanceId}/events";
            string token  = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            HttpResponseMessage response = await _client.PostAsync(token, apiUrl, new StringContent(instanceEvent.ToString(), Encoding.UTF8, "application/json"));

            if (response.IsSuccessStatusCode)
            {
                string eventData = await response.Content.ReadAsStringAsync();

                InstanceEvent result = JsonConvert.DeserializeObject <InstanceEvent>(eventData);
                return(result.Id.ToString());
            }

            throw await PlatformHttpException.CreateAsync(response);
        }
Пример #24
0
        //主界面加载信息
        public object LoadPower()
        {
            string str = HttpContext.Request.Headers["Authorization"].ToString().Replace("Bearer ", "");

            try
            {
                var Uncode = new JwtTokenUtil().UpToken(str);

                Users use  = JsonConvert.DeserializeObject <Users>(Uncode);
                var   uses = (DataSources.GetData <Staff>(ff) as IEnumerable <Staff>)
                             .Where(item => item.Staff_Account == use.Name)
                             .Where(item => item.Staff_Password == use.Pass)
                             .SingleOrDefault();
                var allPowers = getRolesPowers(uses.Staff_Id);
                new RedisHelper().Set(uses.Staff_Id.ToString(), allPowers, 10);
                return(new { code = 0, allPowers });
            }
            catch { }
            return(new { code = 1 });
        }
Пример #25
0
        public async Task <IActionResult> GetCurrentUser()
        {
            _logger.LogInformation($"// ReceiptController // GetCurrentUser // Claim count: {Request.HttpContext.User.Claims.Count()}");
            string userIdString = Request.HttpContext.User.Claims.Where(c => c.Type == AltinnCoreClaimTypes.UserId)
                                  .Select(c => c.Value).SingleOrDefault();

            if (string.IsNullOrEmpty(userIdString))
            {
                return(BadRequest("Invalid request context. UserId must be provided in claims."));
            }

            int    userId  = int.Parse(userIdString);
            string userUrl = string.Empty;

            if (Environment.GetEnvironmentVariable("Platformsettings__ApiProfileEndpoint") != null)
            {
                userUrl = $"{Environment.GetEnvironmentVariable("Platformsettings__ApiProfileEndpoint")}users/{userId}";
            }
            else
            {
                userUrl = $"{_platformSettings.ApiProfileEndpoint}users/{userId}";
            }

            string token = JwtTokenUtil.GetTokenFromContext(Request.HttpContext, "AltinnStudioRuntime");

            JwtTokenUtil.AddTokenToRequestHeader(_client, token);
            HttpResponseMessage response = await _client.GetAsync(userUrl);

            UserProfile userProfile = null;

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                userProfile = await response.Content.ReadAsAsync <UserProfile>();
            }
            else
            {
                _logger.LogError($"Getting user profile with userId {userId} failed with statuscode {response.StatusCode}");
            }

            return(Ok(userProfile));
        }
Пример #26
0
        /// <inheritdoc />
        public async Task <UserProfile> GetUserProfile(int userId)
        {
            UserProfile userProfile = null;

            string endpointUrl = $"users/{userId}";
            string token       = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _generalSettings.JwtCookieName);
            string accessToken = _accessTokenGenerator.GenerateAccessToken("platform", "events");

            HttpResponseMessage response = await _client.GetAsync(token, endpointUrl, accessToken);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                userProfile = await response.Content.ReadAsAsync <UserProfile>();
            }
            else
            {
                _logger.LogError("Getting user profile with userId {userId} failed with statuscode {response.StatusCode}", userId, response.StatusCode);
            }

            return(userProfile);
        }
Пример #27
0
        /// <inheritdoc/>
        public async Task <Person> GetPerson(string SSN)
        {
            Person person = null;

            string endpointUrl = $"persons/{SSN}";

            string token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName);

            HttpResponseMessage response = await _client.GetAsync(token, endpointUrl, _accessTokenGenerator.GenerateAccessToken(_appResource.GetApplication().Org, _appResource.GetApplication().Id.Split("/")[1]));

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                person = await response.Content.ReadAsAsync <Person>();
            }
            else
            {
                _logger.LogError($"Getting person with ssn {SSN} failed with statuscode {response.StatusCode}");
            }

            return(person);
        }
Пример #28
0
        /// <inheritdoc/>
        public async Task <Party> GetParty(int partyId)
        {
            Party party = null;

            string endpointUrl = $"parties/{partyId}";
            string token       = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _cookieOptions.Cookie.Name);

            JwtTokenUtil.AddTokenToRequestHeader(_client, token);
            HttpResponseMessage response = await _client.GetAsync(endpointUrl);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                party = await response.Content.ReadAsAsync <Party>();
            }
            else
            {
                _logger.LogError($"// Getting party with partyID {partyId} failed with statuscode {response.StatusCode}");
            }

            return(party);
        }
Пример #29
0
        /// <inheritdoc/>
        public async Task <bool> DeleteAllInstanceEvents(string instanceId, string instanceOwnerId, string org, string appName)
        {
            string instanceIdentifier = $"{instanceOwnerId}/{instanceId}";
            string apiUrl             = $"instances/{instanceIdentifier}/events";
            string token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _cookieOptions.Cookie.Name);

            JwtTokenUtil.AddTokenToRequestHeader(_client, token);

            try
            {
                HttpResponseMessage response = await _client.DeleteAsync(apiUrl);

                response.EnsureSuccessStatusCode();
                return(true);
            }
            catch
            {
                _logger.LogError($"Unable to delete instance events");
                return(false);
            }
        }
Пример #30
0
        /// <inheritdoc/>
        public async Task <Party> GetParty(int partyId)
        {
            Party party = null;

            string endpointUrl = $"parties/{partyId}";
            string token       = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _generalSettings.JwtCookieName);
            string accessToken = _accessTokenGenerator.GenerateAccessToken("platform", "events");

            HttpResponseMessage response = await _client.GetAsync(token, endpointUrl, accessToken);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                party = await response.Content.ReadAsAsync <Party>();
            }
            else
            {
                _logger.LogError("// Getting party with partyID {partyId} failed with statuscode {response.StatusCode}", partyId, response.StatusCode);
            }

            return(party);
        }