Download the PHP package venveo/craft-oauthclient without Composer
On this page you can find all versions of the php package venveo/craft-oauthclient. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download venveo/craft-oauthclient
More information about venveo/craft-oauthclient
Files in venveo/craft-oauthclient
Informations about the package craft-oauthclient
OAuth 2.0 Client plugin for Craft CMS 3
This plugin provides developers with an easy centralized approach to managing and storing OAuth 2.0 clients and tokens.
It exposes an easy to use API and frontend for authorizing tokens for internal business logic. What it does not do is act as an authentication provider for users to login to the CMS.
Features
- Simple API for integrating League OAuth Providers
- Lots of events for developers
- CLI for refreshing tokens
- Project config support
- 1-line Twig helper for generating authentication UI in your module
Example Use Cases
- Building a custom CRM integration
- Reading from and writing to Google Sheets
- Querying data on a business' Facebook page
Example Non-Use Cases
- Logging-in users on the frontend
- Allowing users to access the CP via social accounts
- Keeping track of many CMS users' social accounts
Requirements
This plugin should work on Craft CMS 3.1.34.3 or later
Installation
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require venveo/craft-oauthclient
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for OAuth 2.0 Client.
- Configure on Craft settings page
Providers
A provider in this context is an OAuth 2.0 server that is exposing an API via token authorization. Out of the box, this plugin ships with the following providers:
- GitHub
The plugin utilizes the widely used oauth2-client
project by thephpleague in order to make adding providers as
painless as possible. We add an additional layer to this abstraction in order to mix in requirements for Craft.
Creating a Provider
Assuming a League provider already exists for your service, you can easily create your own implementation. In your module or plugin, create a file for the provider and follow this outline:
And now you need only register it in your plugin or module's init function:
php <?php use venveo\oauthclient\services\Providers; use craft\events\RegisterComponentTypesEvent; use MyProvider; // [...] Event::on(Providers::class, Providers::EVENT_REGISTER_PROVIDER_TYPES, function (RegisterComponentTypesEvent $event) { $event->types[] = MyProvider:class });
Using the Twig variable to check if the current user is connected
Modifying the authentication flow conditionally
Example 1: Modifying the OAuth Provider Settings
In this example, we'll render the connector with a context and register an event to modify the authorization parameters before the connection URL is rendered.
Example 2: Modifying the OAuth flow based on context
If we wanted to adjust the return URL the user is brought to after authenticating, we have two approaches. The first is quite simple and uses standard Craft form redirects:
The 2nd case is more complicated, and that's when we don't have a form, but instead just a button to the app.getRedirectUrl()
Since it's not a POST request, we need to make use of context
to modify the flow. We'll call our context "my-custom-context" and invoke the redirect URL with that context:
Now in our module or plugin, we can just register an event handler for the AuthorizeController controller:
Success! Now upon logging in, the user will be sent to Google.
Brought to you by Venveo
All versions of craft-oauthclient with dependencies
league/oauth2-client Version ^2.2.1
league/oauth2-google Version ^2.2
league/oauth2-facebook Version ^2.0
league/oauth2-github Version ^2.0