Block a user

@param string|int $userIdentifier
@param string|int $userToBlockIdentifier
@param string     $accessToken
@throws InvalidIdentifierException
@return array|json
500550
public function blockUser($userIdentifier, $userToBlockIdentifier, $accessToken)
    {
        if ($this->apiVersionIsGreaterThanV3()) {
            if (!is_numeric($userIdentifier) || !is_numeric($userToBlockIdentifier)) {
                throw new InvalidIdentifierException('user');
            }
        }

        return $this->put(sprintf('users/%s/blocks/%s', $userIdentifier, $userToBlockIdentifier), [], $accessToken);
    }
932784
public static function createFromAccessTokenEntity(TokenInterface $accessTokenEntity)
    {
        $roles[] = 'ROLE_USER';
        if (($client = $accessTokenEntity->getClient()) instanceof ApiClientInterface ) {
            $roles = array_merge($roles, $client->getRoles());
        }

        if ($user = $accessTokenEntity->getUser()) {
            if ($user instanceof UserInterface) {
                $roles[] = 'ROLE_REAL_USER';
            }

            $roles = array_merge($roles, $user->getRoles());
        }
        $roles = array_unique($roles);

        $token = new self($roles);

        if ($user) {
            $token->setUser($user);
        }

        $token->setAuthenticated(true);
        $token->setAccessToken($accessTokenEntity->getCode());

        return $token;
    }
628092
private function findUserByValidToken($token)
    {
        try {
            /** @var UserInterface $user */
            $user = $this->getUserRepository()->findUserByToken($token);
            if (new \DateTime() > $user->getPasswordResetTokenExpiresAt()) {
                throw new InvalidTokenException($token);
            }

            return $user;
        } catch (NoResultException $exc) {
            throw new InvalidTokenException($token);
        }
    }
511320
public function getAuthorizedUser(AccessToken $token)
    {
        $response = $this->fetchAuthorizedUserDetails($token);

        return $this->createAuthorizedUser($response);
    }
1267698
public function refreshToken(AccessToken $accessToken)
    {
        // request data
        $refreshToken = $accessToken->getRefreshToken();
        $scope        = $accessToken->getScope();

        if (empty($refreshToken)) {
            throw new RuntimeException('No refresh token was set');
        }

        $data = array(
            'grant_type'    => 'refresh_token',
            'refresh_token' => $refreshToken,
        );

        if (!empty($scope)) {
            $data['scope'] = $scope;
        }

        // authentication
        $header = array();

        if ($this->type == self::AUTH_BASIC) {
            $header['Authorization'] = 'Basic ' . base64_encode($this->clientId . ':' . $this->clientSecret);
        }

        if ($this->type == self::AUTH_POST) {
            $data['client_id']     = $this->clientId;
            $data['client_secret'] = $this->clientSecret;
        }

        $request  = new PostRequest($this->url, $header, $data);
        $response = $this->httpClient->request($request);

        $data = Json\Parser::decode($response->getBody());

        if ($response->getStatusCode() == 200) {
            return $this->newToken($data);
        } else {
            throw new RuntimeException('Could not refresh access token');
        }
    }
84930
public function setAccessToken(AccessToken $accessToken)
    {
        $this->accessToken = $accessToken;

        if ($this->tokenUpdatedCallback) {
            call_user_func($this->tokenUpdatedCallback, $accessToken);
        }
    }
604928
public function setAccessToken($accessToken, $accessTokenLimit = null)
    {
        $this->setAuthConfig('access_token', $accessToken);
        if ($accessTokenLimit) {
            $this->setAuthConfig('access_token_limit', $accessTokenLimit);
        }
    }
1341873
public function validateAccessToken($headersOnly = true, $accessToken = null)
    {
        return $this->resourceServer->isValidRequest($headersOnly, $accessToken);
    }
93753
protected function getExtraParams(AccessTokenEntityInterface $accessToken)
    {
        $params = parent::getExtraParams($accessToken);

        // If this is an OIDC request, pack a new id token into it
        if ($this->isOidcRequest($accessToken->getScopes())) {
            $user = $this->userInfoRepository->getByID($accessToken->getUserIdentifier());

            if ($user) {
                $params['id_token'] = (string) $this->createIdToken($accessToken, $this->claimFactory->createFromUserInfo($user));
            }
        }

        return $params;
    }
718644
private function getUser(TokenInterface $authenticationToken)
    {
        $user = $authenticationToken->getUser();

        if (is_string($user)) {
            return $user;
        } elseif (method_exists($user, 'getAPIUser')) {
            return $user->getAPIUser()->id;
        }

        return $authenticationToken->getUsername();
    }
298124
public function deleteFeedPost($channelIdentifier, $postId, $accessToken)
    {
        if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) {
            throw new InvalidIdentifierException('channel');
        }

        if (!is_string($postId)) {
            throw new InvalidTypeException('Post ID', 'string', gettype($postId));
        }

        return $this->delete(sprintf('feed/%s/posts/%s', $channelIdentifier, $postId), [], $accessToken);
    }
1043046
public function validateAccessToken($accessToken = null)
	{
		$this->result = $this->http->get($this->getUrl('sns/auth', array(
			'access_token'	=>	null === $accessToken ? $this->accessToken : $accessToken,
			'openid'		=>	$this->openid,
		)))->json(true);
		return isset($this->result['errcode']) && 0 == $this->result['errcode'];
	}
581320
private function enforceSecurityIdentity(&$sid)
    {
        if (
            ($sid instanceof DomainObjectInterface)
        ) {
            $sid = new UserSecurityIdentity($sid->getObjectIdentifier(), get_class($sid));
        } elseif (! ($sid instanceof SecurityIdentityInterface)) {
            throw new InvalidArgumentException('Object must implement ObjectIdentifiableInterface');
        }
    }
432504
public function createFeedPost($channelIdentifier, $accessToken, $content, $share = false)
    {
        if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) {
            throw new InvalidIdentifierException('channel');
        }

        if (!is_string($content)) {
            throw new InvalidTypeException('Content', 'string', gettype($content));
        }

        if (!is_bool($share)) {
            throw new InvalidTypeException('Share', 'boolean', gettype($share));
        }

        $params = [
            'share' => $share,
            'content' => $content,
        ];

        return $this->post(sprintf('feed/%s/posts', $channelIdentifier), $params, $accessToken);
    }
507739
protected function addCurrentUser(TokenInterface $token, array $sids)
    {
        if (!$token instanceof AnonymousToken) {
            try {
                $sids[] = UserSecurityIdentity::fromToken($token);
            } catch (\InvalidArgumentException $e) {
                // ignore, user has no user security identity
            }
        }

        return $sids;
    }
71091
public function setAccessToken($accessToken)
    {
        $this->_accessToken = $accessToken;
        $this->_request->setAccessToken($this->_accessToken);
        $this->_request->setAccessTokenName('component_access_token');
        return $this;
    }
560804
private function setAccess($accessType, $userId, $allowed)
    {
        if ($userId instanceof AVUser)
        {
            $userId = $userId->getObjectId();
        }
        if ($userId instanceof AVRole)
        {
            $userId = "role:" . $userId->getName();
        }
        if (!is_string($userId))
        {
            throw new AVException("Invalid target for access control.");
        }
        if (!isset($this->permissionsById[$userId]))
        {
            if (!$allowed)
            {
                return;
            }
            $this->permissionsById[$userId] = array();
        }
        if ($allowed)
        {
            $this->permissionsById[$userId][$accessType] = true;
        } else
        {
            unset($this->permissionsById[$userId][$accessType]);
            if (empty($this->permissionsById[$userId]))
            {
                unset($this->permissionsById[$userId]);
            }
        }
    }