Creates token from credentials via user providers

@param array $credentials

@return $this
@throws AuthenticationException
963175
public function tokenize(array $credentials)
    {
        if (empty($credentials)) {
            throw new AuthenticationException('Unable to create token, no or empty credentials');
        }

        foreach ($this->providers as $provider) {
            if (!$provider->supportsCredentials($credentials)) {
                continue;
            }

            if (!$token = $provider->tokenize($credentials)) {
                $this->stash()
                     ->destroy();

                throw new AuthenticationException(sprintf('Unable to create token, credentials could not be authenticated in provider "%s"', get_class($provider)));
            }

            $this->stash()
                 ->put($token);

            return $this;
        }

        $this->stash()
             ->destroy();

        throw new AuthenticationException(sprintf('Unable to create token, missing provider supporting credentials "%s"', implode(', ', array_keys($credentials))));
    }
757837
public static function handler(array $credentials = array()) {

		$calendar_guid = elgg_extract('calendar_guid', $credentials);
		$user_guid = elgg_extract('user_guid', $credentials);
		$token = elgg_extract('token', $credentials);

		$ia = elgg_set_ignore_access(true);
		$calendar = get_entity($calendar_guid);
		$user = get_entity($user_guid);
		elgg_set_ignore_access($ia);

		$pam = new PAM($calendar, $user);

		if (!has_access_to_entity($calendar, $user)) {
			throw new LoginException('User does not have access to this calendar');
		}

		if (!$calendar->getToken()) {
			throw new LoginException('Calendar does not allow remote access');
		}

		if (!$pam->validateToken($token)) {
			throw new LoginException('Invalid token');
		}

		return true;
	}
1173633
public function create(array $credentials)
	{
		$user = $this->createModel();
		$user->fill($credentials);
		$user->save();

		return $user;
	}
440332
public function verify($credentials)
    {
        if(!array_key_exists("jwt", $credentials) || empty($credentials["jwt"])) {
            throw new \Exception("JWT is required");
        }

        // Make sure we have a secret key to decode the JWT
        if(!array_key_exists("secret_key", $credentials) || empty($credentials["secret_key"])) {
            throw new \Exception("Secret Key is required to decode this JWT");
        }

        // Get hash alg from params, default to HS256
        $hashAlgs = array("HS256");
        if(array_key_exists("hash_alg", $credentials) && !empty($credentials["hash_alg"])) {
            $hashAlgs[] = $credentials["hash_alg"];
            $hashAlgs = array_unique($hashAlgs);
        }

        $token = JWT::decode($credentials["jwt"], $credentials["secret_key"], $hashAlgs);

        // User ID is a good checksum to make sure we have a valid JWT
        if(empty($token) || empty($token->id)) {
            throw new \Exception("JWT Token invalid");
        }

        return $token;
    }
461670
public function createCredentials(ClientCredentials $client)
    {
        return $this->createCommand()
            ->setRequest($this->client->post('credentials'))
            ->setBodyEntity($client, 'json')
            ->setResponseClass('Maba\OAuthCommerceInternalClient\Entity\ClientCredentials')
        ;
    }
86450
public function seeCredentials(array $credentials, $guard = null)
    {
        $this->assertTrue(
            $this->hasCredentials($credentials, $guard), 'The given credentials are invalid.'
        );

        return $this;
    }
1109915
public function attempt(array $credentials = [], $login = true)
    {
        $user = $this->getProvider()->retrieveByCredentials($credentials);
        if ($user instanceof Authenticatable && $this->hasValidCredentials($user, $credentials)) {
            if ($login === true) {
                $this->login($user);
            }
            if (!($user instanceof SubjectContract)) {
                throw new InvalidTokenException("Unable to generate token");
            }
            return $this->generateToken($user);
        }
        return false;
    }
962614
public function getByCredentials(array $credentials) : ?Authenticatable
    {
        if (empty($credentials)) {
            return null;
        }

        // First we will add each credential element to the query as a where clause.
        // Then we can execute the query and, if we found a user, return it in a
        // Eloquent User "model" that will be utilized by the Guard instances.
        $query = $this->getModel()->newQuery();

        foreach ($credentials as $key => $value) {
            if (! Str::contains($key, 'password')) {
                $query->where($key, $value);
            }
        }

        return $query->first();
    }
481632
protected function getPasswordCredential($credentials = array())
	{
		$passField = $this->app['config']['auth.credentials.password'];

		if (isset($credentials[$passField]))
		{
			return $credentials[$passField];
		}
		else if (Input::has($passField))
		{
			return Input::get($passField);
		}
		else if (isset($credentials['user_password']))
		{
			return $credentials['user_password'];
		}
		else if (isset($credentials['pwd']))
		{
			return $credentials['pwd'];
		}

		throw new InvalidArgumentException("Password field not found");

	}
1114993
public function authenticate(array $credentials)
    {
        $loginProperty = $this->classMetadata->getPropertyName(ClassMetadata::LOGIN_PROPERTY);
        $passwordProperty = $this->classMetadata->getPropertyName(ClassMetadata::PASSWORD_PROPERTY);

        if (!array_key_exists($passwordProperty, $credentials)) {
            throw new \InvalidArgumentException(sprintf(
                'Unable to find password property "%s" in credential set!',
                $passwordProperty
            ));
        }

        if (!array_key_exists($loginProperty, $credentials)) {
            throw new \InvalidArgumentException(sprintf(
                'Unable to find login property "%s" in credential set!',
                $loginProperty
            ));
        }

        $object = $this->resolveObject($loginProperty, $credentials);

        if (!$this->validateCredentials($object, $credentials[$passwordProperty])) {
            $this->eventDispatcher->dispatch(
                Ma27ApiKeyAuthenticationEvents::CREDENTIAL_FAILURE,
                new OnInvalidCredentialsEvent($object)
            );

            throw new CredentialException();
        }

        $this->eventDispatcher->dispatch(Ma27ApiKeyAuthenticationEvents::AUTHENTICATION, new OnAuthenticationEvent($object));
        $this->buildKey($object);

        $this->om->persist($object);
        $this->om->flush();

        return $object;
    }
1071679
public function findByCredentials(array $credentials)
    {
        $queryBuilder = $this->createQueryBuilder('u');

        $this->createCredentialsCriteria($queryBuilder, $credentials);

        $queryBuilder->setMaxResults(1);

        return $queryBuilder->getQuery()->getOneOrNullResult();
    }
1369681
public function withCredentials($username, $password)
    {
        if (null === $username || null === $password) {
            // No change if credentials or null
            return $this;
        }

        $new = $this->setValue('username', $username)
            ->setValue('password', $password)
            ->setValue('credentials', [$username, $password]);

        // To keep BC
        $new->username = $username;
        $new->password = $password;
        $new->credentials = [$username, $password];

        return $new;
    }
659070
public function retrieveByCredentials(array $credentials)
    {
        // First we will add each credential element to the query as a where clause.
        // Then we can execute the query and, if we found a user, return it in a
        // Eloquent User "model" that will be utilized by the Guard instances.
        $query = $this->createUserModel()->newQuery();

        foreach ($credentials as $key => $value) {
            if (!Str::contains($key, 'password')) {
                $query->where($key, $value);
            }
        }

//        return $query->first();

        $user = $query->first();

        // If the user was not found in the local database, and LDAP authentication
        // is enabled, and the option is set to automatically create new accounts
        // on first login, create the user and return it. Otherwise return what
        // we found, which could be a user or null.
        if (
             is_null($user) &&
             Settings::get('eloquent-ldap.enabled') &&
             Settings::get('eloquent-ldap.create_accounts')
           ) {
            $user = $this->createUserFromLDAP($credentials['username']);
        }

        return $user;
    }
124805
public function setToken(string $token, int $authentication = self::OAUTH_AUTH): AbstractApi
    {
        $this->token = $token;
        $this->setAuthentication($authentication);

        return $this;
    }
900276
public function authenticate(array $credentials)
    {
        list($username, $password) = $credentials;
        $user = $this->users->findOneBy(array('username' => $username));

        if (!$user) {
            throw new NS\AuthenticationException("User not found.", self::IDENTITY_NOT_FOUND);
        }

        if ($user->password !== $this->calculateHash($password)) {
            throw new NS\AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
        }

        $permissions = array();
        foreach ($user->getRole()->getPermissions() as $key => $per) {
            $permissions[$per->getResource()] = $per->getRead();
        }

        return new NS\Identity($user->id, $user->getRole()->getName(), array(
            'username' => $user->username,
            'email' => $user->email,
            'permissions' => $permissions,
        ));
    }
176029
public function setCredentials($credentials)
    {
        if (!$credentials instanceof Credentials) {
            $credentials = new Credentials($credentials);
        }

        $this->credentials = $credentials;
        $this->authToken = $this->login();
    }
962895
protected function sendRequest(array $credentials): ResponseInterface
    {
        $options = [
            ('GET' === $this->requestMethod) ? 'query' : 'json' => $credentials,
        ];

        return $this->setHttpClient($this->app['http_client'])->request($this->getEndpoint(), $this->requestMethod, $options);
    }