2017 © Pedro Peláez
 

library oauth1-bitbucket

Bitbucket OAuth 1.0 Client Provider for The PHP League OAuth1-Client

image

league/oauth1-bitbucket

Bitbucket OAuth 1.0 Client Provider for The PHP League OAuth1-Client

  • Tuesday, December 8, 2015
  • by stevenmaguire
  • Repository
  • 5 Watchers
  • 2 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Bitbucket Provider for OAuth 1.0 Client

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads, (*1)

This package provides Bitbucket OAuth 1.0 support for the PHP League's OAuth 1.0 Client., (*2)

Installation

To install, use composer:, (*3)

composer require league/oauth1-bitbucket

Usage

Usage is the same as The League's OAuth client, using \League\OAuth1\Client\Server\Bitbucket as the server., (*4)

Authenticating with OAuth 1.0

// Create a server instance.
$server = new \League\OAuth1\Client\Server\Bitbucket([
    'identifier'              => 'your-identifier',
    'secret'                  => 'your-secret',
    'callbackUri'             => 'http://your-callback-uri/',
]);

// Obtain Temporary Credentials and User Authorization
if (!isset($_GET['oauth_token'], $_GET['oauth_verifier'])) {

    // First part of OAuth 1.0 authentication is to
    // obtain Temporary Credentials.
    $temporaryCredentials = $server->getTemporaryCredentials();

    // Store credentials in the session, we'll need them later
    $_SESSION['temporary_credentials'] = serialize($temporaryCredentials);
    session_write_close();

    // Second part of OAuth 1.0 authentication is to obtain User Authorization
    // by redirecting the resource owner to the login screen on the server.
    // Create an authorization url.
    $authorizationUrl = $server->getAuthorizationUrl($temporaryCredentials);

    // Redirect the user to the authorization URL. The user will be redirected
    // to the familiar login screen on the server, where they will login to
    // their account and authorize your app to access their data.
    header('Location: ' . $authorizationUrl);
    exit;

// Obtain Token Credentials
} else {

    try {

        // Retrieve the temporary credentials we saved before.
        $temporaryCredentials = unserialize($_SESSION['temporary_credentials']);

        // We will now obtain Token Credentials from the server.
        $tokenCredentials = $server->getTokenCredentials(
            $temporaryCredentials,
            $_GET['oauth_token'],
            $_GET['oauth_verifier']
        );

        // We have token credentials, which we may use in authenticated
        // requests against the service provider's API.
        echo $tokenCredentials->getIdentifier() . "\n";
        echo $tokenCredentials->getSecret() . "\n";

        // Using the access token, we may look up details about the
        // resource owner.
        $resourceOwner = $server->getResourceOwner($tokenCredentials);

        var_export($resourceOwner->toArray());

        // The server provides a way to get an authenticated API request for
        // the service, using the access token; it returns an object conforming
        // to Psr\Http\Message\RequestInterface.
        $request = $server->getAuthenticatedRequest(
            'GET',
            'http://your.service/endpoint',
            $tokenCredentials
        );

    } catch (\League\OAuth1\Client\Exceptions\Exception $e) {

        // Failed to get the token credentials or user details.
        exit($e->getMessage());

    }

}

Testing

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

``` bash
$ ./vendor/bin/phpcs src --standard=psr2 -sp

Contributing

Please see CONTRIBUTING for details., (*6)

Credits

License

The MIT License (MIT). Please see License File for more information., (*7)

The Versions

08/12 2015

dev-master

9999999-dev

Bitbucket OAuth 1.0 Client Provider for The PHP League OAuth1-Client

  Sources   Download

MIT

The Requires

 

The Development Requires

authorization oauth client oauth1 authorisation bitbucket