protected function setUp() { parent::setUp(); $grantTypeFactory = new GrantTypeFactory(); $grantTypeFactory->add(new TestImplicit()); Environment::getContainer()->set('oauth2_grant_type_factory', $grantTypeFactory); }
protected function setUp() { parent::setUp(); $grantTypeFactory = new GrantTypeFactory(); $grantTypeFactory->add(new TestAuthorizationCode()); $grantTypeFactory->add(new TestClientCredentials()); $grantTypeFactory->add(new TestImplicit()); $grantTypeFactory->add(new TestPassword()); $grantTypeFactory->add(new TestRefreshToken()); Environment::getContainer()->set('oauth2_grant_type_factory', $grantTypeFactory); }
protected function doHandle() { $parameters = (array) $this->getBody(ReaderInterface::FORM); $grantType = isset($parameters['grant_type']) ? $parameters['grant_type'] : null; $scope = isset($parameters['scope']) ? $parameters['scope'] : null; $credentials = null; $auth = $this->request->getHeader('Authorization'); $parts = explode(' ', $auth, 2); $type = isset($parts[0]) ? $parts[0] : null; $data = isset($parts[1]) ? $parts[1] : null; if ($type == 'Basic' && !empty($data)) { $data = explode(':', base64_decode($data), 2); $clientId = isset($data[0]) ? $data[0] : null; $clientSecret = isset($data[1]) ? $data[1] : null; $credentials = new Credentials($clientId, $clientSecret); } try { // we get the grant type factory from the DI container the factory // contains the available grant types $accessToken = $this->grantTypeFactory->get($grantType)->generateAccessToken($credentials, $parameters); $this->response->setStatus(200); $this->setBody($accessToken, WriterInterface::JSON); } catch (ErrorExceptionAbstract $e) { $error = new Error(); $error->setError($e->getType()); $error->setErrorDescription($e->getMessage()); $error->setState(null); $this->response->setStatus(400); $this->setBody($error, WriterInterface::JSON); } catch (\Exception $e) { $error = new Error(); $error->setError('server_error'); $error->setErrorDescription($e->getMessage()); $error->setState(null); $this->response->setStatus(400); $this->setBody($error, WriterInterface::JSON); } }
public function getBackendGrantTypeFactory() { $factory = new GrantTypeFactory(); $factory->add(new BackendAuthorization\ClientCredentials($this->get('connection'))); return $factory; }