authenticate() 공개 메소드

public authenticate ( $accessToken )
예제 #1
0
파일: API.php 프로젝트: piwik/piwik
 /**
  * Saves the given license key in case the key is actually valid (exists on the Piwik Marketplace and is not
  * yet expired).
  *
  * @param string $licenseKey
  * @return bool
  *
  * @throws Exception In case of an invalid license key
  * @throws Service\Exception In case of any network problems
  */
 public function saveLicenseKey($licenseKey)
 {
     Piwik::checkUserHasSuperUserAccess();
     $licenseKey = trim($licenseKey);
     // we are currently using the Marketplace service directly to 1) change LicenseKey and 2) not use any cache
     $this->marketplaceService->authenticate($licenseKey);
     try {
         $consumer = $this->marketplaceService->fetch('consumer/validate', array());
     } catch (Api\Service\Exception $e) {
         if ($e->getCode() === Api\Service\Exception::HTTP_ERROR) {
             throw $e;
         }
         $consumer = array();
     }
     if (empty($consumer['isValid'])) {
         throw new Exception(Piwik::translate('Marketplace_ExceptionLinceseKeyIsNotValid'));
     }
     $this->setLicenseKey($licenseKey);
     return true;
 }
예제 #2
0
파일: config.php 프로젝트: piwik/piwik
<?php

use Interop\Container\ContainerInterface;
use Piwik\Plugins\Marketplace\Api\Service;
use Piwik\Plugins\Marketplace\LicenseKey;
return array('MarketplaceEndpoint' => function (ContainerInterface $c) {
    $domain = 'http://plugins.piwik.org';
    $updater = $c->get('Piwik\\Plugins\\CoreUpdater\\Updater');
    if ($updater->isUpdatingOverHttps()) {
        $domain = str_replace('http://', 'https://', $domain);
    }
    return $domain;
}, 'Piwik\\Plugins\\Marketplace\\Api\\Service' => function (ContainerInterface $c) {
    /** @var \Piwik\Plugins\Marketplace\Api\Service $previous */
    $domain = $c->get('MarketplaceEndpoint');
    $service = new Service($domain);
    $key = new LicenseKey();
    $accessToken = $key->get();
    $service->authenticate($accessToken);
    return $service;
});