/** * Determine the route to use for a given entity * * @param AuthenticationEntity $entity * @return string */ protected function getRouteForEntity(AuthenticationEntity $entity) { $baseRoute = 'zf-apigility/api/authentication'; if ($entity->isBasic()) { return $baseRoute . '/http-basic'; } if ($entity->isDigest()) { return $baseRoute . '/http-digest'; } if ($entity->isOAuth2()) { return $baseRoute . '/oauth2'; } return $baseRoute; }
/** * Patch the OAuth2 configuration * * @param AuthenticationEntity $entity * @param array $global * @param array $local * @return void */ protected function patchOAuth2Config(AuthenticationEntity $entity, array $global, array $local) { if (isset($global['route_match']) && $global['route_match']) { $this->globalConfig->patchKey('router.routes.oauth.options.route', $global['route_match']); } switch ($entity->getDsnType()) { case AuthenticationEntity::DSN_MONGO: $toSet = ['storage' => 'ZF\\OAuth2\\Adapter\\MongoAdapter', 'mongo' => $local]; break; case AuthenticationEntity::DSN_PDO: default: $toSet = ['storage' => 'ZF\\OAuth2\\Adapter\\PdoAdapter', 'db' => $local]; break; } $key = 'zf-oauth2'; $this->localConfig->patchKey($key, $toSet); }
public function testSerializationOfOauth2AuthReturnsOnlyKeysSpecificToType() { $entity = new AuthenticationEntity(AuthenticationEntity::TYPE_OAUTH2, ['dsn' => 'sqlite::memory:', 'username' => 'me', 'password' => 'too', 'route_match' => '/api/oauth']); $this->assertEquals(['type' => 'oauth2', 'dsn_type' => 'PDO', 'dsn' => 'sqlite::memory:', 'username' => 'me', 'password' => 'too', 'route_match' => '/api/oauth'], $entity->getArrayCopy()); }