PHP code example of socialiteproviders / cognito
1. Go to this page and download the library: Download socialiteproviders/cognito 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/ */
socialiteproviders / cognito example snippets
'cognito' => [
'host' => env('COGNITO_HOST'),
'client_id' => env('COGNITO_CLIENT_ID'),
'client_secret' => env('COGNITO_CLIENT_SECRET'),
'redirect' => env('COGNITO_CALLBACK_URL'),
'scope' => explode(",", env('COGNITO_LOGIN_SCOPE')),
'logout_uri' => env('COGNITO_SIGN_OUT_URL')
],
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
$event->extendSocialite('cognito', \SocialiteProviders\Cognito\Provider::class);
});
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// ... other providers
\SocialiteProviders\Cognito\CognitoExtendSocialite::class.'@handle',
],
];
return Socialite::driver('cognito')->redirect();
public function cognitoLogout() {
Auth::logout(); // Log out app
return redirect(Socialite::driver('cognito')->logoutCognitoUser()); // Call cognito logout url
}
public function cognitoSwitchAccount() {
Auth::logout(); // Log out app
$scopes = explode(",", env('COGNITO_LOGIN_SCOPE')); // Override default scopes if needed
return redirect(Socialite::driver('cognito')->scopes($scopes)->switchCognitoUser()); // Call cognito logout url
}
COGNITO_HOST=https://your-app.auth.ap-southeast-2.amazoncognito.com
COGNITO_CLIENT_ID=abc123
COGNITO_CLIENT_SECRET=abc123
COGNITO_CALLBACK_URL=https://your-app.ngrok.io/oauth2/callback
COGNITO_SIGN_OUT_URL=https://example.com
COGNITO_LOGIN_SCOPE="openid,profile"