Ejemplo n.º 1
0
        public async Task <ActionResult <PlaceProviderSensitiveData> > GetSensitiveData()
        {
            try
            {
                if (string.IsNullOrEmpty(User.GetPlaceProvider()))
                {
                    throw new ArgumentNullException("Please select place provider");
                }
                var ret = await placeProviderRepository.GetPlaceProviderSensitiveData(User.GetPlaceProvider());

                if (ret != null)
                {
                    ret.EZdraviePass = "";
                }
                return(Ok(ret));
            }
            catch (ArgumentException exc)
            {
                logger.LogError(exc.Message);
                return(BadRequest(new ProblemDetails()
                {
                    Detail = exc.Message
                }));
            }
            catch (Exception exc)
            {
                logger.LogError(exc, exc.Message);
                return(BadRequest(new ProblemDetails()
                {
                    Detail = exc.Message
                }));
            }
        }
Ejemplo n.º 2
0
        private async Task <PlaceProviderSensitiveData> MakeSurePlaceProviderIsAuthenticated(string placeProviderId, IPlaceProviderRepository placeProviderRepository)
        {
            var data = await placeProviderRepository.GetPlaceProviderSensitiveData(placeProviderId);

            if (data.SessionValidity == null || data.SessionValidity.ValidThru.AddMinutes(10) < DateTimeOffset.Now)
            {
                // session is going to expire
                if (data.SessionValidity == null || data.SessionValidity.ValidThru.AddMinutes(10) < DateTimeOffset.Now)
                {
                    if (data.SessionValidity == null || data.SessionValidity.ValidThru.AddMinutes(1) < DateTimeOffset.Now)
                    {
                        // expired .. login again
                        data.LoginPayload = (await Authenticate(data.EZdravieUser, data.EZdraviePass))?.Payload;
                        if (string.IsNullOrEmpty(data.LoginPayload.User.Login))
                        {
                            throw new Exception("Unable to authenticate to ehealth");
                        }
                    }

                    // extend session
                    var extendSessionRequest = new ExtendSessionRequest()
                    {
                        AccessId = data.LoginPayload.Session.SessionId,
                        UserId   = data.LoginPayload.User.Id
                    };
                    data.SessionValidity = await Extendsession(data.LoginPayload.Session.Token, extendSessionRequest);

                    if (data.SessionValidity == null)
                    {
                        data.SessionValidity = new ExtendSessionResponse()
                        {
                            ValidThru = data.LoginPayload.Session.ValidThru
                        };
                    }
                    if (data.SessionValidity.ValidThru.AddMinutes(1) < DateTimeOffset.Now)
                    {
                        throw new Exception("Unable to prolong the session");
                    }

                    await placeProviderRepository.SetPlaceProviderSensitiveData(data, false);
                }
            }
            return(data);
        }