Set the current user for the application with the given scopes.

@param  \Illuminate\Contracts\Auth\Authenticatable|\Laravel\Passport\HasApiTokens  $user
@param  array  $scopes
@param  string  $guard
@return \Illuminate\Contracts\Auth\Authenticatable
506828
public static function actingAs($user, $scopes = [], $guard = 'api')
    {
        $token = Mockery::mock(self::tokenModel())->shouldIgnoreMissing(false);

        foreach ($scopes as $scope) {
            $token->shouldReceive('can')->with($scope)->andReturn(true);
        }

        $user->withAccessToken($token);

        if (isset($user->wasRecentlyCreated) && $user->wasRecentlyCreated) {
            $user->wasRecentlyCreated = false;
        }

        app('auth')->guard($guard)->setUser($user);

        app('auth')->shouldUse($guard);

        return $user;
    }
73800
public function setUser(array $user)
    {
        if (in_array('user', $this->persistantMap)) {
            $this->store->set('user', $user);
        }

        $this->user = $user;
        return $this;
    }
1332626
public static function SetCurrentUser(IAuthenticatable $user, $guid = "CURRENT_USER")
	{
		self::UnsetAllSessionVars(); // this calls Init so we don't have to here
		self::$user = $user;
		$_SESSION[$guid] = serialize($user);
	}
162795
public function dontSeeAuthentication($guard = null)
    {
        $auth = $this->app['auth'];

        if (method_exists($auth, 'guard')) {
            $auth = $auth->guard($guard);
        }

        $this->assertNotTrue($auth->check(), 'There is an user authenticated');
    }
972372
public function authRequest($guard = null)
    {
        return is_null($guard) ? request()->user() ?? request()->user('api') : request()->user($guard);
    }
1290862
public function setUser(?string $user): AtlassianRestClient
    {
        $this->user = $user;
        $this->client = $this->createClient();

        return $this;
    }
154105
public function setUser($user)
    {
        $this->removeTarget();

        if ($user) {
            $this->user = (string) $user;
        }

        return $this;
    }
928596
public function setScopes(Mutable $scopes = null)
    {
        if ($scopes && $scopes->count()) {
            $scopes->prepend(
                new Scope('all')
            );
        }

        $this->scopes = $scopes;

        return $this;
    }
1091744
public function setUser(\Amulen\UserBundle\Entity\User $user = null)
    {
        $this->user = $user;

        return $this;
    }
223411
public function setAuthenticationScopes()
    {

        $scopes = $this->verifyToken()['Scopes'];

        // Add the internal 'public' scope
        $scopes = $scopes . ' public';
        $this->authentication->scopes = explode(' ', $scopes);
    }
429546
public function guarded($guard = null)
	{
		if(!$this->isAuthGuarded())
		{
			if(is_null($guard))
				$guard = $this->guard;

			$this->user = $this->users()->findOrFail(Auth::guard($guard)->user()->id);
		}

		return $this;
	}
732095
public function seeIsAuthenticatedAs($user, $guard = null)
    {
        $expected = $this->app->make('auth')->guard($guard)->user();

        $this->assertInstanceOf(
            get_class($expected), $user,
            'The currently authenticated user is not who was expected'
        );

        $this->assertSame(
            $expected->getAuthIdentifier(), $user->getAuthIdentifier(),
            'The currently authenticated user is not who was expected'
        );

        return $this;
    }
1307784
public function setUser(User $user = null): FamilyPermission
    {
        $this->user = $user;
        if ($user && !$user->getFamilyPermissions()->contains($this)) {
            $user->getFamilyPermissions()->add($this);
        }

        return $this;
    }
410191
public function setUser(\Haven\SecurityBundle\Entity\User $user = null) {
        $this->user = $user;

        return $this;
    }
475840
protected function _setCurrentUser($user = null)
    {
        if ($user === null && !empty($this->Auth)) {
            $user = $this->Auth->user();
        }

        if (!$user) {
            return false;
        }

        $this->_currentUserInstance = $this->_getUserInstance($user);

        return $this->_currentUserInstance;
    }
132664
public function setUser(Authorizable $user)
    {
        $userRoles = $user->getRoles();

        $this->userRoles = $userRoles;

        return $this;
    }
324724
public function seeAuthentication($guard = null)
    {
        $auth = $this->app['auth'];

        if (method_exists($auth, 'guard')) {
            $auth = $auth->guard($guard);
        }

        $this->assertTrue($auth->check(), 'There is no authenticated user');
    }