1. Go to this page and download the library: Download venveo/craft-oauthclient library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
venveo / craft-oauthclient example snippets
use League\OAuth2\Client\Provider\YOUR_PROVIDER_CLASS as LeagueProvider;
use venveo\oauthclient\base\Provider;
class MyProvider extends Provider
{
/**
* @inheritDoc
*/
public static function displayName(): string
{
// This is what is displayed in the CP when registering an App
return 'My Provider';
}
public static function getProviderClass(): string
{
// Return the class name for the league provider
return LeagueProvider::class;
}
}
use venveo\oauthclient\events\AuthorizationUrlEvent;
use venveo\oauthclient\services\Apps;
use yii\base\Event;
// [...]
Event::on(Apps::class, Apps::EVENT_GET_URL_OPTIONS, function (AuthorizationUrlEvent $e) {
if ($e->context === 'cp' && $e->app->handle === 'google') {
// Force re-consent during OAuth
$e->options['prompt'] = 'consent';
$e->options['access_type'] = 'offline';
$e->options['approval_prompt'] = null;
}
});
Event::on(AuthorizeController::class, AuthorizeController::EVENT_BEFORE_AUTHENTICATE, function (AuthorizationEvent $event) {
if ($event->context === 'my-custom-context') {
$event->returnUrl = 'https://google.com';
}
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.