定制 jkbennemann/laravel-4-social-oauth 二次开发

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

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

jkbennemann/laravel-4-social-oauth

Composer 安装命令:

composer require jkbennemann/laravel-4-social-oauth

包简介

OAuth Service Provider for Laravel 4

README 文档

README

oauth-laravel-4 is a simple laravel 4 service provider for socialconnect/auth which provides OAuth support for PHP 5.3+ and is very easy to integrate with any project which requires an OAuth client.

Supported services

The library supports OAuth 1.x and OAuth 2.0 compliant services. A list of currently implemented services can be found on their site. Some examples are listed below:

Included service implementations:

  • Steam OpenID
  • Atlassian OAuth1
  • 500px OAuth1
  • Trello OAuth1
  • Tumblr OAuth1
  • Twitter OAuth1
  • Amazon OAuth2
  • Facebook OAuth2 3.3
  • Vk (ВКонтакте) OAuth2 5.100
  • Instagram OAuth2
  • Google OAuth2
  • GitHub OAuth2
  • GitLab OAuth2
  • Slack OAuth2
  • BitBucket OAuth2
  • Twitch OAuth2
  • Vimeo OAuth2
  • DigitalOcean OAuth2
  • Yandex OAuth2
  • MailRu OAuth2
  • Microsoft (MSN) OAuth2
  • Meetup OAuth2
  • Odnoklassniki OAuth2
  • Discord OAuth2
  • SmashCast OAuth2
  • Steein OAuth2
  • LinkedIn OAuth2
  • Yahoo! OAuth2
  • Wordpress OAuth2
  • Google OpenIDConnect
  • PixelIn OpenIDConnect
  • more to come!

To learn more about SocialConnect/auth go here

Installation

Use composer to install this package.

$ composer require jkbennemann/oauth-laravel-4

Registering the Package

Register the service provider within the providers array found in app/config/app.php:

'providers' => array(
	// ...
	
	'Jkbennemann\OAuth\OAuthServiceProvider',
)

Add an alias within the aliases array found in app/config/app.php:

'aliases' => array(
	// ...
	
	'OAuth' => 'Jkbennemann\OAuth\Facade\OAuth',
)

Configuration

There are two ways to configure oauth-4-laravel. You can choose the most convenient way for you. You can use package config file which can be generated through command line by artisan (option 1) or you can simply create a config file called laravel-4-social-oauth.php in your app\config\ directory (option 2).

Option 1

Create configuration file for package using artisan command

$ php artisan config:publish jkbennemann/laravel-4-social-oauth

Option 2

Create configuration file manually in config directory app/config/laravel-4-social-oauth.php and put there code from below.

<?php 

return array( 
	
	/*
	|--------------------------------------------------------------------------
	| OAuth Config
	|--------------------------------------------------------------------------
    */

    /*
    |--------------------------------------------------------------------------
    | Note: ${provider} will be resolved automatically accordingly
    |--------------------------------------------------------------------------
    */
	'redirect_base_uri' => 'https://you-callback-url.local/login/${provider}',

	/*
    |--------------------------------------------------------------------------
	| Provider
    |--------------------------------------------------------------------------
	 */
	'provider' => array(

        /**
         * Amazon
         */
        'amazon' => array(
            'applicationId'     => '',
            'applicationSecret' => '',
            'scope'         => array()
        ),

        /**
         * Atlassian
         */
        'atlassian' => array(
            'applicationId'     => '',
            'applicationSecret' => ''
        ),

        /**
         * Bitbucket
         */
        'bitbucket' => array(
            'applicationId'     => '',
            'applicationSecret' => '',
            'scope'         => array(
                'account'
            )
        ),

        /**
         * GitHub
         */
        'github' => array(
            'applicationId'     => '',
            'applicationSecret' => '',
            'scope'         => array(
                'user',
                'email'
            ),
            'options'       => array(
                'fetch_emails'   => true
            )
        ),

    )
);

Credentials

Add your credentials to app/config/laravel-4-social-oauth.php

Usage

Basic usage

Just follow the steps below and you will be able to get a service class object with this one rule:

$service = OAuth::provider('github');

Optionally, add a second parameter with the URL which the service needs to redirect to, otherwise it will redirect to the current URL.

$service = OAuth::provider('Github','http://url.to.redirect.to');

Usage examples

Github:

Configuration: Add your Github credentials to the config file

In your Controller use the following code:

/**
 * Login user with github
 *
 * @return void
 */

public function loginWithGithub() {
	
	// get data from input
	$code = Input::get( 'code' );
	
	// get github service
	$service = OAuth::provider( 'github' );
	
	// check if code is valid
	
	// if code is provided get user data and sign in
	if ( !empty( $code ) ) {
		
        // This was a callback request from github, get the token
        $accessToken  = $service->getAccessTokenByRequestParameters(Input::all());

        // fetch information for authorized token
        $user = $service->getIdentity($accessToken);
        
        var_dump($user);

        //perform user lookup e.g. User::findByEmail($user->email);
        //login User
        //redirect the user to any page
        
        exit();	
	} else {
	    // if not ask for permission first
		// get service authorization
		$url = $service->makeAuthUrl();
		
		// return to auth page
		 return Redirect::to($url);
	}

}

jkbennemann/laravel-4-social-oauth 适用场景与选型建议

jkbennemann/laravel-4-social-oauth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 07 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 jkbennemann/laravel-4-social-oauth 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-26