2017 © Pedro Peláez
 

library oauth2-unsplash

Unsplash OAuth 2.0 Client Provider for The PHP League OAuth2-Client

image

hughbertd/oauth2-unsplash

Unsplash OAuth 2.0 Client Provider for The PHP League OAuth2-Client

  • Thursday, December 14, 2017
  • by HughbertD
  • Repository
  • 0 Watchers
  • 2 Stars
  • 14,037 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 5 Versions
  • 23 % Grown

The README.md

Unsplash Provider for OAuth 2.0 Client

Build Status, (*1)

Provides Unsplash OAuth 2.0 support as an implementation of PHP League's OAuth 2.0 Client, (*2)

Installation

To install, use composer:, (*3)

composer require hughbertd/oauth2-unsplash

Usage

Usage is the same as The League's OAuth client, using \CrewLabs\OAuth2\Client\Provider\Unsplash as the provider., (*4)

Authorization Code Flow

<?php
require_once('./vendor/autoload.php');
session_start();

$provider = new \Unsplash\OAuth2\Client\Provider\Unsplash([
    'clientId' => '{clientId}',
    'clientSecret' => '{clientSecret}',
    'redirectUri' => 'http://example.com',
]);

if (!isset($_GET['code'])) {
    // If we don't have an authorization code then get one
    $authUrl = $provider->getAuthorizationUrl();
    $_SESSION['oauth2state'] = $provider->getState();
    header('Location: ' . $authUrl);
    exit;
}

if (isset($_GET['code']) && !isset($_SESSION['token'])) {
    try {
        // Try to get an access token (using the authorization code grant)
        $token = $provider->getAccessToken('authorization_code', [
            'code' => $_GET['code']
        ]);

    } catch (Exception $e) {
        print($e->getMessage());
        exit;
    }

    // Use this to interact with an API on the users behalf
    $_SESSION['token'] = $token->getToken();
}

if (isset($_SESSION['token'])) {
    $user = $provider->getResourceOwner($_SESSION['token']);
    printf('Hello %s!', $user->getName());
    return;
}

Testing

bash $ ./vendor/bin/phpunit, (*5)

Credits

The Versions

14/12 2017

dev-master

9999999-dev

Unsplash OAuth 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hugh Downer

authentication authorization oauth sso oauth2 identity idp single sign on unsplash

14/12 2017

1.0.3

1.0.3.0

Unsplash OAuth 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hugh Downer

authentication authorization oauth sso oauth2 identity idp single sign on unsplash

05/04 2017

1.0.2

1.0.2.0

Unsplash OAuth 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hugh Downer

authentication authorization oauth sso oauth2 identity idp single sign on unsplash

05/04 2017

1.0.1

1.0.1.0

Unsplash OAuth 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hugh Downer

authentication authorization oauth sso oauth2 identity idp single sign on unsplash

05/04 2017

1.0

1.0.0.0

Unsplash OAuth 2.0 Client Provider for The PHP League OAuth2-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

by Hugh Downer

authentication authorization oauth sso oauth2 identity idp single sign on unsplash