Migrating from an OAuth2 authenticated JSON feed

Migrating from an OAuth2 authenticated JSON feed
mikeryan
Monday, June 4, 2020 – 10:24am
Continuing with techniques from the “Acme” project, another ongoing feed I implemented was import from a JSON feed protected by OAuth2 authentication into “doctor” nodes. Let’s look first at the community contributions we needed to implement this.

Community contributions

Provide authentication plugins to HTTP fetcher – Moshe Weitzman had already suggested (and provided a patch for) adding basic and digest authentication to the HTTP fetcher plugin. I broadened the scope to add an Authentication plugin type, and implemented an OAuth2 authentication plugin.

Implement xpath-like selectors for the JSON parser – The JSON parser, from Karen Stevenson’s original JSON source plugin, used a numeric depth to retrieve data elements. The JSON feed we had here did not work with that approach, because at the top level in addition to the array containing our data was another array (and the depth approach would draw from both arrays). Implementing a means to select fields with a /-separated syntax made this much more flexible.

Project implementation

So, let’s look at the source plugin implementation:

source:
plugin: url
# We want to reimport any doctors whose source data has changed.
track_changes: true
# Counting the available records requires fetching the whole feed – cache the
# counts to minimize overhead.
cache_counts: true
# Until https://www.drupal.org/project/drupal/issues/2751829 is fixed, this
# should be used in conjunction with cache_counts in most cases. It was not
# strictly necessary in this project because this was the only cached ‘url’
# source plugin.
cache_key: doctor
data_fetcher_plugin: http
data_parser_plugin: json
item_selector: /providers
# Note that the source .yml file does not contain the urls, or half the
# authentication configuration – these are merged in using the configuration
# UI (see http://virtuoso-performance.com/blog/mikeryan/configuring-migrations-form).
# We present sample values here so you can see what the complete configuration
# looks like.
# The endpoint from which the data itself is fetched.
urls: https://kservice.example2.com/providers
# The http fetcher plugin calls the authentication plugin (if present),
# which accepts plugin-specific configuration and returns the appropriate
# authentication headers to add to the HTTP request.
authentication:
# migrate_plus also has ‘basic’ and ‘digest’ authentication plugins.
plugin: oauth2
# The grant type used by the feed (other grant types supported in theory,
# but untested, are authorization_code, password, refresh_token, and
# urn:ietf:params:oauth:grant-type:jwt-bearer.
grant_type: client_credentials
# The base URI for retrieving the token (provided through the UI).
base_uri: https://kservice.example2.com
# The relative URL for retrieving the token.
token_url: /oauth2/token
# The client ID for the service (provided through the UI).
client_id: default_client_id
# The client secret for the service (provided through the UI).
client_secret: abcdef12345678

The ids and fields configuration operate as they do with other JSON and XML feeds I’ve blogged about.

Tags
Planet Drupal maintenance support plans

Drupal maintenance support plans

Migration

Use the Twitter thread below to comment on this post:

https://t.co/KJzBIauuVG
— Drupal Update (@VirtPerformance) June 4, 2020

 


Source: New feed

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Migrating from an OAuth2 authenticated JSON feed

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.