reverted: --- b/simple_oauth.install +++ /dev/null @@ -1,23 +0,0 @@ -schema(); - if ($schema->tableExists('consumer') && !$schema->fieldExists('consumer', 'third_party')) { - $field = [ - 'type' => 'int', - 'size' => 'tiny', - 'not null' => FALSE, - ]; - $schema->addField('consumer', 'third_party', $field); - } -} reverted: --- b/simple_oauth.module +++ a/simple_oauth.module @@ -83,21 +83,6 @@ 'type' => 'options_buttons', 'weight' => 5, ]); - - $fields['third_party'] = BaseFieldDefinition::create('boolean') - ->setLabel(new TranslatableMarkup('Is this client 3rd party?')) - ->setDescription(new TranslatableMarkup('A boolean indiacting whether the client is 3rd party or not.')) - ->setDisplayOptions('view', [ - 'label' => 'inline', - 'type' => 'boolean', - 'weight' => 4, - ]) - ->setDisplayOptions('form', [ - 'weight' => 4, - ]) - ->setRevisionable(TRUE) - ->setTranslatable(TRUE) - ->setDefaultValue(TRUE); } return $fields; } diff -u b/simple_oauth_extras/simple_oauth_extras.routing.yml b/simple_oauth_extras/simple_oauth_extras.routing.yml --- b/simple_oauth_extras/simple_oauth_extras.routing.yml +++ b/simple_oauth_extras/simple_oauth_extras.routing.yml @@ -1,8 +1,8 @@ oauth2_token_extras.authorize: path: '/oauth/authorize' defaults: - _controller: 'Drupal\simple_oauth_extras\Controller\Oauth2AuthorizeController::authorize' - _title: 'Grant Access to Client' + _controller: 'Drupal\simple_oauth_extras\Controller\Oauth2AuthorizeController::authorize' + _title: 'Grant Access to Client' methods: [GET, POST] requirements: _access: 'TRUE' diff -u b/simple_oauth_extras/src/Controller/Oauth2AuthorizeController.php b/simple_oauth_extras/src/Controller/Oauth2AuthorizeController.php --- b/simple_oauth_extras/src/Controller/Oauth2AuthorizeController.php +++ b/simple_oauth_extras/src/Controller/Oauth2AuthorizeController.php @@ -56,15 +56,32 @@ if (empty($client_uuid)) { throw OAuthServerException::invalidClient(); } - $client_drupal_entities = $this->entityTypeManager()->getStorage('consumer')->loadByProperties([ - 'uuid' => $client_uuid, - ]); + $client_drupal_entities = $this->entityTypeManager() + ->getStorage('consumer') + ->loadByProperties([ + 'uuid' => $client_uuid, + ]); if (empty($client_drupal_entities)) { throw OAuthServerException::invalidClient(); } $client_drupal_entity = reset($client_drupal_entities); - if ($this->currentUser()->isAuthenticated() && $client_drupal_entity->get('third_party')->getString() == 0) { + + $accessPreviouslyConfirmed = false; + + $previous_token_entities = $this->entityTypeManager() + ->getStorage('oauth2_token') + ->loadByProperties([ + 'auth_user_id' => $this->currentUser()->id(), + 'client' => $client_uuid, + ]); + if(!empty($previous_token_entities)){ + $accessPreviouslyConfirmed = true; + } + + if ($this->currentUser() + ->isAuthenticated() && ($client_drupal_entity->get('third_party') + ->getString() == 0 || $accessPreviouslyConfirmed)) { if ($request->get('response_type') == 'code') { $grant_type = 'code'; } @@ -80,9 +97,11 @@ $user_entity = new UserEntity(); $user_entity->setIdentifier($this->currentUser()->id()); $auth_request->setUser($user_entity); - $can_grant_codes = $this->currentUser()->hasPermission('grant simple_oauth codes'); + $can_grant_codes = $this->currentUser() + ->hasPermission('grant simple_oauth codes'); $auth_request->setAuthorizationApproved($can_grant_codes); - $response = $server->completeAuthorizationRequest($auth_request, new Response()); + $response = $server->completeAuthorizationRequest($auth_request, + new Response()); $redirect_response = TrustedRedirectResponse::create( $response->getHeaderLine('location'), $response->getStatusCode(), @@ -92,7 +111,8 @@ } } else { - return \Drupal::formBuilder()->getForm('Drupal\simple_oauth_extras\Controller\Oauth2AuthorizeForm'); + return \Drupal::formBuilder() + ->getForm('Drupal\simple_oauth_extras\Controller\Oauth2AuthorizeForm'); } }