public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            Guid linkId;

            if (_linkRepository.Authenticate(context.UserName, context.Password, out linkId))
            {
                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                identity.AddClaim(new Claim(identity.NameClaimType, context.UserName));
                identity.AddClaim(new Claim("OnPremiseId", linkId.ToString()));
                identity.AddClaim(new Claim(identity.RoleClaimType, "OnPremise"));

                context.Validated(identity);
            }

            if (!context.IsValidated)
            {
                var user = _userRepository.Authenticate(context.UserName, context.Password);

                if (user != null)
                {
                    var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                    identity.AddClaim(new Claim(identity.NameClaimType, context.UserName));
                    identity.AddClaim(new Claim(identity.RoleClaimType, "Admin"));
                    identity.AddClaim(new Claim("UserId", user.Id.ToString()));

                    context.Validated(identity);
                }
            }

            return(base.GrantResourceOwnerCredentials(context));
        }