What's the proper way to create a plugin that uses and extends another author’s plugin? I’m creating a plugin that will ultimately create new entries using the Moves API (https://dev.moves-app.com). The Moves API needs OAuth make authenticated calls on a user's account, so I'm using Dukt's OAuth plugin (https://dukt.net/craft/oauth) to handle the OAuth authentication process.

I actually have it up and running, but to create an Oauth provider that isn't supported natively by Dukt's plugin, I've added files to their folders.

Here’s what I’ve done.


Created a Moves.php file in the craft/plugins/oauth/vendor/chrisnharvey/oauth/src/Oauth/Provider/ folder that sets up the necessary info to communicate w/ the Moves API - Link to source: https://gist.github.com/bwlng/2cb486c8d83001deae19#file-moves-php
Created a MovesOAuthProviderSource.php file in the craft/plugins/oauth/vendor/chrisnharvey/oauth/providers/folder that echoes the other providers Dukt supports out of the box. Link to source: https://gist.github.com/bwlng/2cb486c8d83001deae19#file-movesoauthprovidersource-php


Is there a better way to do this? Ideally want to require the Dukt plugin be installed, and then keep the code I've linked to above in my own folder in craft/plugins/moves.
Adding a new provider to OAuth plugin is a two step process:

Create a new OAuth Provider in lusitanian/oauth

The first thing you will need to do is to add support for your new provider in lusitanian/oauth OAuth PHP library. This library supports OAuth 1 &amp; 2 authentication process and you can give a look at other providers to get started writing your own. 

It's usually just a matter of a smart copy paste from the code of another provider, by updating:


scopes
api URL
authorize URL
access token URL


That said, you will sometimes have to adjust your code to support the web service's specificities. Read your web service's authentication docs carefully to understand who they implemented the OAuth authentication process and you'll be good to go.

So when your provider is ready, just perform a pull request on lusitanian/oauth OAuth PHP library on GitHub. We're pulling new providers on each Craft OAuth plugin release, so if you got your provider added to lusitanian's library, it will be automatically part of Craft OAuth plugin's next release.

At this point, if you add your new provider in Craft OAuth plugin code, it won't do anything and the provider will not appear in OAuth settings.

Create an OAuth Provider Source in the OAuth plugin

The OAuth provider source class makes the link between between your lusitanian/oauth provider and Craft OAuth plugin.

You should name the file based on lusitanian/oauth's provider file name and save it under oauth/providers folder. For example if your lusitanian/oauth provider file is named Vimeo.php, you provider source file will be named VimeoOAuthProviderSource.php.

This file contains basic informations like the web service's console url, its name, and a simple getAccount() method, and when you'll add it to the oauth/providers folder, your provider will start showing up in Craft CP / Plugin / OAuth.

When you're ready with your OAuth provider source, perform a pull request on Craft OAuth plugin on GitHub and your provider will be added to the next release.

Checking that OAuth plugin is installed

In your plugin, you will have to check that OAuth is installed before using it in order to prevent errors.

In your templates you can check that OAuth plugin is installed this way:

{% if craft.oauth is not defined %}

    {# OAuth plugin not installed #}

{% else %}

    {# OAuth installed #}

{% endif %}


In your php files, you could do it that way:

$plugin = craft()-&gt;plugins-&gt;getPlugin('oauth');

if(!$plugin)
{
    // oauth is not installed
}
else
{
    // oauth is installed
}


I'm working on a step by step guide on how to implement OAuth in Craft plugin. It's not ready yet but I'll probably start to share the draft in August.