/// <summary>The grant resource owner credentials.</summary>
        /// <param name="context">The context.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            // Adding Header to enable the Cross Origin Calls
            var allowedOrigin = context.OwinContext.Get <string>("as:clientAllowedOrigin") ?? "*";

            if (!context.OwinContext.Response.Headers.ContainsKey("Access-Control-Allow-Origin"))
            {
                context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });
            }

            // Create User Credential using Name/ password from Auth context
            var userCredentials = AuthHelper.CheckUserCredential(context.UserName, AuthenticationUtility.GetHash(context.Password));
            var tokenInfoList   = await this.userManagement.SelectAll(userCredentials);

            // Get valid userInfo for given credential
            var tokenInfo = tokenInfoList.Values.FirstOrDefault();

            if (tokenInfo == null)
            {
                context.SetError("Wrong username or password.");
                context.Response.Headers.Add("AuthorizationResponse", new[] { "Failed" });
                return;
            }

            if (tokenInfo.IsActive == 0)
            {
                context.SetError("Your account is disabled. Please contact the Admin.");
                context.Response.Headers.Add("AuthorizationResponse", new[] { "Failed" });
                return;
            }

            if (tokenInfo.IsLocked == 1)
            {
                context.SetError("Your account is locked. Please contact the Admin.");
                context.Response.Headers.Add("AuthorizationResponse", new[] { "Failed" });
                return;
            }

            // Set basic user information
            var guid     = Guid.NewGuid().ToString();
            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));

            identity.AddClaim(new Claim("userName", context.UserName));
            identity.AddClaim(new Claim("UserId", tokenInfo.Id.ToString()));
            identity.AddClaim(new Claim("GUID", guid));
            identity.AddClaim(new Claim("persistence", "jai was here"));

            var props = new AuthenticationProperties(new Dictionary <string, string>
            {
                {
                    "GUID", guid
                },
                {
                    "as:client_id", context.ClientId ?? null
                },
                {
                    "userName", tokenInfo.UserName
                },
                {
                    "userId", tokenInfo.Id.ToString()
                },
                {
                    "role", tokenInfo.Role
                },
                {
                    "isLocked", tokenInfo.IsLocked.ToString()
                },
                {
                    "isActive", tokenInfo.IsActive.ToString()
                }
            });

            var ticket = new AuthenticationTicket(identity, props);

            context.Validated(ticket);

            return;
        }