定制 kolovious/melisocialite 二次开发

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

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

kolovious/melisocialite

Composer 安装命令:

composer require kolovious/melisocialite

包简介

Mercadolibre Laravel Socialite Integration

README 文档

README

Laravel Socialite provider for Mercadolibre OAuth authentication.

Supports Laravel 9.x, 10.x, 11.x, and 12.x

License

Mercadolibre Laravel Socialite is open-sourced software licensed under the MIT license

Installation

composer require kolovious/meli-socialite

Configuration

Laravel 11.x & 12.x (Auto-Discovery)

For Laravel 11 and 12, the service provider and facade are automatically discovered. You can skip the manual registration steps below.

Laravel 9.x & 10.x (Manual Registration)

After installing the Socialite library, register the Kolovious\MeliSocialite\MeliSocialiteServiceProvider in your config/app.php configuration file after the Socialite Service Provider:

'providers' => [

    // Other service providers...
    Laravel\Socialite\SocialiteServiceProvider::class,
    
    Kolovious\MeliSocialite\MeliSocialiteServiceProvider::class,
    
],

Also the Meli Facade is available for actions with the API

'alias' => [
    // Other alias...
    
    'Meli' => Kolovious\MeliSocialite\Facade\Meli::class,
    
],

You will also need to add credentials for the OAuth services your application utilizes. These credentials should be placed in your config/services.php configuration file:

'meli' => [
    'client_id' => 'your-meli-app-id',
    'client_secret' => 'your-meli-secret-code',
    'redirect' => 'http://your-callback-url',
],

Basic Usage

Next, 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;

use Socialite;

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

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

        // $user->token;
    }
}

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.

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

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

Retrieving User Details

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

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

// Tokens & Expire time
$token         = $user->token;
$refresh_token = $user->refresh_token;
$expires_at    = $user->expires_at; // UNIX TIMESTAMP

// Methods from Socialite User 
$user->getId();
$user->getNickname();
$user->getName();
$user->getEmail();

// Raw Data
$user->user // Provided by Meli

Using the Facade to make API calls.

// Items from User ( ALL ) 
$offset = 0;
$call= "/users/".$user_id."/items/search";
$result = Meli::get($call, ["offset"=>$offset, 'access_token'=>$access_token]);

// Update Item Description
// Will use the saved access_token in the MeliManager object.
$result = Meli::withToken()->put('/items/'.$item_id.'/description', [ 'text' => $this->description ]); 

or

// Will save this token for future uses. Same as above.
$result = Meli::withToken($token)->put('/items/'.$item_id.'/description', [ 'text' => $this->description ]);

or

// Will use the Access Token in the Auth user, and save it for future uses. You can call withToken() the next time and it will work as espected
$result = Meli::withAuthToken()->put('/items/'.$item_id.'/description', [ 'text' => $this->description ]);

kolovious/melisocialite 适用场景与选型建议

kolovious/melisocialite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.16k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「MercadoLibre」 「socialite」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 kolovious/melisocialite 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-08