承接 alexsoft/laravel-socialite-bitbucket 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

alexsoft/laravel-socialite-bitbucket

Composer 安装命令:

composer require alexsoft/laravel-socialite-bitbucket

包简介

Bitbucket OAuth2 Provider for Laravel Socialite

README 文档

README

Laravel Socialite itself supports Bitbucket oAuth 2. It is strongly recommended to use it. https://laravel.com/docs/socialite This is deprecated now.

Bitbucket OAuth2 Provider for Laravel Socialite

Packagist Software License StyleCI

This package allows you to use Laravel Socialite using OAuth 2 of Bitbucket.

Installation

You can install the package via composer:

Laravel 5.4+

composer require alexsoft/laravel-socialite-bitbucket

Laravel 5.0 - 5.3

You will need to use 1.0 version. Usage remains the same.

composer require alexsoft/laravel-socialite-bitbucket:^1.0

Note: if you use Laravel 5.5+ you can skip service provider registration, because it should be auto discovered.

Then you should register service provider in your config/app.php file:

'providers' => [
    // Other service providers
    
    Alexsoft\LaravelSocialiteBitbucket\Provider::class,

]

You will also need to add credentials for the OAuth application that you can get on the Oauth settings page of you Bitbucket account. They should be placed in your config/services.php file. You may copy the example configuration below to get started:

'bitbucket' => [
    'client_id' => env('BITBUCKET_CLIENT_ID'),
    'client_secret' => env('BITBUCKET_CLIENT_SECRET'),
    'redirect' => env('BITBUCKET_REDIRECT'),
],

Basic usage

So now, you are ready to authenticate users! You will need two routes: one for redirecting the user to the OAuth provider, and another for receiving the callback from the provider after authentication. We will access Socialite using the Socialite facade:

<?php

namespace App\Http\Controllers\Auth;

use Socialite;

class AuthController extends Controller
{
    /**
     * Redirect the user to the Bitbucket authentication page.
     *
     * @return Response
     */
    public function redirectToProvider()
    {
        return Socialite::driver('bitbucket2')->redirect();
    }

    /**
     * Obtain the user information from GitHub.
     *
     * @return Response
     */
    public function handleProviderCallback()
    {
        $user = Socialite::driver('bitbucket2')->user();

        // $user->token;
    }
}

Of course, you will need to define routes to your controller methods:

Route::get('auth/bitbucket', 'Auth\AuthController@redirectToProvider');
Route::get('auth/bitbucket/callback', 'Auth\AuthController@handleProviderCallback');

The redirect method takes care of sending the user to the OAuth provider, while the user method will read the incoming request and retrieve the user's information from the provider.

Bitbucket Oauth2 does not support scopes on request, all scopes are configured in Oauth application settings.

Retrieving user details

Once you have a user instance, you can grab a few more details about the user:

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

// OAuth Two Providers
$token = $user->token;
$refreshToken = $user->refreshToken; // may not always be provided
$expiresIn = $user->expiresIn;

// OAuth One Providers
$token = $user->token;
$tokenSecret = $user->tokenSecret;

// All Providers
$user->getId();
$user->getNickname();
$user->getName();
$user->getEmail();
$user->getAvatar();

Nota bene

Unlike Github Bitbucket provides you only one hour valid tokens so you will need to refresh access tokens.

Here is the piece of code that refreshes your token (requires Guzzle):

$options = [
    'auth' => [config('services.bitbucket.client_id'), config('services.bitbucket.client_secret')],
    'form_params' => [
        'grant_type' => 'refresh_token',
        'refresh_token' => "BITBUCKET_REFRESH_TOKEN"
    ]
];

$response = (new GuzzleHttp\Client)
    ->post('https://bitbucket.org/site/oauth2/access_token', $options)
    ->getBody()->getContents();

$response = json_decode($response, true);

$newAccessToken = $response['access_token'];

By some reason, after this operation refresh token is not updated, so you do not have to update it in your storage.

alexsoft/laravel-socialite-bitbucket 适用场景与选型建议

alexsoft/laravel-socialite-bitbucket 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 971 次下载、GitHub Stars 达 4, 最近一次更新时间为 2016 年 09 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 alexsoft/laravel-socialite-bitbucket 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 alexsoft/laravel-socialite-bitbucket 我们能提供哪些服务?
定制开发 / 二次开发

基于 alexsoft/laravel-socialite-bitbucket 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-15