Add support for feeds requiring OAuth 2.0 Authorization

Created on 5 February 2019, almost 6 years ago
Updated 10 September 2024, 2 months ago

Problem/Motivation

One of the feeds for which I want to use this module requires using OAuth Authorization. More and more APIs are adding OAuth Authorization like this, particularly for private or sensitive data. This type of authorization is different than the HTTP Basic Authorization that is referenced in the related issue.ed in the issue marked as related.

Proposed resolution

Feeds is the best D8 module for importing feeds and it seems that adding support for OAuth Authorization would not only really help everyone out, but be a natural and great addition for this module.

Remaining tasks

  • Discuss and decide how to handle the HttpFetcher's get() method signature.
  • Add support for Authentication Code grant type or remove from options.
  • Reviews needed.
  • Tests need to be written.

User interface changes

  • When adding a Feed Type, in the fetcher section for HTTP Fetchers, there is now an option for enabling OAuth Authorization.
  • If this feature is enabled, each Feed of that Feed Type will have the option to enable the use of this authorization and then enter the necessary parameters to authorize according to the relevant grant type.
Feature request
Status

Needs work

Component

Code

Created by

🇺🇸United States tclark62

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States cainaru Norwood, NY, USA

    A while back when testing this, I noticed that other feeds that are using HTTP Basic Auth, but not Oauth, start failing with this patch. I wonder if modifying the submitConfigurationForm like the following might help (particularly with the failing tests) ?

      public function submitConfigurationForm(array &$form, FormStateInterface $form_state, FeedInterface $feed = NULL) {
        $feed->setSource($form_state->getValue('source'));
        // Only submit these if the feed has the Oauth option present.
        if (isset($form_state->getValue('authorization_options')['feed_authorization_setting'])) {
          $feed_config = [
            'feed_authorization_setting' => $form_state->getValue('authorization_options')['feed_authorization_setting'],
            'access_token_url' => $form_state->getValue('authorization_options')['access_token_url'],
            'grant_type' => $form_state->getValue('authorization_options')['grant_type'],
            'client_id' => $form_state->getValue('authorization_options')['client_id'],
            'scope' => $form_state->getValue('authorization_options')['scope'],
            'username' => $form_state->getValue('authorization_options')['username'],
          ];
          $client_secret = $form_state->getValue('authorization_options')['client_secret'];
          $password = $form_state->getValue('authorization_options')['password'];
    
          // Only save the client secret and/or password if they have been changed.
          if (!empty($client_secret)) {
            $feed_config['client_secret'] = $client_secret;
          }
          if (!empty($password)) {
            $feed_config['password'] = $password;
          }
          $feed->setConfigurationFor($this->plugin, $feed_config);
        }
      }
    

    And perhaps setting the feed_authorization_setting to FALSE in defaultFeedConfiguration()?

  • 🇺🇸United States jgoodwill01

    Any updates on this patch? Would love to have oath 2.0 feed imports!

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    696 pass, 2 fail
  • 🇺🇸United States sclsweb

    I'm trying to use this patch, entering all the credentials, but when attempting to import, I get:

    The feed from https://example.libcal.com/1.1/events?cal_id=19407 seems to be broken because of error "Client error: `GET https://example.libcal.com/1.1/events?cal_id=19407` resulted in a `403 Forbidden` response: You do not have permission to perform this operation. ".

    The same credentials work to get data in Postman (API endpoint URL, grant type, access token URL, client ID & secret). Is this an issue with the patch? Any advice for debugging?

  • 🇺🇸United States sclsweb

    Update: I changed the scope and it worked! There was a log message that didn't display on the import screen, that identified the scope as the problem.

  • 🇺🇸United States sclsweb

    Update: I changed the scope and it worked! There was a log message that didn't display on the import screen, that identified the scope as the problem.

    Would love to see this ultimately committed. I have a production site that wants to use it.

  • 🇺🇸United States Greg Boggs Portland Oregon

    Different APIs require different scopes, Scope needs to be a configuration along side user and password.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update 5 months ago
    715 pass, 2 fail
  • 🇨🇦Canada dylan donkersgoed London, Ontario

    I merged in the latest 8.x-3.x branch. Rerolled patch for 8.x-3.0-beta4 attached as well.

  • Pipeline finished with Failed
    5 months ago
    Total: 1401s
    #192053
  • 🇺🇸United States Greg Boggs Portland Oregon

    The patch needs a re-roll for Beta5

  • 🇺🇸United States Greg Boggs Portland Oregon

    The current patch makes oauth scope a required field. However, some APIs don't use Oauth scope. So this patch makes oauth scope optional. Still needs a reroll for Beta 5

  • 🇺🇸United States Greg Boggs Portland Oregon

    mucked up the patch file last time. trying again.

  • 🇺🇸United States Greg Boggs Portland Oregon

    Ok, apparently I have forgotten how to patch. This one will work, I think.

  • 🇺🇸United States SocialNicheGuru

    Does not apply to 3.0-rc1

  • 🇮🇳India bhavanir

    The patch not working for the RC version of the module - composer require 'drupal/feeds:^3.0@RC' . Kindly check and provide.

  • 🇺🇸United States SocialNicheGuru

    MR 98 does apply to feeds 3.0-rc2

  • Pipeline finished with Failed
    9 days ago
    Total: 291s
    #331336
  • 🇨🇦Canada dylan donkersgoed London, Ontario

    I've fixed the conflicts in the MR. Also attaching a patch for the 3.0-rc2 version.

  • 🇨🇦Canada dylan donkersgoed London, Ontario

    That last patch doesn't work with composer, uploading another in diff format.

Production build 0.71.5 2024