Obtain Credential Object based on StoreId provided.

@param null $accountId
@return BasicAuth
@throws InvalidCredentialException
490076
public function getCredentialObject($accountId = null)
    {
        if ($accountId == null && array_key_exists($this->defaultAccountName, $this->credentialHashmap)) {
            $credObj = $this->credentialHashmap[$this->defaultAccountName];
        } elseif (array_key_exists($accountId, $this->credentialHashmap)) {
            $credObj = $this->credentialHashmap[$accountId];
        }

        if (empty($credObj)) {
            throw new InvalidCredentialException("Credential not found for " . ($accountId ? $accountId : " default user") .
                ". Please make sure your configuration/APIContext has credential information");
        }
        return $credObj;
    }
60404
public function createUser($accountID, $contactID, $username, $password)
    {
        try
        {
            return $this->httpHelper->patch("accounts/" . intval($accountID) . "/contacts/" . intval($contactID),[
                'username' => $username,
                'password' => $password
            ]);
        }
        catch (ApiException $e)
        {
            throw new InvalidArgumentException($e->getMessage());
        }
    }
794902
public function getCredentials()
    {
        $auth = $this->request->getHeader('Authorization');

        if (!$auth) {
            return null;
        }

        if ('basic ' !== strtolower(substr($auth, 0, 6))) {
            return null;
        }

        $credentials = explode(':', base64_decode(substr($auth, 6)), 2);

        if (2 !== count($credentials)) {
            return null;
        }

        return $credentials;
    }
1146799
public function getUserEntityByUserCredentials(
        $username,
        $password,
        $grantType,
        ClientEntityInterface $clientEntity
    ): ?UserEntityInterface {
        $builder = $this->connection->createQueryBuilder();
        $user = $builder->select(['user.id', 'user.password'])
            ->from('user')
            ->where('username = :username')
            ->setParameter('username', $username)
            ->execute()
            ->fetch();

        if (!$user) {
            return null;
        }

        if (!password_verify($password, $user['password'])) {
            return null;
        }

        return new User(Uuid::fromBytesToHex($user['id']));
    }
1009116
public function getIsRootPageId($pageId)
    {
        // Page 0 can never be a root page
        if ($pageId === 0) {
            return false;
        }

        // Page -1 is a workspace thing
        if ($pageId === -1) {
            return false;
        }

        $cacheId = 'RootPageResolver' . '_' . 'getIsRootPageId' . '_' . $pageId;
        $isSiteRoot = $this->runtimeCache->get($cacheId);

        if (!empty($isSiteRoot)) {
            return $isSiteRoot;
        }

        $page = $this->getPageRecordByPageId($pageId);
        if (empty($page)) {
            throw new \InvalidArgumentException(
                'The page for the given page ID \'' . $pageId
                . '\' could not be found in the database and can therefore not be used as site root page.',
                1487171426
            );
        }

        $isSiteRoot = Site::isRootPage($page);
        $this->runtimeCache->set($cacheId, $isSiteRoot);

        return $isSiteRoot;
    }
365538
public function setAccountID($accountID)
    {
        if (trim($accountID) == null)
        {
            throw new InvalidArgumentException("You must supply an account ID.");
        }

        if (!is_numeric($accountID))
        {
            throw new InvalidArgumentException("Account ID must be numeric.");
        }
        $this->accountID = intval($accountID);
    }
177344
public function getToken($accountUid)
    {
        $requestData = $this->getDefaultRequestData('query', []);
        $endpoint = vsprintf('accounts/%s/token', [$accountUid]);

        return $this->sendRequest($endpoint, $requestData, static::HTTP_METHOD_GET);
    }
428183
public function getBasicResponse()
    {
        // Default the basic response
        if ($this->basicResponse === null) {
            $this->basicResponse = function () {
                if (headers_sent()) {
                    throw new RuntimeException('Attempting basic auth after headers have already been sent.');
                }

                header('WWW-Authenticate: Basic');
                header('HTTP/1.0 401 Unauthorized');

                echo 'Invalid credentials.';
                exit;
            };
        }

        $response = $this->basicResponse;

        return $response();
    }
231956
public function getById(string $recordId): JsonResponse
    {
        return $this->response->success('OK', $this->service->getUserById($recordId));
    }
674899
protected function resolveIdentity($username, $accountId)
    {
        $identitySeed = $this->getServiceBroker()
            ->service('User')
            ->resolveIdentity($username);
        
        $accountIds = isset($identitySeed['accountIds']) ? $identitySeed['accountIds'] : [];
    
        if (in_array($accountId, $accountIds)) {
            $identitySeed['account']    = $accountId;
            $identitySeed['accountId']  = $accountId;
        }
        
        if ($identitySeed) {
            return $this->prepareIdentity($identitySeed);
        } else {
            return false;
        }
    }
1340389
public function setAccountId($id)
    {
        if (!empty($id) && ctype_print($id)) {
            $this->account_id = $id;
        }

        return $this;
    }
301448
public function getAuthorizerAccessToken($appId, $refreshToken)
    {
        $cacheKey = $this->getAuthorizerAccessTokenCacheKey($appId);
        $credential = $this->cache->get($cacheKey);
        if (!$credential || $credential['expireTime'] - time() < 60) {
            $ret = $this->authorizerToken($appId, $refreshToken);
            if ($ret['code'] !== 1) {
                return $ret;
            } else {
                $credential = [
                    'accessToken' => $ret['authorizer_access_token'],
                    'expireTime' => time() + $ret['expires_in'],
                    'refreshToken' => $ret['authorizer_refresh_token'],
                ];
                $this->cache->set($cacheKey, $credential);
            }
        }

        return $credential['accessToken'];
    }
455531
public function getCustomer($customerId)
    {
        $requestData = new Get\RequestData();
        $requestData->setCustomerId($customerId);

        $customers = $this->getCustomers($requestData)->getResponse()->getCustomers();

        return isset($customers[0]) ? $customers[0] : null;
    }
850993
public Credential loadCredential(String userId) throws AuthException {
        try {
            return authorizationCodeFlow.loadCredential(userId);
        } catch (IOException e) {
            throw new AuthException("Unable to load credential.", e);
        }
    }
156636
public function getInvoicePdf($accountID, $invoiceID)
    {
        return $this->httpHelper->get("accounts/" . intval($accountID) . "/invoices/" . intval($invoiceID) . "/pdf");
    }
63548
public function create($account_id)
    {
        return $this->createResource(sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH_ACCOUNT, $account_id, self::PATH));
    }
989152
public static function getCredential($userId)
    {
        $model = new User_Credential();
        $where = 'account_id = ' . $model->_toDb($userId, 'account_id');
        $creds = $model->getList(array(
            'filter' => $where
        ));
        if ($creds === false or count($creds) !== 1) {
            return false;
        }
        return $creds[0];
    }