sempro / socialite-provider-vipps
Vipps OAuth2 Provider for Laravel Socialite
Requires
- php: ^8.0
- ext-json: *
- socialiteproviders/manager: ^4.4
This package is auto-updated.
Last update: 2025-04-02 11:37:38 UTC
README
Custom provider for using Vipps with Laravel Socialite. This package requires laravel socialite in your project.
1. Installation
composer require indentno/socialite-provider-vipps
2. Event Listener
Laravel 11+
In Laravel 11, the default EventServiceProvider
provider was removed. Instead, add the listener using the listen
method on the Event
facade, in your AppServiceProvider
boot
method.
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) { $event->extendSocialite('vipps', \Indent\SocialiteProviderVipps\Provider::class); });
Laravel 10 or below
Configure the package's listener to listen for `SocialiteWasCalled` events.Add the event to your listen[]
array in app/Providers/EventServiceProvider
. See the Base Installation Guide for detailed instructions.
protected $listen = [ \SocialiteProviders\Manager\SocialiteWasCalled::class => [ // ... other providers \Indent\SocialiteProviderVipps\VippsExtendSocialite::class . '@handle', ], ];
3. Add configuration to config/services.php
'vipps' => [ 'client_id' => env('VIPPS_CLIENT_ID'), 'client_secret' => env('VIPPS_CLIENT_SECRET'), 'redirect' => env('VIPPS_REDIRECT_URI'), // Optional. Can be provided for interacting with vipps test api. 'base_url' => 'apitest.vipps.no', // Optional. Can be added in order to request more data. // (See link for list of scopes: https://api.vipps.no/access-management-1.0/access/.well-known/openid-configuration) 'scopes' => [ 'name', 'email', ], ],
Remember to whitelist the redirect_uri in the Vipps portal.
4. Usage
To initiate the Vipps login, add this to your controller
return Socialite::driver('vipps')->redirect();
You've now gotten a user token from Vipps in your callback function. Now we need to use the user token to get the phone number of the authenticated user.
$user = Socialite::driver('vipps')->user();
Example for a VippsAuthController:
<?php namespace App\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Http\RedirectResponse; use Laravel\Socialite\Facades\Socialite; class VippsAuthController extends Controller { public function redirect(): RedirectResponse { return Socialite::driver('vipps')->redirect(); } public function callback() { $user = Socialite::driver('vipps')->user(); if (!$user) { // Return error message } // Verify user exists, authenticate and redirect } }
Vipps guidelines
When using Vipps login you need to use the login button svgs provided by Vipps. Go to Vipps brand guidelines for more info.
License
MIT © Indent AS