devshaded/sparebank1-socialite-provider 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

devshaded/sparebank1-socialite-provider

最新稳定版本:0.0.1

Composer 安装命令:

composer require devshaded/sparebank1-socialite-provider

包简介

README 文档

README

This is a custom provider for OAuth login with SpareBank1

Installation

To install the package via composer, run the following command:

composer require devshaded/sparebank1-socialite-provider

Configuration

Once the package is installed, register the provider in config/services.php as follows:

'sb1' => [
    'client_id' => env('SB1_CLIENT_ID'),
    'client_secret' => env('SB1_CLIENT_SECRET'),
    'finInstId' => env('SB1_FIN_INST_ID'),
    'redirect' => env('SB1_REDIRECT_URI'),
],

Usage

To initiate the OAuth login with SpareBank1, you can use the following code to redirect users to the authentication page:

return Socialite::driver('sp1')->redirect();

To handle the callback after the user has authenticated:

$user = Socialite::driver('sp1')->user();

Environment Variables

Ensure you have added the following variables to your .env file:

SB1_CLIENT_ID=your-client-id
SB1_CLIENT_SECRET=your-client-secret
SB1_REDIRECT_URI=your-redirect-url
SB1_FIN_INST_ID=fid-ringerike-hadeland

Replace your-client-id, your-client-secret, and your-redirect-url with the appropriate values from your SpareBank1 OAuth credentials.

Example

Route::get('/oauth/redirect', function () {
    return Socialite::driver('sb1')->redirect();
});

Route::get('/oauth/callback', function () {
    $user = Socialite::driver('sb1')->user();

    $existingUser = User::where('email', $user->getEmail())->first();

    if ($existingUser) {
        $existingUser->update([
            'firstname' => $user->user['firstname'],
            'lastname' => $user->user['lastname'],
            'email' => $user->getEmail(),
            'sub' => $user->user['sub'],
            'dob' => $user->user['dateOfbirth'],
            'phone' => $user->user['mobilePhoneNumber'],
        ]);

        $existingUser->accessToken()->update([
            'token' => $user->token,
            'refresh_token' => $user->refreshToken,
            'expires_in' => $user->expiresIn,
        ]);
    } else {
        $newUser = User::create([
            'firstname' => $user->user['firstname'],
            'lastname' => $user->user['lastname'],
            'email' => $user->getEmail(),
            'sub' => $user->user['sub'],
            'dob' => $user->user['dateOfbirth'],
            'phone' => $user->user['mobilePhoneNumber'],
        ]);

        $newUser->accessToken()->create([
            'token' => $user->token,
            'refresh_token' => $user->refreshToken,
            'expires_in' => $user->expiresIn,
        ]);
    }
});

License

This package is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-12