diff --git a/config/install/simple_oauth.settings.yml b/config/install/simple_oauth.settings.yml index 2db05e8..6c7b637 100644 --- a/config/install/simple_oauth.settings.yml +++ b/config/install/simple_oauth.settings.yml @@ -2,3 +2,4 @@ access_token_expiration: 300 refresh_token_expiration: 1209600 remember_clients: true token_cron_batch_size: 0 +use_implicit: false diff --git a/config/schema/simple_oauth.schema.yml b/config/schema/simple_oauth.schema.yml index 07bc0b3..69d7dfe 100644 --- a/config/schema/simple_oauth.schema.yml +++ b/config/schema/simple_oauth.schema.yml @@ -42,3 +42,7 @@ simple_oauth.settings: remember_clients: type: boolean label: 'Remember clients' + use_implicit: + type: boolean + label: 'Enable the implicit grant?' + description: 'Only use the implicit grant if you understand the security implications of using it.' diff --git a/simple_oauth.module b/simple_oauth.module index deba4e1..6355956 100644 --- a/simple_oauth.module +++ b/simple_oauth.module @@ -2,7 +2,7 @@ /** * @file - * Contains simple_oauth.module.. + * Contains simple_oauth.module. */ use Drupal\Core\Entity\EntityInterface; @@ -15,6 +15,7 @@ use Drupal\consumers\Entity\Consumer; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; use Drupal\user\RoleInterface; +use Drupal\Core\Link; /** * Implements hook_cron(). @@ -91,6 +92,45 @@ function simple_oauth_entity_base_field_info(EntityTypeInterface $entity_type) { 'type' => 'options_buttons', 'weight' => 5, ]); + $fields['redirect'] = BaseFieldDefinition::create('uri') + ->setLabel(new TranslatableMarkup('Redirect URI')) + ->setDescription(new TranslatableMarkup('The URI this client will redirect to when needed.')) + ->setDisplayOptions('view', [ + 'label' => 'inline', + 'weight' => 4, + ]) + ->setDisplayOptions('form', [ + 'weight' => 4, + ]) + ->setDisplayConfigurable('view', TRUE) + ->setTranslatable(TRUE) + // URIs are not length limited by RFC 2616, but we can only store 255 + // characters in our entity DB schema. + ->setSetting('max_length', 255); + + $fields['user_id'] = BaseFieldDefinition::create('entity_reference') + ->setLabel(new TranslatableMarkup('User')) + ->setDescription(new TranslatableMarkup('When no specific user is authenticated Drupal will use this user as the author of all the actions made.')) + ->setRevisionable(TRUE) + ->setSetting('target_type', 'user') + ->setSetting('handler', 'default') + ->setTranslatable(FALSE) + ->setDisplayOptions('view', [ + 'label' => 'inline', + 'type' => 'entity_reference_label', + 'weight' => 1, + ]) + ->setCardinality(1) + ->setDisplayOptions('form', [ + 'type' => 'entity_reference_autocomplete', + 'weight' => 0, + 'settings' => [ + 'match_operator' => 'CONTAINS', + 'size' => '60', + 'autocomplete_type' => 'tags', + 'placeholder' => '', + ], + ]); } return $fields; } @@ -156,6 +196,7 @@ function simple_oauth_form_consumer_form_submit($entity_type_id, Consumer $entit */ function simple_oauth_consumers_list_alter(&$data, $context) { if ($context['type'] === 'header') { + $data['redirect'] = t('Redirect'); $data['scopes'] = t('Scopes'); } elseif ($context['type'] === 'row') { @@ -166,5 +207,9 @@ function simple_oauth_consumers_list_alter(&$data, $context) { foreach ($entity->get('roles')->getValue() as $role) { $data['scopes']['data']['#items'][] = $role['target_id']; } + $data['redirect'] = NULL; + if ($redirect_url = $context['entity']->get('redirect')->value) { + $data['redirect'] = Link::fromTextAndUrl($redirect_url, Url::fromUri($redirect_url)); + } } } diff --git a/simple_oauth.permissions.yml b/simple_oauth.permissions.yml index 452ec82..3d6a95b 100644 --- a/simple_oauth.permissions.yml +++ b/simple_oauth.permissions.yml @@ -13,3 +13,10 @@ update own simple_oauth entities: view own simple_oauth entities: title: 'View Access Token entities' + +debug simple_oauth tokens: + title: 'Debug OAuth2 tokens' + +grant simple_oauth codes: + title: 'Grant OAuth2 codes' + description: 'Allow using the AuthCode grant' diff --git a/simple_oauth.routing.yml b/simple_oauth.routing.yml index b9da27f..ef78187 100644 --- a/simple_oauth.routing.yml +++ b/simple_oauth.routing.yml @@ -58,3 +58,25 @@ oauth2_token.token: methods: [POST] requirements: _access: 'TRUE' +oauth2_token.authorize: + path: '/oauth/authorize' + defaults: + _controller: 'Drupal\simple_oauth\Controller\Oauth2AuthorizeController::authorize' + _title: 'Grant Access to Client' + methods: [GET, POST] + requirements: + _access: 'TRUE' + options: + no_cache: TRUE + +oauth2_token.user_debug: + path: '/oauth/debug' + defaults: + _controller: 'Drupal\simple_oauth\Controller\DebugController::debug' + methods: [GET] + requirements: + _permission: 'debug simple_oauth tokens' + _format: 'json' + options: + _auth: ['oauth2'] + no_cache: TRUE diff --git a/simple_oauth.services.yml b/simple_oauth.services.yml index 69ffc97..f9427ba 100644 --- a/simple_oauth.services.yml +++ b/simple_oauth.services.yml @@ -44,6 +44,9 @@ services: simple_oauth.repositories.refresh_token: class: Drupal\simple_oauth\Repositories\RefreshTokenRepository arguments: ['@entity_type.manager', '@serializer'] + simple_oauth.repositories.auth_code: + class: Drupal\simple_oauth\Repositories\AuthCodeRepository + arguments: ['@entity_type.manager', '@serializer'] simple_oauth.server.response_type: class: \League\OAuth2\Server\ResponseTypes\BearerTokenResponse plugin.manager.oauth2_grant.processor: diff --git a/simple_oauth_extras/config/install/simple_oauth_extras.settings.yml b/simple_oauth_extras/config/install/simple_oauth_extras.settings.yml deleted file mode 100644 index ec0c0a3..0000000 --- a/simple_oauth_extras/config/install/simple_oauth_extras.settings.yml +++ /dev/null @@ -1 +0,0 @@ -use_implicit: false diff --git a/simple_oauth_extras/config/schema/simple_oauth_extras.schema.yml b/simple_oauth_extras/config/schema/simple_oauth_extras.schema.yml deleted file mode 100644 index 5817cee..0000000 --- a/simple_oauth_extras/config/schema/simple_oauth_extras.schema.yml +++ /dev/null @@ -1,8 +0,0 @@ -simple_oauth_extras.settings: - type: config_object - label: 'Simple OAuth 3rd Party Settings' - mapping: - use_implicit: - type: boolean - label: 'Enable the implicit grant?' - description: 'Only use the implicit grant if you understand the security implications of using it.' diff --git a/simple_oauth_extras/simple_oauth_extras.info.yml b/simple_oauth_extras/simple_oauth_extras.info.yml deleted file mode 100644 index 8666ff6..0000000 --- a/simple_oauth_extras/simple_oauth_extras.info.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: Simple OAuth Extras -type: module -description: OAuth2 extra access grants. -core: 8.x -package: Authentication -dependencies: - - simple_oauth:simple_oauth diff --git a/simple_oauth_extras/simple_oauth_extras.module b/simple_oauth_extras/simple_oauth_extras.module deleted file mode 100644 index e32ee4e..0000000 --- a/simple_oauth_extras/simple_oauth_extras.module +++ /dev/null @@ -1,104 +0,0 @@ - 'checkbox', - '#title' => t('Enable the implicit grant?'), - '#description' => t('The implicit grant has the potential to be used in an insecure way. Only enable this if you understand the risks. See https://tools.ietf.org/html/rfc6819#section-4.4.2 for more information.'), - '#default_value' => \Drupal::config('simple_oauth_extras.settings')->get('use_implicit'), - ]; - $form['#submit'][] = 'simple_oauth_extras_form_oauth2_token_settings_submit'; -} - -/** - * Form submission handler. - * - * @param array $form - * An associative array containing the structure of the form. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. - */ -function simple_oauth_extras_form_oauth2_token_settings_submit(array &$form, FormStateInterface $form_state) { - $settings = \Drupal::configFactory()->getEditable('simple_oauth_extras.settings'); - $settings->set('use_implicit', $form_state->getValue('use_implicit')); - $settings->save(); -} - -/** - * Implements hook_entity_base_field_info(). - */ -function simple_oauth_extras_entity_base_field_info(EntityTypeInterface $entity_type) { - $fields = []; - if ($entity_type->id() == 'consumer') { - $fields['redirect'] = BaseFieldDefinition::create('uri') - ->setLabel(new TranslatableMarkup('Redirect URI')) - ->setDescription(new TranslatableMarkup('The URI this client will redirect to when needed.')) - ->setDisplayOptions('view', [ - 'label' => 'inline', - 'weight' => 4, - ]) - ->setDisplayOptions('form', [ - 'weight' => 4, - ]) - ->setDisplayConfigurable('view', TRUE) - ->setTranslatable(TRUE) - // URIs are not length limited by RFC 2616, but we can only store 255 - // characters in our entity DB schema. - ->setSetting('max_length', 255); - - $fields['user_id'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(new TranslatableMarkup('User')) - ->setDescription(new TranslatableMarkup('When no specific user is authenticated Drupal will use this user as the author of all the actions made.')) - ->setRevisionable(TRUE) - ->setSetting('target_type', 'user') - ->setSetting('handler', 'default') - ->setTranslatable(FALSE) - ->setDisplayOptions('view', [ - 'label' => 'inline', - 'type' => 'entity_reference_label', - 'weight' => 1, - ]) - ->setCardinality(1) - ->setDisplayOptions('form', [ - 'type' => 'entity_reference_autocomplete', - 'weight' => 0, - 'settings' => [ - 'match_operator' => 'CONTAINS', - 'size' => '60', - 'autocomplete_type' => 'tags', - 'placeholder' => '', - ], - ]); - } - return $fields; -} - -/** - * Implements hook_consumers_list_alter(). - */ -function simple_oauth_extras_consumers_list_alter(&$data, $context) { - if ($context['type'] === 'header') { - $data['redirect'] = t('Redirect'); - } - elseif ($context['type'] === 'row') { - $data['redirect'] = NULL; - if ($redirect_url = $context['entity']->get('redirect')->value) { - $data['redirect'] = Link::fromTextAndUrl($redirect_url, Url::fromUri($redirect_url)); - } - } -} diff --git a/simple_oauth_extras/simple_oauth_extras.permissions.yml b/simple_oauth_extras/simple_oauth_extras.permissions.yml deleted file mode 100644 index 49fb84a..0000000 --- a/simple_oauth_extras/simple_oauth_extras.permissions.yml +++ /dev/null @@ -1,3 +0,0 @@ -grant simple_oauth codes: - title: 'Grant OAuth2 codes' - description: 'Allow using the AuthCode grant' diff --git a/simple_oauth_extras/simple_oauth_extras.routing.yml b/simple_oauth_extras/simple_oauth_extras.routing.yml deleted file mode 100644 index 54da7c9..0000000 --- a/simple_oauth_extras/simple_oauth_extras.routing.yml +++ /dev/null @@ -1,23 +0,0 @@ -oauth2_token_extras.authorize: - path: '/oauth/authorize' - defaults: - _controller: 'Drupal\simple_oauth_extras\Controller\Oauth2AuthorizeController::authorize' - _title: 'Grant Access to Client' - methods: [GET, POST] - requirements: - _access: 'TRUE' - options: - _auth: ['cookie'] - no_cache: TRUE - -oauth2_token.user_debug: - path: '/oauth/debug' - defaults: - _controller: 'Drupal\simple_oauth_extras\Controller\DebugController::debug' - methods: [GET] - requirements: - _access: 'TRUE' - _format: 'json' - options: - _auth: ['oauth2'] - no_cache: TRUE diff --git a/simple_oauth_extras/simple_oauth_extras.services.yml b/simple_oauth_extras/simple_oauth_extras.services.yml deleted file mode 100644 index 74958d4..0000000 --- a/simple_oauth_extras/simple_oauth_extras.services.yml +++ /dev/null @@ -1,4 +0,0 @@ -services: - simple_oauth_extras.repositories.auth_code: - class: Drupal\simple_oauth_extras\Repositories\AuthCodeRepository - arguments: ['@entity_type.manager', '@serializer'] diff --git a/simple_oauth_extras/tests/simple_oauth_extras_test/simple_oauth_extras_test.info.yml b/simple_oauth_extras/tests/simple_oauth_extras_test/simple_oauth_extras_test.info.yml deleted file mode 100644 index b266a9b..0000000 --- a/simple_oauth_extras/tests/simple_oauth_extras_test/simple_oauth_extras_test.info.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: Simple OAuth Extras Test -type: module -description: Test module for Simple OAuth Extras -core: 8.x -package: Testing -hidden: true -dependencies: - - simple_oauth_extras diff --git a/simple_oauth_extras/tests/simple_oauth_extras_test/simple_oauth_extras_test.routing.yml b/simple_oauth_extras/tests/simple_oauth_extras_test/simple_oauth_extras_test.routing.yml deleted file mode 100644 index 6b4c5fa..0000000 --- a/simple_oauth_extras/tests/simple_oauth_extras_test/simple_oauth_extras_test.routing.yml +++ /dev/null @@ -1,8 +0,0 @@ -oauth2_token_extras.test_token: - path: '/oauth/test' - defaults: - _controller: '\Drupal\simple_oauth_extras_test\Controller\RedirectDebug::token' - _title: 'Test Route' - methods: [GET] - requirements: - _access: 'TRUE' diff --git a/simple_oauth_extras/src/Controller/DebugController.php b/src/Controller/DebugController.php similarity index 91% rename from simple_oauth_extras/src/Controller/DebugController.php rename to src/Controller/DebugController.php index d312f60..9090081 100644 --- a/simple_oauth_extras/src/Controller/DebugController.php +++ b/src/Controller/DebugController.php @@ -1,6 +1,6 @@ userPermissions = $user_permissions; diff --git a/simple_oauth_extras/src/Controller/Oauth2AuthorizeController.php b/src/Controller/Oauth2AuthorizeController.php similarity index 95% rename from simple_oauth_extras/src/Controller/Oauth2AuthorizeController.php rename to src/Controller/Oauth2AuthorizeController.php index 72427e7..f10ef7e 100644 --- a/simple_oauth_extras/src/Controller/Oauth2AuthorizeController.php +++ b/src/Controller/Oauth2AuthorizeController.php @@ -1,6 +1,6 @@ get('client_id'); @@ -123,7 +131,7 @@ class Oauth2AuthorizeController extends ControllerBase { $consumer_storage = $this->entityTypeManager()->getStorage('consumer'); } catch (InvalidPluginDefinitionException $exception) { - watchdog_exception('simple_oauth_extras', $exception); + watchdog_exception('simple_oauth', $exception); return RedirectResponse::create(Url::fromRoute('')->toString()); } $client_drupal_entities = $consumer_storage @@ -146,7 +154,7 @@ class Oauth2AuthorizeController extends ControllerBase { if ($this->currentUser()->isAnonymous()) { $this->messenger->addStatus($this->t('An external client application is requesting access to your data in this site. Please log in first to authorize the operation.')); // If the user is not logged in. - $destination = Url::fromRoute('oauth2_token_extras.authorize', [], [ + $destination = Url::fromRoute('oauth2_token.authorize', [], [ 'query' => UrlHelper::parse('/?' . $request->getQueryString())['query'], ]); $url = Url::fromRoute('user.login', [], [ @@ -174,7 +182,7 @@ class Oauth2AuthorizeController extends ControllerBase { } catch (OAuthServerException $exception) { $this->messenger->addMessage($this->t('Fatal error. Unable to get the authorization server.')); - watchdog_exception('simple_oauth_extras', $exception); + watchdog_exception('simple_oauth', $exception); return RedirectResponse::create(Url::fromRoute('')->toString()); } if ($auth_request) { @@ -188,7 +196,7 @@ class Oauth2AuthorizeController extends ControllerBase { ); } } - return $this->formBuilder->getForm('Drupal\simple_oauth_extras\Controller\Oauth2AuthorizeForm'); + return $this->formBuilder->getForm('Drupal\simple_oauth\Controller\Oauth2AuthorizeForm'); } /** diff --git a/simple_oauth_extras/src/Controller/Oauth2AuthorizeForm.php b/src/Controller/Oauth2AuthorizeForm.php similarity index 97% rename from simple_oauth_extras/src/Controller/Oauth2AuthorizeForm.php rename to src/Controller/Oauth2AuthorizeForm.php index c943e72..0d6bded 100644 --- a/simple_oauth_extras/src/Controller/Oauth2AuthorizeForm.php +++ b/src/Controller/Oauth2AuthorizeForm.php @@ -1,6 +1,6 @@ set('public_key', $form_state->getValue('public_key')); $settings->set('private_key', $form_state->getValue('private_key')); $settings->set('remember_clients', $form_state->getValue('remember_clients')); + $settings->set('use_implicit', $form_state->getValue('use_implicit')); $settings->save(); parent::submitForm($form, $form_state); } @@ -191,6 +192,12 @@ class Oauth2TokenSettingsForm extends ConfigFormBase { 'warning' ); } + $form['use_implicit'] = [ + '#type' => 'checkbox', + '#title' => t('Enable the implicit grant?'), + '#description' => t('The implicit grant has the potential to be used in an insecure way. Only enable this if you understand the risks. See https://tools.ietf.org/html/rfc6819#section-4.4.2 for more information.'), + '#default_value' => \Drupal::config('simple_oauth.settings')->get('use_implicit'), + ]; return parent::buildForm($form, $form_state); } diff --git a/src/ExpiredCollector.php b/src/ExpiredCollector.php index 7d15b8c..296f794 100644 --- a/src/ExpiredCollector.php +++ b/src/ExpiredCollector.php @@ -97,8 +97,6 @@ class ExpiredCollector { ])); } catch (QueryException $exception) { - // This happens when simple_oauth_extras is not enabled because the - // 'user_id' field is not available. return $output; } // Append all the tokens for each of the clients having this account as the diff --git a/simple_oauth_extras/src/Grant/ClientCredentialsOverrideGrant.php b/src/Grant/ClientCredentialsOverrideGrant.php similarity index 89% rename from simple_oauth_extras/src/Grant/ClientCredentialsOverrideGrant.php rename to src/Grant/ClientCredentialsOverrideGrant.php index 3c3379d..b494460 100644 --- a/simple_oauth_extras/src/Grant/ClientCredentialsOverrideGrant.php +++ b/src/Grant/ClientCredentialsOverrideGrant.php @@ -1,18 +1,21 @@ get('simple_oauth.settings'); $this->authCodeRepository = $auth_code_repository; $this->refreshTokenRepository = $refresh_token_repository; - // TODO: Make this configurable and not just the same as the access toke expiration. - $this->authCodeExpiration = new \DateInterval(sprintf('PT%dS', $settings->get('access_token_expiration'))); + $this->authCodeExpiration = new \DateInterval( + sprintf('PT%dS', $settings->get('access_token_expiration')) + ); } /** @@ -52,7 +61,7 @@ class AuthorizationCode extends Oauth2GrantBase { $configuration, $plugin_id, $plugin_definition, - $container->get('simple_oauth_extras.repositories.auth_code'), + $container->get('simple_oauth.repositories.auth_code'), $container->get('simple_oauth.repositories.refresh_token'), $container->get('config.factory') ); diff --git a/simple_oauth_extras/src/Plugin/Oauth2Grant/ClientCredentials.php b/src/Plugin/Oauth2Grant/ClientCredentials.php similarity index 68% rename from simple_oauth_extras/src/Plugin/Oauth2Grant/ClientCredentials.php rename to src/Plugin/Oauth2Grant/ClientCredentials.php index eff7b52..fa17912 100644 --- a/simple_oauth_extras/src/Plugin/Oauth2Grant/ClientCredentials.php +++ b/src/Plugin/Oauth2Grant/ClientCredentials.php @@ -1,11 +1,13 @@ get('simple_oauth_extras.settings')->get('use_implicit'); + $enabled = $config_factory->get('simple_oauth.settings')->get('use_implicit'); if (!$enabled) { throw new PluginNotFoundException('implicit'); } diff --git a/simple_oauth_extras/src/Plugin/Oauth2Grant/RefreshToken.php b/src/Plugin/Oauth2Grant/RefreshToken.php similarity index 93% rename from simple_oauth_extras/src/Plugin/Oauth2Grant/RefreshToken.php rename to src/Plugin/Oauth2Grant/RefreshToken.php index f9c6149..1d4f541 100644 --- a/simple_oauth_extras/src/Plugin/Oauth2Grant/RefreshToken.php +++ b/src/Plugin/Oauth2Grant/RefreshToken.php @@ -1,6 +1,6 @@ serializer->normalize($token_entity); - $values['bundle'] = static::$bundle_id; - $new_token = $this->entityTypeManager->getStorage(static::$entity_type_id)->create($values); + $values['bundle'] = static::$bundleId; + $new_token = $this->entityTypeManager->getStorage(static::$entityTypeId)->create($values); if ($token_entity instanceof RefreshTokenEntityInterface) { $access_token = $token_entity->getAccessToken(); @@ -72,7 +72,7 @@ trait RevocableTokenRepositoryTrait { public function revoke($token_id) { if (!$tokens = $this ->entityTypeManager - ->getStorage(static::$entity_type_id) + ->getStorage(static::$entityTypeId) ->loadByProperties(['value' => $token_id])) { return; } @@ -88,7 +88,7 @@ trait RevocableTokenRepositoryTrait { public function isRevoked($token_id) { if (!$tokens = $this ->entityTypeManager - ->getStorage(static::$entity_type_id) + ->getStorage(static::$entityTypeId) ->loadByProperties(['value' => $token_id])) { return TRUE; } @@ -102,7 +102,7 @@ trait RevocableTokenRepositoryTrait { * {@inheritdoc} */ public function getNew() { - $class = static::$entity_class; + $class = static::$entityClass; return new $class(); } diff --git a/src/Repositories/ScopeRepository.php b/src/Repositories/ScopeRepository.php index da47796..4817ff5 100644 --- a/src/Repositories/ScopeRepository.php +++ b/src/Repositories/ScopeRepository.php @@ -9,9 +9,14 @@ use League\OAuth2\Server\Entities\ScopeEntityInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; use Drupal\simple_oauth\Entities\ScopeEntity; +/** + * The repository for scopes. + */ class ScopeRepository implements ScopeRepositoryInterface { /** + * The entity type manager. + * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; @@ -52,7 +57,7 @@ class ScopeRepository implements ScopeRepositoryInterface { $default_user = $client_entity->getDrupalEntity()->get('user_id')->entity; } catch (\InvalidArgumentException $e) { - // Do nothing. This means that simple_oauth_extras is not enabled. + // Do nothing. } /** @var \Drupal\user\UserInterface $user */ $user = $user_identifier diff --git a/tests/simple_oauth_test/simple_oauth_test.info.yml b/tests/simple_oauth_test/simple_oauth_test.info.yml new file mode 100644 index 0000000..c59ea7c --- /dev/null +++ b/tests/simple_oauth_test/simple_oauth_test.info.yml @@ -0,0 +1,8 @@ +name: Simple OAuth Test +type: module +description: Test module for Simple OAuth +core: 8.x +package: Testing +hidden: true +dependencies: + - simple_oauth diff --git a/tests/simple_oauth_test/simple_oauth_test.routing.yml b/tests/simple_oauth_test/simple_oauth_test.routing.yml new file mode 100644 index 0000000..e0052a4 --- /dev/null +++ b/tests/simple_oauth_test/simple_oauth_test.routing.yml @@ -0,0 +1,8 @@ +oauth2_token.test_token: + path: '/oauth/test' + defaults: + _controller: '\Drupal\simple_oauth_test\Controller\RedirectDebug::token' + _title: 'Test Route' + methods: [GET] + requirements: + _access: 'TRUE' diff --git a/simple_oauth_extras/tests/simple_oauth_extras_test/src/Controller/RedirectDebug.php b/tests/simple_oauth_test/src/Controller/RedirectDebug.php similarity index 57% rename from simple_oauth_extras/tests/simple_oauth_extras_test/src/Controller/RedirectDebug.php rename to tests/simple_oauth_test/src/Controller/RedirectDebug.php index 5ac7c94..8ef9cf9 100644 --- a/simple_oauth_extras/tests/simple_oauth_extras_test/src/Controller/RedirectDebug.php +++ b/tests/simple_oauth_test/src/Controller/RedirectDebug.php @@ -1,15 +1,24 @@ getRequestUri()); diff --git a/simple_oauth_extras/tests/src/Functional/AuthCodeFunctionalTest.php b/tests/src/Functional/AuthCodeFunctionalTest.php similarity index 92% rename from simple_oauth_extras/tests/src/Functional/AuthCodeFunctionalTest.php rename to tests/src/Functional/AuthCodeFunctionalTest.php index e6d0af6..e6fbfd4 100644 --- a/simple_oauth_extras/tests/src/Functional/AuthCodeFunctionalTest.php +++ b/tests/src/Functional/AuthCodeFunctionalTest.php @@ -1,50 +1,57 @@ redirectUri = Url::fromRoute('oauth2_token_extras.test_token', [], [ + $this->redirectUri = Url::fromRoute('oauth2_token.test_token', [], [ 'absolute' => TRUE, ])->toString(); $this->client->set('redirect', $this->redirectUri); $this->client->set('description', $this->getRandomGenerator() ->paragraphs()); $this->client->save(); - $this->authorizeUrl = Url::fromRoute('oauth2_token_extras.authorize'); + $this->authorizeUrl = Url::fromRoute('oauth2_token.authorize'); $this->grantPermissions(Role::load(RoleInterface::AUTHENTICATED_ID), [ 'grant simple_oauth codes', ]); @@ -198,20 +205,26 @@ class AuthCodeFunctionalTest extends TokenBearerFunctionalTestBase { $code = $this->getAndValidateCodeFromResponse(); - $response = $this->postGrantedCodeWithScopes($code, $this->scope . ' ' . $this->extraRole->id()); + $response = $this->postGrantedCodeWithScopes( + $code, $this->scope . ' ' . $this->extraRole->id() + ); $this->assertValidTokenResponse($response, TRUE); - // Do another request with the additional scope, this scope is now remembered too. + // Do another request with the additional scope, this scope is now + // remembered too. $valid_params['scope'] = $this->extraRole->id(); $this->drupalGet($this->authorizeUrl->toString(), [ 'query' => $valid_params, ]); $code = $this->getAndValidateCodeFromResponse(); - $response = $this->postGrantedCodeWithScopes($code, $this->scope . ' ' . $this->extraRole->id()); + $response = $this->postGrantedCodeWithScopes( + $code, $this->scope . ' ' . $this->extraRole->id() + ); $this->assertValidTokenResponse($response, TRUE); - // Disable the remember clients feature, make sure that the redirect doesn't happen automatically anymore. + // Disable the remember clients feature, make sure that the redirect doesn't + // happen automatically anymore. $this->config('simple_oauth.settings') ->set('remember_clients', FALSE) ->save(); @@ -241,6 +254,7 @@ class AuthCodeFunctionalTest extends TokenBearerFunctionalTestBase { * Get the code in the response after granting access to scopes. * * @return mixed + * The code. * * @throws \Behat\Mink\Exception\ExpectationException */ diff --git a/simple_oauth_extras/tests/src/Functional/ClientCredentialsFunctionalTest.php b/tests/src/Functional/ClientCredentialsFunctionalTest.php similarity index 93% rename from simple_oauth_extras/tests/src/Functional/ClientCredentialsFunctionalTest.php rename to tests/src/Functional/ClientCredentialsFunctionalTest.php index 3086eb1..7167243 100644 --- a/simple_oauth_extras/tests/src/Functional/ClientCredentialsFunctionalTest.php +++ b/tests/src/Functional/ClientCredentialsFunctionalTest.php @@ -1,19 +1,16 @@ redirectUri = Url::fromRoute('oauth2_token_extras.test_token', [], [ + $this->redirectUri = Url::fromRoute('oauth2_token.test_token', [], [ 'absolute' => TRUE, ])->toString(); $this->client->set('redirect', $this->redirectUri); $this->client->save(); - $this->authorizeUrl = Url::fromRoute('oauth2_token_extras.authorize'); + $this->authorizeUrl = Url::fromRoute('oauth2_token.authorize'); $this->grantPermissions(Role::load(RoleInterface::AUTHENTICATED_ID), [ 'grant simple_oauth codes', ]); @@ -68,7 +73,7 @@ class ImplicitFunctionalTest extends TokenBearerFunctionalTestBase { $assert_session = $this->assertSession(); $assert_session->statusCodeEquals(500); $this - ->config('simple_oauth_extras.settings') + ->config('simple_oauth.settings') ->set('use_implicit', TRUE) ->save(); $this->drupalGet($this->authorizeUrl->toString(), [ @@ -116,7 +121,7 @@ class ImplicitFunctionalTest extends TokenBearerFunctionalTestBase { $assert_session = $this->assertSession(); $assert_session->responseContains('Fatal error. Unable to get the authorization server.'); $this - ->config('simple_oauth_extras.settings') + ->config('simple_oauth.settings') ->set('use_implicit', TRUE) ->save(); $this->drupalGet($this->authorizeUrl->toString(), [ diff --git a/simple_oauth_extras/tests/src/Functional/RefreshFunctionalTest.php b/tests/src/Functional/RefreshFunctionalTest.php similarity index 95% rename from simple_oauth_extras/tests/src/Functional/RefreshFunctionalTest.php rename to tests/src/Functional/RefreshFunctionalTest.php index 0cf55e7..643d2ee 100644 --- a/simple_oauth_extras/tests/src/Functional/RefreshFunctionalTest.php +++ b/tests/src/Functional/RefreshFunctionalTest.php @@ -1,22 +1,22 @@