コード例 #1
0
        private bool SignInToWebApi(FranchisseNameAndLicenseDto objFranchiseeAndLicense, string keyAuthentication)
        {
            //var claimExceptiona = new InvalidClaimsException("InvalidLicenseKey", keyAuthentication)
            //{
            //    QuickspatchUserName = string.Empty
            //};
            //throw claimExceptiona;
            // Get token
            if (ConstantValue.DeploymentMode == DeploymentMode.Camino)
            {
                return(true);
            }

            // Get token
            var objTokenStore = _webApiUserService.GetToken(objFranchiseeAndLicense);

            if (objTokenStore == null)
            {
                var claimException = new InvalidClaimsException("InvalidLicenseKey", keyAuthentication)
                {
                    QuickspatchUserName = string.Empty
                };
                throw claimException;
            }
            if (!string.IsNullOrEmpty(objTokenStore.AccessToken))
            {
                // Store token to cookie
                var accessTokenCookie = new HttpCookie(ClaimsDeclaration.TokenClaim, objTokenStore.AccessToken)
                {
                    HttpOnly = true,
                    Expires  = DateTime.UtcNow.AddDays(7)
                };
                if (HttpContext.Response.Cookies[ClaimsDeclaration.TokenClaim] != null)
                {
                    HttpContext.Response.Cookies.Remove(ClaimsDeclaration.TokenClaim);
                }
                HttpContext.Response.Cookies.Add(accessTokenCookie);
                var refreshTokenCookie = new HttpCookie(ClaimsDeclaration.RefreshTokenClaim, objTokenStore.RefreshToken)
                {
                    HttpOnly = true,
                    Expires  = DateTime.UtcNow.AddYears(1)
                };
                if (HttpContext.Response.Cookies[ClaimsDeclaration.RefreshTokenClaim] != null)
                {
                    HttpContext.Response.Cookies.Remove(ClaimsDeclaration.RefreshTokenClaim);
                }
                HttpContext.Response.Cookies.Add(refreshTokenCookie);
            }


            return(false);
        }
コード例 #2
0
        public IHttpActionResult CheckConnection(CheckConnectDto checkConnectDto)
        {
            var franchisee     = _franchiseeConfigurationService.FirstOrDefault();
            var franchiseeData = new FranchisseNameAndLicenseDto()
            {
                LicenseKey     = franchisee.LicenseKey,
                FranchiseeName = franchisee.Name
            };

            var objTokenStore = _webApiConsumeUserService.GetToken(franchiseeData);

            if (objTokenStore != null)
            {
                int checkConnectValue = _courierService.CheckConnection(checkConnectDto);
                return(Ok(new DtoBase {
                    Id = checkConnectValue
                }));
            }

            return(Ok(new DtoBase {
                Id = 10
            }));
        }