定制 ray/oauth-module 二次开发

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

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

ray/oauth-module

最新稳定版本:2.2.0

Composer 安装命令:

composer require ray/oauth-module

包简介

OAuth module for Ray.Di

README 文档

README

Build Status

OAuth Module for Ray.Di

Installation

Composer install

$ composer require ray/oauth-module

Module install

use Ray\Di\AbstractModule;
use Ray\OAuthModule\OAuth1Module;
use Ray\OAuthModule\OAuth1Service;

class AppModule extends AbstractModule
{
	protected function configure()
	{
		$this->install(new OAuth1Module(OAuth1Service::TWITTER, $_ENV['CONSUMER_KEY'], $_ENV['CONSUMER_SECRET'], '/oauth/callback'));
	}
}

Usage

Redirects to the authorization page.

use Ray\OAuthModule\Inject\TwitterOAuthInject;

class OAuthController
{
    use TwitterOAuthInject;

    public function redirectAction()
    {
        $this->twitterOAuth->authorize();
    }
}

Requests the AccessToken. This is callback process after authorization finished.

use Ray\OAuthModule\Inject\TwitterOAuthInject;

class OAuthController
{
    use TwitterOAuthInject;

    public function callbackAction()
    {
        if ($_GET['denied']) {
            // should be handled as error
            return 'ERROR';
        }

        // requests AccessToken
        $token = $this->twitterOAuth->requestAccessToken($_GET['oauth_token'], $_GET['oauth_verifier']);
        /** @var OAuth\OAuth1\Token\TokenInterface $token */

        // $accessToken       = $token->getAccessToken();
        // $accessTokenSecret = $token->getAccessTokenSecret();
        $userId     = $token->getExtraParams()['user_id'];
        $screenName = $token->getExtraParams()['screen_name'];

        // gets authorized user info
        $user = $this->twitterOAuth->api('get', 'users/show.json', ['user_id' => $userId]);
        $user = json_decode($user);

        $result = 'user_id : ' . $userId .'<br />';
        $result.= 'screen_name : @' . $screenName . '<br />';
        $result.= 'name: ' . $user->name;

        return $result;
    }
}

Demo

OAuth1 (Twitter)

See docs/demo/www/oauth1_twitter.php for detail.

# 1. Create and configure the Twitter App on Developer Website

# 2. Set Consumer Key and Secret in docs/demo/www/oauth1_twitter.php

# 3. Start the PHP built-in Web-Server
$ php -S localhost:8080 -t docs/demo/www

# 4. Access http://localhost:8080/oauth1_twitter.php
<< output >>
user_id: {Your User ID}
screen_name: @{your_screen_name}
name: {Your Name}

OAuth2 (Facebook)

See docs/demo/www/oauth2_facebook.php for detail.

# 1. Create and configure the Facebook App on Developer Website

# 2. Set App ID and Secret in docs/demo/www/oauth2_facebook.php

# 3. Start the PHP built-in Web-Server
$ php -S localhost:8080 -t docs/demo/www

# 4. Access http://localhost:8080/oauth2_facebook.php
<< output >>
id: {Your ID}
name: {Your Name}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-05