Esempio n. 1
0
        public IntegrationLoginResponse RequestIntegrationToken([FromBody] IntegrationLoginRequest request)
        {
            IntegrationLoginResponse response = new IntegrationLoginResponse();

            try
            {
                if (!string.IsNullOrEmpty(request.Key) && !string.IsNullOrEmpty(request.Source) && !string.IsNullOrEmpty(request.User))
                {
                    int tokenTimeout = Convert.ToInt32(_configuration["JWTTokenTimeout"]);

                    var result = _UserRepository.GetIntegrationLoginDetails(request.Key, request.User, request.Source);

                    if (result != null && result.Any())
                    {
                        var    curUser   = _UserRepository.GetUserDetails(result.First().UserName);
                        string userRoles = "";
                        int    i         = 0;

                        foreach (UserRoleDetails role in curUser.UserRoleDetails)
                        {
                            i++;
                            userRoles = userRoles + role.RoleName;

                            if (i != curUser.UserRoleDetails.Count)
                            {
                                userRoles = userRoles + ", ";
                            }
                        }
                        var token = CreateToken.GenerateToken(result.First().UserName, _configuration["SecurityKey"], _configuration["ValidIssuer"], _configuration["ValidAudience"], curUser.CompanyName, userRoles, tokenTimeout);
                        response.Token    = new JwtSecurityTokenHandler().WriteToken(token);
                        response.Expiry   = tokenTimeout.ToString();
                        response.UserInfo = result.FirstOrDefault();
                        response.Message  = "Success";

                        return(response);
                    }
                    else
                    {
                        response.Token   = null;
                        response.Expiry  = null;
                        response.Message = "Invalid Credentials";
                        return(response);
                    }
                }
                else
                {
                    response.Token   = null;
                    response.Expiry  = null;
                    response.Message = "UnAuthorized Request";
                    return(response);
                }
            }
            catch (Exception ex)
            {
                response.Token   = null;
                response.Expiry  = null;
                response.Message = ex.Message;
                return(response);
            }
        }
Esempio n. 2
0
        public async Task <IntegrationLoginResponse> GetIntegrationToken(IntegrationLoginRequest objTokenRequest)
        {
            IntegrationLoginResponse objLoginResponse = new IntegrationLoginResponse();

            objLoginResponse = await serviceProxy.PostData(_configuration.GetValue <string>("ServiceGetIntegrationToken"), objTokenRequest, typeof(IntegrationLoginResponse));

            return(objLoginResponse);
        }
Esempio n. 3
0
        public IActionResult CommonRedirectionBasedOnSource(IntegrationLoginRequest objLoginRequest, string token)
        {
            List <IntegrationConfigurationInfo> objIntegrationConfig = loginProviders.GetIntegrationRedirection(objLoginRequest, token).Result;
            string quetyString = string.Empty;

            if (objIntegrationConfig != null && objIntegrationConfig.Any())
            {
                quetyString  = "?Application=" + objLoginRequest.Source;
                quetyString += "&Module=" + objLoginRequest.Module;
                quetyString += "&Operation=" + objLoginRequest.Operation;

                foreach (var item in objIntegrationConfig)
                {
                    quetyString += "&" + item.SystemFieldName + "=" + Request.Query[item.ApplicationFieldName];
                }

                return(Redirect(objIntegrationConfig[0].URL + quetyString));
            }

            ViewBag.Unautherized = false;
            return(View("IntegrationError"));
        }
Esempio n. 4
0
        public async Task <List <IntegrationConfigurationInfo> > GetIntegrationRedirection(IntegrationLoginRequest objRedirectionRequest, string ticket)
        {
            List <IntegrationConfigurationInfo> objIntegrationConfig = new List <IntegrationConfigurationInfo>();

            objIntegrationConfig = await serviceProxy.PostData(_configuration.GetValue <string>("ServiceSettings:GetIntegrationRedirection"), objRedirectionRequest, typeof(List <IntegrationConfigurationInfo>), ticket);

            return(objIntegrationConfig);
        }
Esempio n. 5
0
        public async Task <IActionResult> IntegrationLogin(IntegrationLoginViewModel model, string returnUrl)
        {
            IntegrationLoginRequest objLoginRequest = new IntegrationLoginRequest();

            objLoginRequest.User      = !string.IsNullOrEmpty(model.User) ? model.User.Replace(' ', '+') : string.Empty; // User secret key Encrypted
            objLoginRequest.Key       = !string.IsNullOrEmpty(model.Key) ? model.Key.Replace(' ', '+') : string.Empty;   //Application Key Encrypted
            objLoginRequest.Source    = model.Source;
            objLoginRequest.Module    = model.Module;
            objLoginRequest.Operation = model.Operation;

            if (string.IsNullOrEmpty(returnUrl))
            {
                DeleteAllCookies();
            }
            else
            {
                return(RedirectToLocal(returnUrl));
            }

            List <ProductAttributeDetails> commonSession = new List <ProductAttributeDetails>();

            if (!string.IsNullOrEmpty(returnUrl) && HttpContext.Session.GetComplexData <List <ProductAttributeDetails> >(SessionName) != null)
            {
                commonSession = HttpContext.Session.GetComplexData <List <ProductAttributeDetails> >(SessionName);
                return(RedirectToLocal(returnUrl));
            }

            IntegrationLoginResponse objTokenResponse = loginProviders.GetIntegrationToken(objLoginRequest).Result;

            if (objTokenResponse.Message == "Success" && objTokenResponse.Token != "")
            {
                Response.Cookies.Append("JWTToken", objTokenResponse.Token, new CookieOptions {
                    Expires = DateTimeOffset.Now.AddMinutes(Convert.ToInt32(1000))
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "JWTToken", Value = objTokenResponse.Token
                });

                UserDetailsRequest objUserDetailsRequest = new UserDetailsRequest();
                objUserDetailsRequest.UserName = objTokenResponse.UserInfo.Email;
                UserDetailsResponse objUserDetailsResponse = loginProviders.GetUserDetails(objUserDetailsRequest, objTokenResponse.Token).Result;

                if (objUserDetailsResponse == null)
                {
                    throw new ApplicationException("UserDetailsResponse is null");
                }

                string EmailId = objTokenResponse.UserInfo.Email;
                int    time    = Convert.ToInt32(objTokenResponse.Expiry);
                SetCookiesForLoginUser(objUserDetailsResponse, EmailId, Convert.ToInt32(objTokenResponse.Expiry));
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "EmailId", Value = EmailId
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "UserName", Value = objUserDetailsResponse.FirstName + " " + objUserDetailsResponse.LastName
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "ContactDisplayMessage", Value = objUserDetailsResponse.ContactDisplayMessage
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "CompanyName", Value = objUserDetailsResponse.CompanyName
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "Currency", Value = objUserDetailsResponse.Currency
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "BalanceAmount", Value = objUserDetailsResponse.BalanceAmount
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "CreditAmount", Value = objUserDetailsResponse.CreditAmount
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "Photo", Value = objUserDetailsResponse.Photo ?? ""
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "UserRoles", Value = objUserDetailsResponse.UserRoleDetails.Count > 0 ? string.Join(",", objUserDetailsResponse.UserRoleDetails.Select(a => a.RoleName)) : "No Role"
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "VoyagerUser_Id", Value = objUserDetailsResponse.VoyagerUser_Id
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "CompanyId", Value = objUserDetailsResponse.CompanyId
                });
                commonSession.Add(new ProductAttributeDetails {
                    AttributeId = "ContactId", Value = objUserDetailsResponse.ContactId
                });

                HttpContext.Session.SetComplexData(SessionName, commonSession);

                //Set user login date in mUsers
                UserSetReq request = new UserSetReq();
                request.User.VoyagerUser_Id = objUserDetailsResponse.VoyagerUser_Id;
                request.User.LastLoginDate  = DateTime.Now;
                UserSetRes response = loginProviders.UpdateUser(request, objTokenResponse.Token).Result;

                // create claims
                List <Claim> claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, objTokenResponse.UserInfo.Email),
                    new Claim(ClaimTypes.Email, objTokenResponse.UserInfo.Email)
                };

                // create identity
                ClaimsIdentity identity = new ClaimsIdentity(claims, "cookie");

                // create principal
                ClaimsPrincipal principal = new ClaimsPrincipal(identity);

                // sign-in
                await HttpContext.SignInAsync(
                    principal : principal,
                    properties : new AuthenticationProperties
                {
                    ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToInt32(objTokenResponse.Expiry))
                });

                if (returnUrl != null)
                {
                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    return(CommonRedirectionBasedOnSource(objLoginRequest, objTokenResponse.Token));
                }
            }
            else
            {
                ViewBag.Unautherized = true;
                return(View("IntegrationError"));
            }
        }
Esempio n. 6
0
        public async Task <List <IntegrationConfigurationInfo> > GetIntegrationRedirection([FromBody] IntegrationLoginRequest request)
        {
            var response = new List <IntegrationConfigurationInfo>();

            response = await _settingsRepository.GetIntegrationRedirection(request);

            return(response);
        }