@param Authenticatable $user
@param array $additionalCustomClaims

@return string
540835
public function issue(Authenticatable $user, array $additionalCustomClaims = [])
    {
        // gets a new builder instance.
        $builder = $this->builder();

        // set the issued
        $builder->setIssuer($this->issuer);

        // set the subject.
        $builder->setSubject($user->getAuthIdentifier());

        // generate a unique id for the token, and set it to replicate as a header.
        $builder->setId($this->generateId(), true);

        // detect what time is it.
        $now = $this->now();

        // set issue date.
        $builder->setIssuedAt($now->timestamp);

        // set the token cannot be used before now.
        $builder->setNotBefore($now->timestamp);

        // calculate and set the expiration date for the token.
        $expiresAt = (clone $now)->addMinutes($this->ttl);
        $builder->setExpiration($expiresAt->timestamp);

        // created a custom claim that informs the limit time
        // for the token to be renewed.
        // the refresh limit is based on ttl + limit (grace period).
        $refreshLimit = (clone $now)->addMinutes($this->ttl + $this->refreshLimit);
        $builder->set('rli', $refreshLimit->timestamp);

        // loop through custom claims.
        foreach($additionalCustomClaims as $claim => $value) {
            // set custom claim.
            $builder->set($claim, $value);
        }

        // set user object default custom claims.
        if (method_exists($user, 'customJWTClaims')) {
            // call the methods.
            try {
                // call the custom claims method.
                $customClaims = (array) $user->customJWTClaims();

                // if the custom claims method returns a array.
                foreach($customClaims as $claim => $value) {
                    $builder->set($claim, $value);
                }
            } catch(\Exception $e) {
                // just continue since the custom claims should
                // not prevent the token of being issued.
            }
        }

        // get the signer.
        $signer = $this->signer();

        // sign the configure token.
        $builder->sign($signer, $this->secret);

        // gets the actual signed token as string.
        $token = (string) $builder->getToken();

        // returns the token.
        return $token;
    }
248540
public function updateRememberToken(Authenticatable $user, $token)
    {
        $user->setRememberToken($token);
        $this->em->persist($user);
        $this->em->flush($user);
    }
136662
public function login(AuthenticatableContract $user, $remember = false)
    {
        $this->updateSession($user->getAuthIdentifier());

        // If the user should be permanently "remembered" by the application we will
        // queue a permanent cookie that contains the encrypted copy of the user
        // identifier. We will then decrypt this later to retrieve the users.
        if ($remember) {
            $this->ensureRememberTokenIsSet($user);

            $this->queueRecallerCookie($user);
        }

        // If we have an event dispatcher instance set we will fire an event so that
        // any listeners will hook into the authentication events and run actions
        // based on the login and logout events fired from the guard instances.
        $this->fireLoginEvent($user, $remember);

        $this->setUser($user);
    }
585935
private function exportUsers($exporter, array $extra)
    {
        $dontExport = ['password', 'description', 'salt', 'plainPassword'];

        if (isset($extra['workspace'])) {
            $users = $this->om->getRepository('ClarolineCoreBundle:User')
                ->findAllWithFacetsByWorkspace($extra['workspace']);
        } else {
            $users = $this->om->getRepository('ClarolineCoreBundle:User')
                ->findAllWithFacets();
        }

        $fieldsFacets = $this->om->getRepository('ClarolineCoreBundle:Facet\FieldFacet')->findAll();
        $fields = $this->getExportableFields('Claroline\CoreBundle\Entity\User');

        foreach ($fields as $field) {
            if (in_array($field, $dontExport)) {
                unset($fields[array_search($field, $fields)]);
            }
        }

        $data = [];
        $fieldFacetsName = [];

        foreach ($fieldsFacets as $fieldsFacet) {
            $fieldFacetsName[] = $fieldsFacet->getName();
        }

        foreach ($users as $user) {
            $data[$user->getId()] = [];
            foreach ($fields as $field) {
                $data[$user->getId()][$field] = $this->formatValue($this->getValueFromObject($user, $field));
            }

            foreach ($fieldFacetsName as $fieldFacetName) {
                $found = false;
                foreach ($user->getFieldsFacetValue() as $fieldFacetValue) {
                    if ($fieldFacetValue->getFieldFacet()->getName() === $fieldFacetName) {
                        $found = true;
                        $data[$user->getId()][$fieldFacetName] = $this->formatValue($fieldFacetValue->getValue());
                    }
                }

                if (!$found) {
                    $data[$user->getId()][$fieldFacetName] = null;
                }
            }
        }

        foreach ($fieldFacetsName as $fieldFacetName) {
            $fields[] = $fieldFacetName;
        }

        return $exporter->export($fields, $data);
    }
1332578
public function issueToken(Authenticatable $user): string
    {
        $token = str_random(60);
        $this->cache->put($this->getCacheKey($token), $user->getAuthIdentifier(), $this->config['token_ttl']);
        return $token;
    }
148963
protected function cycleRememberToken(AuthenticatableContract $user)
    {
        $user->setRememberToken($token = Str::random(60));

        $this->provider->updateRememberToken($user, $token);
    }
132304
protected function createRememberTokenIfDoesntExist(UserContract $user)
    {
        $rememberToken = $user->getRememberToken();

        if (empty($rememberToken)) {
            $this->refreshRememberToken($user);
        }
    }
1347041
public static function getUserGuard(Authenticatable $user)
    {
        $provider = self::getUserProvider($user);

        return self::getProviderGuard($provider, $user);
    }
1138997
public function processAuthenticate($state, $extra = null)
    {

        if (!isset($state)) {
            return ["FAILURE"];
        }

        //If we don't already have a promise for this state, create one
        if (!isset($this->promises[$state])) {
            $deferred               = new Deferred();
            $this->promises[$state] = $deferred;
        }

        return $this->promises[$state]->promise();

    }
644548
public function getUser(array $credentials)
    {
        $credentials = Arr::except($credentials, ['token']);

        $user = $this->users->retrieveByCredentials($credentials);

        if ($user && !$user instanceof Contracts\RequiresEmailVerification) {
            throw new UnexpectedValueException('User must implement RequiresEmailVerification interface.');
        }

        return $user;
    }
177217
protected function queueRecallerCookie(AuthenticatableContract $user)
    {
        $this->getCookieJar()->queue($this->createRecaller(
            $user->getAuthIdentifier().'|'.$user->getRememberToken().'|'.$user->getAuthPassword()
        ));
    }
372332
function getThingUserClaims(user, thing, isSuperAdministrator) {

	if (!thing)
		throw new utils.ErrorCustom(httpStatusCodes.INTERNAL_SERVER_ERROR, "Thing can't be null", 26);

	let thingUserClaimsAndRights = {
		read    : thing.publicReadClaims,
		change  : thing.publicChangeClaims
	};

	if (user) {
		thingUserClaimsAndRights.read   = thingUserClaimsAndRights.read   | thing.everyoneReadClaims;
		thingUserClaimsAndRights.change = thingUserClaimsAndRights.change | thing.everyoneChangeClaims;

		var thingUserRights = getThingUserRights(user._id, user.username, thing);
		if (thingUserRights)
		{
			thingUserClaimsAndRights.read   = thingUserClaimsAndRights.read   | thingUserRights.userReadClaims;
			thingUserClaimsAndRights.change = thingUserClaimsAndRights.change | thingUserRights.userChangeClaims;
		}

		if (isSuperAdministrator)
		{
			thingUserClaimsAndRights.read   = thConstants.ThingUserReadClaims.AllClaims;
			thingUserClaimsAndRights.change = thConstants.ThingUserChangeClaims.AllClaims;
		}
	}

	return thingUserClaimsAndRights;
}
478739
protected function generateToken(SubjectContract $user)
    {
        $tokenGenerator = $this->getGenerator();
        $claims = $user->getJWTClaims();
        $claims['sub'] = $user->getJWTSubject();
        $claims[static::JWT_GUARD_CLAIM] = $this->id;
        if (!($token = $tokenGenerator($claims))) {
            throw new InvalidTokenException("Unable to generate token");
        }
        return $token;
    }
28142
public function authenticate(User $user, array $params = [])
    {
        if ($user->isEnabled() && password_verify($params['password'], $user->getPassword())) {
            return $user->getId();
        }
        return false;
    }
710746
public function getAuthorizationUri(array $additionalParameters = [])
	{
		$parameters = array_merge($additionalParameters, [
			'type' => 'web_server',
			'client_id' => $this->credentials->getConsumerId(),
			'redirect_uri' => $this->credentials->getCallbackUrl(),
			'response_type' => 'code',
		]);

		$parameters['scope'] = implode($this->service->getScopeSeparator(), $this->scopes);

		if ($this->needsStateParameterInAuthUrl()) {
			if (!isset($parameters['state'])) {
				$parameters['state'] = $this->generateAuthorizationState();
			}
			$this->storeAuthorizationState($parameters['state']);
		}

		// Build the url
		$url = clone $this->getAuthorizationEndpoint();
		foreach ($parameters as $key => $val) {
			$url->addToQuery($key, $val);
		}

		return $url;
	}
442530
public function assertAuthenticatedAs($user, $guard = null)
    {
        $expected = [
            'id' => $user->getAuthIdentifier(),
            'className' => get_class($user),
        ];

        PHPUnit::assertSame(
            $expected, $this->currentUserInfo($guard),
            'The currently authenticated user is not who was expected.'
        );

        return $this;
    }
26000
public function updateTenancy(Authenticatable $user, TenantParticipantContract $owner, TenantParticipantContract $creator)
    {
        $this->user          = $user;
        $this->tenantOwner   = $owner;
        $this->tenantCreator = $creator;

        return $this;
    }