Skip to content

Commit

Permalink
Add initial project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmaguire committed Dec 8, 2015
0 parents commit 0b187ab
Show file tree
Hide file tree
Showing 13 changed files with 650 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
/build
/example
/vendor
composer.phar
composer.lock
.DS_Store
35 changes: 35 additions & 0 deletions .scrutinizer.yml
@@ -0,0 +1,35 @@
filter:
excluded_paths: [test/*]
checks:
php:
code_rating: true
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true
tools:
external_code_coverage:
timeout: 600
runs: 2
php_analyzer: true
php_code_coverage: false
php_code_sniffer:
config:
standard: PSR2
filter:
paths: ['src']
php_loc:
enabled: true
excluded_dirs: [vendor, test]
php_cpd:
enabled: true
excluded_dirs: [vendor, test]
21 changes: 21 additions & 0 deletions .travis.yml
@@ -0,0 +1,21 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- hhvm

before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-source --dev
- travis_retry phpenv rehash

script:
- ./vendor/bin/phpcs --standard=psr2 src/
- ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi

19 changes: 19 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,19 @@
# Changelog
All Notable changes to `oauth1-bitbucket` will be documented in this file

## 0.1.0 - 2015-12-10

### Added
- Initial release!

### Deprecated
- Nothing

### Fixed
- Nothing

### Removed
- Nothing

### Security
- Nothing
42 changes: 42 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,42 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

We accept contributions via Pull Requests on [Github](https://github.com/thephpleague/oauth1-bitbucket).


## Pull Requests

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the README and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow SemVer. Randomly breaking public APIs is not an option.

- **Create topic branches** - Don't ask us to pull from your master branch.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.

- **Ensure tests pass!** - Please run the tests (see below) before submitting your pull request, and make sure they pass. We won't accept a patch until all tests pass.

- **Ensure no coding standards violations** - Please run PHP Code Sniffer using the PSR-2 standard (see below) before submitting your pull request. A violation will cause the build to fail, so please make sure there are no violations. We can't accept a patch if the build fails.


## Running Tests

``` bash
$ ./vendor/bin/phpunit
```


## Running PHP Code Sniffer

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

**Happy coding**!
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Steven Maguire

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
122 changes: 122 additions & 0 deletions README.md
@@ -0,0 +1,122 @@
# Bitbucket Provider for OAuth 1.0 Client
[![Latest Version](https://img.shields.io/github/release/thephpleague/oauth1-bitbucket.svg?style=flat-square)](https://github.com/thephpleague/oauth1-bitbucket/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/thephpleague/oauth1-bitbucket/master.svg?style=flat-square)](https://travis-ci.org/thephpleague/oauth1-bitbucket)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/thephpleague/oauth1-bitbucket.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/oauth1-bitbucket/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/thephpleague/oauth1-bitbucket.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/oauth1-bitbucket)
[![Total Downloads](https://img.shields.io/packagist/dt/league/oauth1-bitbucket.svg?style=flat-square)](https://packagist.org/packages/league/oauth1-bitbucket)

This package provides Bitbucket OAuth 1.0 support for the PHP League's [OAuth 1.0 Client](https://github.com/thephpleague/oauth1-client).

## Installation

To install, use composer:

```
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.

### Authenticating with OAuth 1.0

```php
// 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
```
``` bash
$ ./vendor/bin/phpcs src --standard=psr2 -sp
```

## Contributing

Please see [CONTRIBUTING](https://github.com/thephpleague/oauth1-bitbucket/blob/master/CONTRIBUTING.md) for details.


## Credits

- [Steven Maguire](https://github.com/stevenmaguire)
- [All Contributors](https://github.com/thephpleague/oauth1-bitbucket/contributors)


## License

The MIT License (MIT). Please see [License File](https://github.com/thephpleague/oauth1-bitbucket/blob/master/LICENSE) for more information.
44 changes: 44 additions & 0 deletions composer.json
@@ -0,0 +1,44 @@
{
"name": "league/oauth1-bitbucket",
"description": "Bitbucket OAuth 1.0 Client Provider for The PHP League OAuth1-Client",
"license": "MIT",
"authors": [
{
"name": "Steven Maguire",
"email": "stevenmaguire@gmail.com",
"homepage": "https://github.com/stevenmaguire"
}
],
"keywords": [
"oauth",
"oauth1",
"client",
"authorization",
"authorisation",
"bitbucket"
],
"require": {
"php": ">=5.5.0",
"league/oauth1-client": "dev-develop"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"mockery/mockery": "~0.9",
"squizlabs/php_codesniffer": "~2.0"
},
"autoload": {
"psr-4": {
"League\\OAuth1\\Client\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"League\\OAuth1\\Client\\Test\\": "test/src/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
38 changes: 38 additions & 0 deletions phpunit.xml
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<logging>
<log type="coverage-html"
target="./build/coverage/html"
charset="UTF-8"
highlight="false"
lowUpperBound="35"
highLowerBound="70"/>
<log type="coverage-clover"
target="./build/coverage/log/coverage.xml"/>
</logging>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./test/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./</directory>
<exclude>
<directory suffix=".php">./example</directory>
<directory suffix=".php">./vendor</directory>
<directory suffix=".php">./test</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

0 comments on commit 0b187ab

Please sign in to comment.