2017 © Pedro Peláez
 

library oauth-client

A simple OAuth client

image

devtronic/oauth-client

A simple OAuth client

  • Thursday, December 28, 2017
  • by Devtronic
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 25 % Grown

The README.md

OAuth Client

This is a simple client for OAuth Services (W.I.P.), (*1)

Currently included services: - Battle.net - Dropbox - Facebook - GitHub - Google - Instagram - PayPal - Shopify - Slack - Twitter, (*2)

More OAuth2 services coming soon, (*3)

Installation

$ composer require devtronic/oauth-client

Usage

OAuth 2.0, (*4)

<?php

$ro = new \Devtronic\OAuth\ResourceOwner\GoogleResourceOwner(
    $clientId = '<your-client-id>',
    $clientSecret = '<your-client-secret>',
    $redirectUrl = '<your-redirect-url>' # This script for example
);

# Prints all available scopes
# print_r($ro->getScopes());

$scopes = [
    'https://www.googleapis.com/auth/userinfo.profile'
];

if (!isset($_REQUEST['code'])) {
    header('location: ' . $ro->getAuthorizeUrl($scopes));
    exit;
} else {
    $token = $ro->getAccessToken($scopes, $_REQUEST['code']);

    $client = new \GuzzleHttp\Client(['verify' => false]);
    $res = $client->request('GET', 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json', [
        'headers' => [
            'Authorization' => sprintf('Bearer ' . $token->getToken()),
        ]
    ]);
    echo '<pre>';
    print_r(json_decode($res->getBody()->getContents(), true));
}

OAuth 1.0, (*5)

<?php

$ro = new \Devtronic\OAuth\ResourceOwner\TwitterResourceOwner(
    $consumerKey = '<your-consumer-key>',
    $consumerSecret = '<your-consumer-secret>',
    $redirectUrl = '<your-redirect-url>' # This script for example
);

if (!isset($_REQUEST['oauth_token'])) {
    header('location: ' . $ro->getAuthorizeUrl());
    exit;
} else {
    // Get the Token
    $token = $ro->getAccessToken($_REQUEST['oauth_token'], $_REQUEST['oauth_verifier']);

    // Start your own request
    $client = new \GuzzleHttp\Client(['verify' => false]);
    $url = 'https://api.twitter.com/1.1/account/verify_credentials.json';
    $res = $client->request('GET', $url, [
        'headers' => [
            // Sign the request and get the auth header
            'Authorization' => $ro->getAuthorizationHeader(
                'GET',   # Request Method 
                $url,    # Requested URL
                [],      # Request Parameters (GET, POST etc.)
                $token   # The previously received AccessToken
            ),
        ]
    ]);
    echo '<pre>';
    print_r(json_decode($res->getBody()->getContents(), true));
}

The Versions

28/12 2017

dev-master

9999999-dev

A simple OAuth client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julian Finkler

28/12 2017

v1.2.0

1.2.0.0

A simple OAuth client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julian Finkler

06/09 2017

v1.1.0

1.1.0.0

A simple OAuth client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julian Finkler

03/09 2017

v1.0.0

1.0.0.0

A simple OAuth client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Julian Finkler