Closed (fixed)
Project:
Migrate Plus
Version:
8.x-4.0
Component:
Plugins
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
6 Jul 2016 at 14:05 UTC
Updated:
21 Dec 2018 at 15:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mikeryanMy current project needs OAuth support, so let's throw that in too...
Comment #3
mikeryanSee #2762499: Rearrange Url plugin configuration - this is the point (adding fetcher-specific configuration) that the idea of rearranging the configuration that's been rattling around the back of my mind reaches the front of my mind... So, if we took that approach, it might look like
or
(each authentication type defining its particular set of parameters).
Thoughts?
Comment #4
mikeryanAnd... Should we, instead of building each authentication type directly into the http plugin, implement them as plugins? Or is that overdesigning?
Comment #5
moshe weitzman commentedSure, I think some nesting improves clarity. To be honest though, folks coy/paste the examples and press on.
I cant spot the difference between your two examples. The first examples specifies the url source but the second doesn't.
Comment #6
moshe weitzman commentedI can see value in not jamming everything into its the same http plugin. In my patch the key work happens in getOptions(). I would think that each auth method could extend same class and override getOptions()?
Comment #7
mikeryanI'll hold off on the rearrangement for now - I played enough with it to be convinced BC will be simple enough, we can do that later.
This untested patch sets up an Authentication plugin type - there's a lot of boilerplate, but the specific authentication plugins themselves are simple enough. What I'd like to do next is actually put basic auth on the /migrate_example_advanced_position endpoint so we have a real test and demonstration of authentication, haven't quite figured that out - the basic_auth module authenticates against Drupal users, while we'd like to set a hard-coded username/password for the REST endpoint here.
The Authentication plugin has a single method, authenticate(), returning an array of options to be passed to Guzzle after merging with any other explicitly-provided headers. The basic and digest providers don't have to do anything but return the proper arrays, but oauth2 will need to deal with obtaining an access token.
Comment #8
mikeryan*This* untested patch, I meant...
Comment #9
mikeryanAs for oauth2 support, it's not builtin to Guzzle but CommerceGuys have a plugin: https://github.com/commerceguys/guzzle-oauth2-plugin.
Comment #10
mikeryanBelay that - it doesn't support Guzzle 6.
Comment #11
mikeryanThere's a fork of that plugin purportedly supporting Guzzle 6: https://packagist.org/packages/sainsburys/guzzle-oauth2-plugin. Will look into that... What are best practices for handling an external dependency for a specific plugin within a module, when you don't want the whole module dependent?
Comment #12
moshe weitzman commentedIn composer, you can suggest a dependency. I think thats the closest analogue. Your other options are to break out the oauth stuff into a separate module that requires oauth package, or users of your module have the oauth package even if they dont need it.
Comment #13
mikeryanThis works with my OAuth2 feed, untested with basic/digest authentication.
Comment #14
moshe weitzman commentedLooks great.
authenticate() doesn't actually perform authentication. I might rename to getOptions(), but thats minor. Perhaps be explicit and say: "Any option listed at http://docs.guzzlephp.org/en/latest/request-options.html is valid."
Comment #15
mikeryanWith OAuth I was thinking of the preliminary get-a-token stuff as authentication, but right, the actual authentication happens on the request. Maybe something more explicit like getAuthentiationOptions()?
Oh, yeah - definitely need to point to the guzzle plugin info since that determines the available parameters (unfortunately, that is under-documented).
"add to a different migration"?
This is handled through the plugin manager, which is constructed with the annotation namespace (Drupal\migrate_plus\Annotation\Authentication) and the namespace where plugins using that annotation may be discovered (Plugin/migrate_plus/authentication). So, a plugin manager for another "Authentication" plugin type won't see these plugins, and our plugin manager won't see theirs. I get your point though - "Authentication" is broad enough to be likely used for other plugins, which may be confusing to humans if not the plugin managers...
Comment #16
mikeryanUpdated patch.
Comment #17
mikeryanRemoving the example until/unless it works.
Comment #19
mikeryanComment #20
geerlingguy commentedNote that the above patch didn't make it into 8.x-2.0-beta2 (it seems like a few of the patches were committed just after that tag was created?). Had me puzzled since I thought it was :)
Comment #22
merilainen commentedAnyone have any idea how to use this?
Comment #23
mrkdboyd commentedThis worked for me. Make sure you
composer require sainsburys/guzzle-oauth2-plugin:^3.0.Comment #24
hazong commentedHey community,
I’m trying to migrate some data from a remote rest/api (son). Here is my current migration iml file.
I also enabled the migrate_plus and migrate_tools
Running the command ‘drush ms’ provides the following error:
‘Class 'Sainsburys\Guzzle\Oauth2\GrantType\ClientCredentials' not found in /usr/share/nginx/html/modules/contrib/migrate_plus/src/Plugin/migrate_plus/authentication/OAuth2.php’
Could some one help me try to understand what is happening or how I can handle this issue?
Thank you in advance
Comment #25
hazong commentedComment #26
johnle commented@hazong,
You need to do a
composer require sainsburys/guzzle-oauth2-pluginI am not sure of this oauth2 plugin is still maintain or being abandon.
Comment #27
johnle commentedOops accidentally hit submit.
Comment #28
heddnPlease open a new issue. Don't reopen a feature issue from 2 years.