Example #1
0
        public ResgridPrincipleV3(V3AuthToken authToken)
        {
            AuthToken = authToken;
            IsSystem  = false;

            _identity = new GenericIdentity(authToken.UserName, "Basic");
        }
Example #2
0
        public static async Task <bool> AuthAndSetPrinciple(ICacheProvider cacheProvider, IDepartmentsRepository departmentsRepository, string authTokenString, HttpContext context, bool v3)
        {
            if (string.IsNullOrWhiteSpace(authTokenString))
            {
                return(false);
            }

            var encodedUserPass = authTokenString.Trim();

            if (v3)
            {
                var authToken = V3AuthToken.Decode(encodedUserPass);

                if (authToken != null)
                {
                    string userId;

                    if (Config.SecurityConfig.SystemLoginCredentials.ContainsKey(authToken.UserName))
                    {
                        if (Config.SecurityConfig.SystemLoginCredentials[authToken.UserName] != encodedUserPass)
                        {
                            return(false);
                        }

                        authToken.UserId = authToken.UserName;
                    }
                    else
                    {
                        var result = await ValidateUserAndDepartmentByUser(cacheProvider, departmentsRepository, authToken.UserName, authToken.DepartmentId, null);

                        if (!result.IsValid)
                        {
                            return(false);
                        }

                        authToken.UserId = result.UserId;
                    }

                    var principal = new ResgridPrincipleV3(authToken);
                    Thread.CurrentPrincipal = principal;
                    if (context != null)
                    {
                        context.User = new System.Security.Claims.ClaimsPrincipal(principal);
                    }
                }
            }

            return(true);
        }
Example #3
0
        public static AuthenticationHeaderValue GetAuthHeaderValue(V3AuthToken authToken)
        {
            var authString = Create(authToken.UserName, authToken.DepartmentId);

            return(new AuthenticationHeaderValue("Basic", authString));
        }