定制 happyonlinegr/socialite-provider-vipps 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

happyonlinegr/socialite-provider-vipps

Composer 安装命令:

composer require happyonlinegr/socialite-provider-vipps

包简介

Vipps Provider for Laravel Socialite

README 文档

README

Installation

composer require happyonlinegr/socialite-provider-vipps

Service Provider

Add to app.php:

'providers' => [
    Laravel\Socialite\SocialiteServiceProvider::class,
    \SocialiteProviders\Manager\ServiceProvider::class,
];

Event Listener

  • Add SocialiteProviders\Manager\SocialiteWasCalled event to your listen[] array in app/Providers/EventServiceProvider.

Example:

/**
 * The event handler mappings for the application.
 *
 * @var array
 */
protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        '\SocialiteProviders\Vipps\VippsExtendSocialite@handle',
    ],
];

Configuration setup

You will need to add an entry to the services configuration file so that after config files are cached for usage in production environment (Laravel command artisan config:cache) all config is still available.

Add to config/services.php.

'vipps' => [
    'client_id' => env('VIPPS_CLIENT_ID'),
    'client_secret' => env('VIPPS_CLIENT_SECRET'),
    'redirect' => env('VIPPS_REDIRECT_URI'),
],

Remember to whitelist the redirect_uri in the Vipps portal.

5. 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')->stateless()->user();

Example for a VippsAuthController:

<?php
 
 namespace App\Http\Controllers\Api;
 
 use App\Http\Controllers\Controller;
 use Illuminate\Http\Request;
 use Laravel\Socialite\Facades\Socialite;
 
 class VippsAuthController extends Controller
 {
     public function index(Request $request)
     {
         return Socialite::driver('vipps')->redirect();
     }
 
     public function handleCallback()
     {
         $user = Socialite::driver('vipps')->stateless()->user();
 
         if (!$user) {
             //Return error message
         }

         //Do stuff
     }
}

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-10-19