PHP code example of ahilmurugesan / socialite-apple

1. Go to this page and download the library: Download ahilmurugesan/socialite-apple 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/ */

    

ahilmurugesan / socialite-apple example snippets


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

"apple" => [    
  "client_id" => env("APPLE_CLIENT_ID"),  
  "client_secret" => env("APPLE_CLIENT_SECRET"),  
  "redirect" => env("APPLE_REDIRECT_URI"),
  "key_id" => env("APPLE_KEY_ID"),  
  "team_id" => env("APPLE_TEAM_ID"),  
  "auth_key" => env("APPLE_AUTH_KEY"),  
  "client_secret_updated_at" => env("APPLE_CLIENT_SECRET_UPDATED_AT"),  
  "refresh_token_interval_days" => env("APPLE_REFRESH_TOKEN_INTERVAL_DAYS"),  
],

// authorize with provider
return Socialite::with('apple')->redirect();

// fetch user after callback
$user = Socialite::with('apple')->user();

// fetch user using token ( token from apple authentication )
$token = "eyJraWQiOiJlWGF1bm1MIiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLnZvbmVjLnNpd2EuYXBpIiwiZXhwIjoxNTg3OTI2MjAzLCJpYXQiOjE1ODc5MjU2MDMsInN1YiI6IjAwMTcxMC44NThkN2NhNWUwZDg0MWI5ODFiNGVkYWY2NWM0M2ZmNi4xOTMyIiwiYXRfaGFzaCI6IjRHZFprR0k2X2Q3Qk5xMFFJTkhKZEEiLCJlbWFpbCI6ImFoaWxtdXJ1Z2VzYW5AZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOiJ0cnVlIiwiYXV0aF90aW1lIjoxNTg3OTI1NjAxLCJub25jZV9zdXBwb3J0ZWQiOnRydWV9.ciXdwwkySnG-Ne_l9NqxuLkDPyptUVvJ_Puk10LSsXNEtLBAijskQhIjwi3HYsEXNLdlbMGfJ25rnlMWu93RoqYJFo_u_rFjH_4Xt9E_ddnqY147yZvVw5k912FtXabQSl2bFiR7yrzuQvznxyAiYFP9v9HvXyTcYS2ki6ISdPjmTyb927yWyGDx-aigksV752toAA8XXmjjEyi01eY-wng4CaV4mxjJU_bQSpnh6zGLpmI-lxqBIfSbvW1ukMDh9VW7fIRq9l3yFba91TAT9oBv7QQVcEAU7jHNzKX3qU7JvCfr7d2UUXFVkOxYZFz1HuPHB5C9QuYn5TtFUb2ozw";
$user = Socialite::with('apple')->userFromToken($token));

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

// to use stateless
return Socialite::with('apple')->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);
return Socialite::with('apple')->setConfig($config)->redirect();

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

php artisan socialite:apple

php artisan socialite:apple --refresh