public static string LogFolder  = "Logs";                           //Logs Folder Name

        public static async Task <string> GetSSOTokenURL(SSOSubUser subuser)
        {
            try
            {
                if (string.IsNullOrEmpty(subuser?.ManagedBy) || string.IsNullOrEmpty(subuser?.Userid) ||
                    string.IsNullOrEmpty(subuser?.SSOKey))
                {
                    WriteLog($"Default Values are not available - {subuser?.ManagedBy} {subuser?.Userid}");
                    return($"{webBaseURL}#/login?errormsg=Default values are not available - {subuser?.ManagedBy}{subuser?.Userid}");
                }

                /*
                 * If you want allow access only to users who are already available uncomment this
                 * if (!await CheckAPIStatus($"{subuser?.ManagedBy}{subuser?.Userid}"))
                 *  return $"{webBaseURL}#/login?errormsg=User not available - {subuser?.ManagedBy}{subuser?.Userid}";
                 */

                string json = JsonConvert.SerializeObject(subuser);

                string token = GetSSOToken(json, subuser.ManagedBy, subuser.SSOKey);

                string signOnURL = $"{webBaseURL}#/login?sso={subuser.ManagedBy}&ssotoken={token}";

                return(signOnURL);
            }
            catch (Exception ex)
            {
                WriteErrorLog(ex);
                return(webBaseURL);
            }
        }
        public async Task <ActionResult> CloudCherry()
        {
            try
            {
                string ssoKey    = ConfigurationManager.AppSettings["ssokey"];
                string ccAccount = ConfigurationManager.AppSettings["ccaccount"];

                var identity = (ClaimsIdentity)User.Identity;
                if (identity != null)
                {
                    string userId  = string.IsNullOrEmpty(identity.Name) ? null : Regex.Replace(identity.Name.Split('@').FirstOrDefault(), @"[^0-9a-zA-Z]+", string.Empty);;
                    string emailId = identity.Name;

                    var subUser = new SSOSubUser
                    {
                        Userid    = userId,            // SSO user to login
                        Role      = "ManagerReadOnly", //Manager Or ManagerReadOnly
                        Email     = emailId,
                        TimeStamp = DateTime.UtcNow,
                        SSOKey    = ssoKey,
                        ManagedBy = ccAccount
                    };


                    var redirectUrl = await SSOHelper.GetSSOTokenURL(subUser);

                    SSOHelper.WriteLog($"Redirecting {ccAccount} - {userId} to CloudCherry");
                    return(Redirect(redirectUrl));
                }

                SSOHelper.WriteLog("Identity Not Found");
                return(Redirect($"{SSOHelper.webBaseURL}#/login?errormsg=Unable to sign-in, contact administrator"));
            }
            catch (Exception ex)
            {
                SSOHelper.WriteErrorLog(ex);
                return(Redirect($"{SSOHelper.webBaseURL}#/login?errormsg=Unable to sign-in, contact administrator"));
            }
        }