PHP code example of redsnapper / socialite-swissrx

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

    

redsnapper / socialite-swissrx example snippets


//Providers\EventServiceProvider.php

use RedSnapper\SwissRx\SwissRxExtendSocialite;
use SocialiteProviders\Manager\SocialiteWasCalled;

protected $listen = [
        //...
        SocialiteWasCalled::class => [
            SwissRXExtendSocialite::class
        ],
    ];

//config\services.php

//...
'swissrx' => [
    'client_id' => env('SWISS_RX_KEY'),
    'client_secret' => env('SWISS_RX_SECRET'),
    'redirect' => config('app.url') . "/swiss-rx/callback",
    'token_leeway'  => env('SWISS_RX_TOKEN_LEEWAY'), // optional - you can use this if you are getting 'Cannot handle token prior to...' exceptions
],


SWISS_RX_KEY=<your-key>
SWISS_RX_SECRET=<your-secret>

//web.php

Route::get('/swiss-rx/login', [LoginController::class, 'redirectToProvider'])->name('login');
Route::get('/swiss-rx/callback', [LoginController::class, 'handleProviderCallback'])->name('login.callback');

//Http\Controllers\LoginController.php

use Laravel\Socialite\Facades\Socialite;


public function redirectToProvider()
{
    return Socialite::driver('swissrx')->with([
        'lang' => request()->get('lang', 'en')
    ])->redirect();
}

public function handleProviderCallback()
{
    $swissRxUser = Socialite::driver('swissrx')->user();

    retunr $swissRxUser;
}


public function redirectToProvider()
{
    return Socialite::driver('swissrx')->with([
        'lang' => request()->get('lang', 'en')
    ])
    ->setScopes(['personal'])
    ->redirect();
}