Retourne la liste d'amis soit de l'utilisateur identifié par son token, soit de l'utilisateur spécifié dans l'URL.

@param null|string $token
@param null|string $login
@return array
162385
public function membersFriends($token = null, $login = null)
    {
        $params = array();

        // handle token parameter
        if (!is_null($token)) {
            $params['token'] = $token;
        }

        $url = 'members/friends.json';

        // handle login parameter
        if (!is_null($login)) {
            $url = 'members/friends/' . $login . '.json';
        }

        return $this->query($url, $params);
    }
881250
public function authenticatedUser($token = null)
    {
        $token = $this->getToken($token);

        $usersAPI = new Users($token);

        return $usersAPI->authenticatedUser();
    }
1004637
protected function _get($token = null)
    {
        $token = $this->_token($token);

        $subject = $this->_subject([
            'success' => true,
            'entity' => $this->_table()->newEntity(),
            'token' => $token
        ]);

        $this->_trigger('beforeRender', $subject);
    }
997618
public function getUserHubs($login)
    {
        $this->checkAliasName($login);

        return $this->adapter->get(sprintf('/users/%s/hubs', $login));
    }
736553
public function login($username, $password, \Espo\Entities\AuthToken $authToken = null, $params = [], $request)
    {
        if (!$password) return;

        $isPortal = !empty($params['isPortal']);

        if ($authToken) {
            return $this->loginByToken($username, $authToken);
        }

        if ($isPortal) {
            $useLdapAuthForPortalUser = $this->getUtils()->getOption('portalUserLdapAuth');
            if (!$useLdapAuthForPortalUser) {
                return parent::login($username, $password, $authToken, $params, $request);
            }
        }

        $ldapClient = $this->getLdapClient();

        /* Login LDAP system user (ldapUsername, ldapPassword) */
        try {
            $ldapClient->bind();
        } catch (\Exception $e) {
            $options = $this->getUtils()->getLdapClientOptions();
            $GLOBALS['log']->error('LDAP: Could not connect to LDAP server ['.$options['host'].'], details: ' . $e->getMessage());

            $adminUser = $this->adminLogin($username, $password);
            if (!isset($adminUser)) {
                return null;
            }

            $GLOBALS['log']->info('LDAP: Administrator ['.$username.'] was logged in by Espo method.');
        }

        if (!isset($adminUser)) {
            try {
                $userDn = $this->findLdapUserDnByUsername($username);
            } catch (\Exception $e) {
                $GLOBALS['log']->error('Error while finding DN for ['.$username.'], details: ' . $e->getMessage() . '.');
            }

            if (!isset($userDn)) {
                $GLOBALS['log']->error('LDAP: Authentication failed for user ['.$username.'], details: user is not found.');

                $adminUser = $this->adminLogin($username, $password);
                if (!isset($adminUser)) {
                    return null;
                }

                $GLOBALS['log']->info('LDAP: Administrator ['.$username.'] was logged in by Espo method.');
            }

            $GLOBALS['log']->debug('User ['.$username.'] is found with this DN ['.$userDn.'].');

            try {
                $ldapClient->bind($userDn, $password);
            } catch (\Exception $e) {
                $GLOBALS['log']->error('LDAP: Authentication failed for user ['.$username.'], details: ' . $e->getMessage());
                return null;
            }
        }

        $user = $this->getEntityManager()->getRepository('User')->findOne([
            'whereClause' => [
                'userName' => $username,
                'type!=' => ['api', 'system']
            ]
        ]);

        if (!isset($user) && $this->getUtils()->getOption('createEspoUser')) {
            $userData = $ldapClient->getEntry($userDn);
            $user = $this->createUser($userData, $isPortal);
        }

        return $user;
    }
901491
public function verify(Request $request, $token = null)
    {
        if (is_null($token)) {
            return $this->showVerifyMessage();
        }

        $credentials = ['email' => $request->get('email'), 'token' => $token];

        $broker = $this->getBroker();

        $response = Verification::broker($broker)->verify($credentials, function ($user) {
            $this->verifyUser($user);
        });

        switch ($response) {
            case Contracts\VerificationBroker::VERIFIED:
                return $this->getVerificationSuccessResponse($response);

            default:
                return $this->getVerificationFailureResponse($request, $response);
        }
    }
834224
public function verify($token = null) {
        if (!$token) {
            $data = $this->requestVerificationToken();
            $token = $data['token'];
        }

        return $this->_post('servers/' . $this->id . '/verify', ['token' => $token]);
    }
794134
protected function createToken($login) {
    $jwt = (new Builder())
            ->setIssuer($this->getTokenIssuer())
            ->setIssuedAt(time())
            ->setExpiration(time()+3600)
            ->set(self::AUTH_USER_NAME, $login)
            ->sign($this->getTokenSigner(), $this->key)
            ->getToken();
    return $jwt->__toString();
  }
667829
@Get("/tokens")
    public CompletableFuture<Collection<Token>> listTokens(User loginUser) {
        if (loginUser.isAdmin()) {
            return mds.getTokens()
                      .thenApply(tokens -> tokens.appIds().values());
        } else {
            return mds.getTokens()
                      .thenApply(Tokens::withoutSecret)
                      .thenApply(tokens -> tokens.appIds().values());
        }
    }
1259605
static function getToken($url, $login, $password) {
	    $responseEntity = RestHelper::post($url, [
		    'login' => $login,
		    'password' => $password,
	    ]);
	    if(!$responseEntity->is_ok) {
		    return null;
	    }
	    $token = self::getTokenFromResponse($responseEntity);
	    return $token;
    }
610193
public void login(String token) {
        TokenAuth tokenAuth = new TokenAuth(token);
        Object[] methodArgs = new Object[1];
        methodArgs[0] = tokenAuth;
        getDDP().call("login", methodArgs, new DDPListener() {
            @Override
            public void onResult(Map<String, Object> jsonFields) {
                handleLoginResult(jsonFields);
            }
        });
    }
508516
public static function findByPasswordResetToken($token, $status = self::STATUS_ACTIVE)
    {
        if (!static::isPasswordResetTokenValid($token)) {
            return null;
        }
        if ($status == null) {
            return static::find()->where(['password_reset_token' => $token])->limit(1)->one();
        }
        return static::find()->where(['password_reset_token' => $token, 'status' => $status])->limit(1)->one();
    }
959432
@Override
    public List<Object> loginRequest() {
        String token = token();
        if (token == null)
            return null;
        Map<String, String> loginParams = new HashMap<String, String>();
        loginParams.put(kLoginParamAccessToken, token);
        return Arrays.asList("POST", "_facebook", loginParams);
    }
42966
protected function loadEzUser($login)
    {
        if (empty($login)) {
            return null;
        }

        /** @var \eZ\Publish\API\Repository\UserService $userService */
        $userService = $this->getContainer()->get('ezpublish.api.service.user');

        try {
            return $userService->loadUserByLogin($login);
        } catch (NotFoundException $e) {
            return null;
        }
    }
241845
protected function _token($token = null)
    {
        if ($token) {
            return $token;
        }

        $token = $this->_request()->data('token');
        if ($token) {
            return $token;
        }

        $token = $this->_request()->param('token');
        if ($token) {
            return $token;
        }

        return $this->_request()->query('token');
    }
1348643
protected function findUserByField(LoginForm &$loginForm, $field = 'username')
    {
        return [
            $field,
            function ($attribute) use (&$loginForm) {
                $user = Yii::createObject(ModelMapHelper::User());
                /** @var LazyCache $cache */
                $cache = Yii::$app->cache;
                $value = $loginForm->$attribute;
                $loginForm->user = $cache->lazy(function () use ($user, $value, $attribute) {
                    return $user::find()
                        ->where(
                            "$attribute=:param",
                            [
                                ':param' => $value,
                            ]
                        )->one();
                }, "User:by:$attribute:$value", 86400, new TagDependency(['tags'=>$user::commonTag()]));
            }
        ];
    }
968531
private function retrieveByToken(string $token)
    {
        $token = $this->validateToken($token);
        if (!$token) {
            return NULL;
        }
        $user = new User();
        if ($token->hasClaim('sub')) {
            $user->id = $token->getClaim('sub');
        }
        if ($token->hasClaim('name')) {
            $user->name = $token->getClaim('name');
        }
        if ($token->hasClaim('email')) {
            $user->email = $token->getClaim('email');
        }
        if ($token->hasClaim('roles')) {
            $user->roles = explode(' ', $token->getClaim('roles'));
        }
        if ($token->hasClaim('registries')) {
            $user->registries = explode(' ', $token->getClaim('registries'));
        }
        if ($token->hasClaim('cpf')) {
            $user->cpf = $token->getClaim('cpf');
        }
        if ($token->hasClaim('avatar')) {
            $user->avatar = $token->getClaim('avatar');
        }

        return $user;
    }