2017 © Pedro Peláez
 

library oauth-module

OAuth module for Ray.Di

image

ray/oauth-module

OAuth module for Ray.Di

  • Sunday, November 19, 2017
  • by kawanamiyuu
  • Repository
  • 5 Watchers
  • 3 Stars
  • 1,288 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 1 % Grown

The README.md

Ray.OAuthModule

Build Status, (*1)

OAuth Module for Ray.Di, (*2)

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., (*3)

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., (*4)

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., (*5)

# 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., (*6)

# 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}

The Versions

19/11 2017

dev-master

9999999-dev

OAuth module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth ray.di

19/11 2017

2.2.0

2.2.0.0

OAuth module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth ray.di

16/06 2016

2.1.0

2.1.0.0

OAuth module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth ray.di

11/03 2015

2.0.0

2.0.0.0

OAuth module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth ray.di

24/02 2015

1.1.1

1.1.1.0

OAuth module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth ray.di

07/01 2015

1.1.0

1.1.0.0

OAuth module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth ray.di

27/12 2014

1.0.0

1.0.0.0

OAuth module for Ray.Di

  Sources   Download

MIT

The Requires

 

The Development Requires

oauth ray.di