PHP code example of scottybo / socialite-wordpress-wp-oauth-server

1. Go to this page and download the library: Download scottybo/socialite-wordpress-wp-oauth-server 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/ */

    

scottybo / socialite-wordpress-wp-oauth-server example snippets


/**
 * The event handler mappings for the application.
 *
 * @var array
 */
protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        // add your listeners (aka providers) here
        'SocialiteProviders\\WordPressSelfHosted\\WordPressSelfHostedExtendSocialite@handle',
    ],
];

'wordpress_self_hosted' => [
    'client_id' => env('WORDPRESS_SELF_HOSTED_KEY'),
    'client_secret' => env('WORDPRESS_SELF_HOSTED_SECRET'),
    'redirect' => env('WORDPRESS_SELF_HOSTED_REDIRECT_URI')
    'endpoints' => [
        'authorize' => 'https://www.thirty.site/oauth/authorize/',
        'introspection' => 'https://www.thirty.site/oauth/introspection/',
        'me' => 'https://www.thirty.site/oauth/me/',
        'token' => 'https://www.thirty.site/oauth/token/',
    ]
],

'wordpress_self_hosted' => [
    'client_id' => 'abc123',
    'client_secret' => 'abc123',
    'redirect' => 'https://app.laravel.site/auth/wordpress_self_hosted/callback';
    'endpoints' => [
        'authorize' => 'https://www.selfhosted.site/oauth/authorize/',
        'introspection' => 'https://www.selfhosted.site/oauth/introspection/',
        'me' => 'https://www.selfhosted.site/oauth/me/',
        'token' => 'https://www.selfhosted.site/oauth/token/',
    ]
],

return Socialite::with('WordPressSelfHosted')->redirect();

// to turn off stateless
return Socialite::with('WordPressSelfHosted')->stateless(false)->redirect();

// to use stateless
return Socialite::with('WordPressSelfHosted')->stateless()->redirect();

$clientId = "secret";
$clientSecret = "secret";
$redirectUrl = "http://yourdomain.com/api/redirect";
$additionalProviderConfig = ['site' => 'meta.stackoverflow.com'];
$config = new \SocialiteProviders\Manager\Config($clientId, $clientSecret, $redirectUrl, $additionalProviderConfig);
return Socialite::with('WordPressSelfHosted')->setConfig($config)->redirect();

$user = Socialite::driver('WordPressSelfHosted')->user();
$accessTokenResponseBody = $user->accessTokenResponseBody;
 php
'providers' => [
    // a whole bunch of providers
    // remove 'Laravel\Socialite\SocialiteServiceProvider',
    \SocialiteProviders\Manager\ServiceProvider::class, // add
];