2017 © Pedro Peláez
 

craft-plugin patron

An OAuth2 Client for Craft CMS

image

flipboxfactory/patron

An OAuth2 Client for Craft CMS

  • Tuesday, July 17, 2018
  • by nateiler
  • Repository
  • 2 Watchers
  • 0 Stars
  • 944 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 8 Versions
  • 570 % Grown

The README.md

An OAuth2 client manager for Craft CMS

Join the chat at https://gitter.im/flipboxfactory/patron Latest Version Software License Build Status Coverage Status Quality Score Total Downloads, (*1)

Patron is an OAuth2 client manager; Providing an easy to use interface for managing OAuth2 providers and tokens., (*2)

Screenshot, (*3)

Requirements

This plugin requires Craft CMS 3.0 or later., (*4)

Installation

Choose one of the following ways to add Patron to your project:, (*5)

  1. Composer:, (*6)

    Simply run the following command from your project root:, (*7)

    composer require flipboxfactory/patron
    
  2. Craft CMS Plugin Store:, (*8)

    Within your Craft CMS project admin panel, navigate to the 'Plugin Store' and search for 'Patron'. Installation is a button click away., (*9)

Once the plugin is included in your project, navigate to the Control Panel, go to Settings → Plugins and click the “Install” button for Patron., (*10)

Features

Patron provides an Craft CMS admin interface for The PHP League's OAuth2 client package. Additional features include: * Project Config compatible * Provider locking (for plugin developers) * Ships with native providers: Facebook, GitHub, Google, LinkedIn, Instagram * Register your own OAuth2 Providers, (*11)

Templating

The craft.patron template variable provides access to the entire Patron plugin. However, there are two useful tags worth highlighting:, (*12)

Retrieving providers:, (*13)

{% set providerQuery = craft.patron.providers %}
{% set provider = providerQuery.handle('providerHandle').one() %}

Retrieving tokens:, (*14)

{% set tokenQuery = craft.patron.tokens %}
{% set token = tokenQuery.provider('providerHandle').one() %} {# a token associated to a provider #}

Screenshots

Proviers, (*15)

Update, (*16)

Tokens, (*17)

Settings, (*18)


Settings

The settings (including provider configurations) can be overridden with the plugins configuration file: config/patron.php, (*19)

It's recommended that sensitive data (such as the client secret) is accessed via environmental variables:, (*20)

[
    'providerHandle' => [
        'clientId' => getenv('SOME_PROVIDER_CLIENT_ID'),
        'clientSecret' => getenv('SOME_PROVIDER_CLIENT_SECRET'),
    ],
    'anotherProviderHandle' => [
            'clientId' => getenv('SOME_OTHER_PROVIDER_CLIENT_ID'),
            'clientSecret' => getenv('SOME_OTHER_PROVIDER_CLIENT_SECRET'),
        ]
]

Third Party Providers

Adding addition providers to Patron is handled through the following events:, (*21)

  1. Register a compatible The PHP League OAuth2 provider using a fully qualified class name. The PHP League has an extensive list that have been contributed by the community., (*22)

    \yii\base\Event::on(
        \flipbox\patron\cp\Cp::class,
        \flipbox\patron\events\RegisterProviders::REGISTER_PROVIDERS,
        function (\flipbox\patron\events\RegisterProviders $event) {
            $event->providers[] = '\your\fully\qualified\provider\class\name'; // Ex: \Stevenmaguire\OAuth2\Client\Provider\Salesforce::class
        }
    );
    
  2. [Optional] Register a settings interface for the Provider. If your provider can be configured, the settings interface will enable configuration inputs via the Craft CP. The settings interface will be registered on the same provider class in step 1., (*23)

    \yii\base\Event::on(
        '\your\fully\qualified\provider\class\name', // Ex: \Stevenmaguire\OAuth2\Client\Provider\Salesforce::class
        \flipbox\patron\events\RegisterProviderSettings::REGISTER_SETTINGS,
        function (\flipbox\patron\events\RegisterProviderSettings $event) {
            $event->class = '\your\fully\qualified\settings\class\name';  // Ex: \flipbox\patron\salesforce\settings\SalesforceSettings::class
        }
    );
    
  3. [Optional] Register additional info for the Provider. Throughout the Craft CP we use a provider name and icon. Register the following in order to specify these values:, (*24)


    \yii\base\Event::on( \flipbox\patron\cp\Cp::class, \flipbox\patron\events\RegisterProviderInfo::REGISTER_INFO, function (\flipbox\patron\events\RegisterProviderInfo $event) { $event->info['\your\fully\qualified\provider\class\name] = [ 'name' => 'Your Provider', 'icon' => '/path/to/icon.svg' // Ex: '@vendor/flipboxfactory/patron-salesforce/icons/salesforce.svg' ]; } );

As an example, here are a few third-party provider packages to reference: * Salesforce OAuth2 Provider for Patron * HubSpot OAuth2 Provider for Patron, (*25)

Provider Locking

A provider can be 'locked' by a plugin. As a result, only the plugin (that locked it) can delete the provider. This is useful when another plugin is using Patron to manage it's OAuth2 connections, which may not be apparent., (*26)

```php

/** @var \flipbox\patron\records\Provider $provider */
/** @var \craft\base\PluginInterface $yourPlugin */


$provider->saveAndLock($yourPlugin);

```

Contributing

Please see CONTRIBUTING for details., (*27)

Credits

License

The MIT License (MIT). Please see License File for more information., (*28)

The Versions