redsnapper/socialite-swissrx

A Laravel Socialite provider for Swiss Rx, an authentication system for Swiss healthcare professionals.

Maintainers

Package info

github.com/RedSnapper/socialite-swiss-rx

pkg:composer/redsnapper/socialite-swissrx

Statistics

Installs: 5 124

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

V2.0.0 2026-02-19 15:42 UTC

This package is auto-updated.

Last update: 2026-02-19 15:45:52 UTC


README

#Sociaite/Swiss-Rx

A Laravel Socialite driver for Swiss RX, an authentication system for Swiss healthcare professionals

Latest Version on Packagist GitHub Tests Action Status Total Downloads

This repo can be used to provide OAuth authentication with [Swiss Rx] (https://swiss-rx-login.ch/).

Installation

You can install the package via composer:

composer require redsnapper/socialite-swissrx

Add event listener mapping in your EventServiceProvider.php

//Providers\EventServiceProvider.php

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

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

Then go to your services.php and add swissrx credentials. When using your callback, make sure it's registered with swiss-rx first.

//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
],

And finally add your Swiss-Rx key and secret to the .env file:

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

Usage

Register your routes

//web.php

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

Then in your controller call the redirectToProvider() and handleProviderCallback():

//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;
}

Scopes

By default the anonymous scope is used, which will not return any user data other than their ID. To retrieve user data use the socialite method setScopes() to request the personal scope:

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

Secret key requirements

As of v2.0, firebase/php-jwt has been upgraded to v7 to address CVE-2025-45769 (weak encryption). This version enforces a minimum key length of 32 bytes for HS256 signatures.

Older 9-character secrets previously provided by Swiss RX are no longer supported. If you are still using a short secret, you will need to request a new one from Swiss RX.

Testing

vendor/bin/phpunit

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.