<commit_before><?php namespace Tymon\JWTAuth;

use Tymon\JWTAuth\Providers\ProviderInterface;
use Tymon\JWTAuth\Exceptions\JWTAuthException;
use Illuminate\Auth\AuthManager;
use Illuminate\Http\Request;
use User;

class JWTAuth {

	/**
	 * @var \Tymon\JWTAuth\Providers\ProviderInterface
	 */
	protected $provider;

	/**
	 * @var \Illuminate\Auth\AuthManager
	 */
	protected $auth;

	/**
	 * @var string
	 */
	protected $identifier = 'id';

	/**
	 * @var string
	 */
	protected $token;

	/**
	 * @param \Tymon\JWTAuth\Providers\ProviderInterface $provider
	 */
	public function __construct(ProviderInterface $provider, AuthManager $auth)
	{
		$this->provider = $provider;
		$this->auth = $auth;
	}

	/**
	 * Find a user using the user identifier in the subject claim
	 * 
	 * @param  string $token
	 * @return mixed
	 */
	public function toUser($token = false)
	{
		$this->requireToken();

		$this->provider->decode($this->token);

		if ( ! $user = User::where( $this->identifier, $this->provider->getSubject() )->first() )
		{
			return false;
		}

		return $user;
	}

	/**
	 * Generate a token using the user identifier as the subject claim
	 * 
	 * @param $user
	 * @return string
	 */
	public function fromUser($user)
	{
		return $this->provider->encode($user->{$this->identifier})->get();
	}

	/**
	 * Attempt to authenticate the user and return the token
	 *  
	 * @param  array $credentials
	 * @return mixed
	 * @throws \Tymon\JWTAuth\Exceptions\JWTAuthException
	 */
	public function attempt(array $credentials = [])
	{
		if (! $this->auth->once($credentials) )
		{
			return false;
		}

		return $this->fromUser( $this->auth->user() );
	}

	/**
	 * Log the user in via the token
	 * 
	 * @param  string $token 
	 * @return mixed        
	 */
	public function login($token = false)
	{
		$this->requireToken();

		$id = $this->provider->getSubject($this->token);

		if (! $user = $this->auth->loginUsingId($id) )
		{
			return false;
		}

		return $user;
	}

	/**
	 * Get the token from the request
	 *
	 * @param  string $query
	 * @return mixed
	 */
	public function getToken($query = 'token')
	{
		$request = app('request');

		if ( ! $token = $this->parseAuthHeader($request) )
		{
			if ( ! $token = $request->query($query, false) )
			{
				return false;
			}
		}
<commit_msg>allowing method chaining<commit_after><?php namespace Tymon\JWTAuth;

use Tymon\JWTAuth\Providers\ProviderInterface;
use Tymon\JWTAuth\Exceptions\JWTAuthException;
use Illuminate\Auth\AuthManager;
use Illuminate\Http\Request;
use User;

class JWTAuth {

	/**
	 * @var \Tymon\JWTAuth\Providers\ProviderInterface
	 */
	protected $provider;

	/**
	 * @var \Illuminate\Auth\AuthManager
	 */
	protected $auth;

	/**
	 * @var string
	 */
	protected $identifier = 'id';

	/**
	 * @var string
	 */
	protected $token;

	/**
	 * @param \Tymon\JWTAuth\Providers\ProviderInterface $provider
	 */
	public function __construct(ProviderInterface $provider, AuthManager $auth)
	{
		$this->provider = $provider;
		$this->auth = $auth;
	}

	/**
	 * Find a user using the user identifier in the subject claim
	 * 
	 * @param  string $token
	 * @return mixed
	 */
	public function toUser($token = false)
	{
		$this->requireToken($token);

		$this->provider->decode($this->token);

		if ( ! $user = User::where( $this->identifier, $this->provider->getSubject() )->first() )
		{
			return false;
		}

		return $user;
	}

	/**
	 * Generate a token using the user identifier as the subject claim
	 * 
	 * @param $user
	 * @return string
	 */
	public function fromUser($user)
	{
		return $this->provider->encode($user->{$this->identifier})->get();
	}

	/**
	 * Attempt to authenticate the user and return the token
	 *  
	 * @param  array $credentials
	 * @return mixed
	 * @throws \Tymon\JWTAuth\Exceptions\JWTAuthException
	 */
	public function attempt(array $credentials = [])
	{
		if (! $this->auth->once($credentials) )
		{
			return false;
		}

		return $this->fromUser( $this->auth->user() );
	}

	/**
	 * Log the user in via the token
	 * 
	 * @param  string $token 
	 * @return mixed        
	 */
	public function login($token = false)
	{
		$this->requireToken($token);

		$id = $this->provider->getSubject($this->token);

		if (! $user = $this->auth->loginUsingId($id) )
		{
			return false;
		}

		return $user;
	}

	/**
	 * Get the token from the request
	 *
	 * @param  string $query
	 * @return mixed
	 */
	public function getToken($query = 'token')
	{
		$request = app('request');

		if ( ! $token = $this->parseAuthHeader($request) )
		{
			if ( ! $token = $request->query($query, false) )
			{
				return false;
			}
		}

{'fraction_non_alphanumeric': 0.15815772322398436, 'fraction_numerical': 0.0, 'mean_word_length': 3.1365678346810424, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6486067', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1536, 'n_words': 354}