setToken() public static method

Set the token.
public static setToken ( string $token )
$token string
Ejemplo n.º 1
1
 /**
  * @param \App\User $user
  */
 protected function headers($user = null)
 {
     $headers = ['Accept' => 'application/json'];
     if (!is_null($user)) {
         $token = JWTAuth::fromUser($user);
         JWTAuth::setToken($token);
         $headers['HTTP_AUTHORIZATION'] = 'Bearer ' . (string) $token;
     }
     return $headers;
 }
Ejemplo n.º 2
0
 /**
  * @param \App\User $user
  */
 protected function headers($user = null)
 {
     $headers = ['Accept' => 'application/json'];
     if (!is_null($user)) {
         $token = JWTAuth::fromUser($user);
         JWTAuth::setToken($token);
         $headers['Authorization'] = 'Bearer ' . $token;
     }
     return $headers;
 }
Ejemplo n.º 3
0
	public function authenticate($userCredentials) 
	{
		if(!$token = \JWTAuth::attempt($credentials)) {
			//throw exception
		}

		$user = \JWTAuth::setToken($token)->toUser();

		return $user;

	}
Ejemplo n.º 4
0
 /**
  * @param $token
  */
 public static function invalidate($token)
 {
     \JWTAuth::setToken($token);
     $payload = \JWTAuth::manager()->getJWTProvider()->decode($token);
     $userId = ArrayUtils::get($payload, 'user_id');
     $exp = ArrayUtils::get($payload, 'exp');
     static::removeTokenMap($userId, $exp);
     try {
         \JWTAuth::invalidate();
     } catch (TokenExpiredException $e) {
         //If the token is expired already then do nothing here. The token map is already removed above.
     }
 }
 private function _createToken($user)
 {
     $token = JWTAuth::fromUser($user);
     JWTAuth::setToken($token);
     return $token;
 }
Ejemplo n.º 6
0
 protected function login($user_id = 1)
 {
     $user = User::find($user_id);
     $this->token = JWTAuth::fromUser($user);
     JWTAuth::setToken($this->token);
     Auth::login($user);
 }
Ejemplo n.º 7
0
 /**
  * Get user.
  *
  * @return void
  */
 public function testDeleteUser()
 {
     $response = $this->authenticateUser();
     $token = json_decode($response->content())->token;
     $user = JWTAuth::setToken($token)->authenticate();
     $this->delete('user/' . $user->id, ['HTTP_Authorization' => 'Bearer ' . $token])->assertResponseOk();
 }