Skip to content

Commit

Permalink
deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPropre committed Mar 26, 2021
1 parent c87740e commit 9c16db0
Show file tree
Hide file tree
Showing 12 changed files with 3,360 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ composer.phar
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock

.phpunit.result.cache
35 changes: 35 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -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: 3
php_analyzer: true
php_code_coverage: false
php_code_sniffer:
config:
standard: PSR12
filter:
paths: ['src']
php_loc:
enabled: true
excluded_dirs: [vendor, test]
php_cpd:
enabled: true
excluded_dirs: [vendor, test]
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: php

php:
- 7.3
- 7.4
- 8.0

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

script:
- ./vendor/bin/phpcs --extensions=php --standard=psr12 -sp src
- ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

after_success:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
42 changes: 42 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Contributing

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

We accept contributions via Pull Requests on [Github](https://github.com/MrPropre/oauth2-epicgames).


## Pull Requests

- **[PSR-12 Extended Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-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-12 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 --extensions=php --standard=psr12 -sp src
```

**Happy coding**!
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 MrPropre
Copyright (c) 2021 Adrien Alais

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
138 changes: 136 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,136 @@
# oauth2-epicgames
Epic Games Provider for the OAuth 2.0 Client
# Epic Games Provider for OAuth 2.0 Client
[![Latest Version](https://img.shields.io/github/release/MrPropre/oauth2-epicgames.svg?style=flat-square)](https://github.com/MrPropre/oauth2-epicgames/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/MrPropre/oauth2-epicgames/master.svg?style=flat-square)](https://travis-ci.org/MrPropre/oauth2-epicgames)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/MrPropre/oauth2-epicgames.svg?style=flat-square)](https://scrutinizer-ci.com/g/MrPropre/oauth2-epicgames/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/MrPropre/oauth2-epicgames.svg?style=flat-square)](https://scrutinizer-ci.com/g/MrPropre/oauth2-epicgames)
[![Total Downloads](https://img.shields.io/packagist/dt/mrpropre/oauth2-epicgames.svg?style=flat-square)](https://packagist.org/packages/mrpropre/oauth2-epicgames)

This package provides Epic Games OAuth 2.0 support for the PHP League's [OAuth 2.0 Client](https://github.com/thephpleague/oauth2-client).

This package is compliant with [PSR-4][], [PSR-7][], and [PSR-12][]. If you notice compliance oversights,
please send a patch via pull request.

[PSR-4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md
[PSR-7]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md
[PSR-12]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md

## Installation

To install, use composer:

```
composer require mrpropre/oauth2-epicgames
```

## Requirements

The following versions of PHP are supported.

* PHP 7.3
* PHP 7.4
* PHP 8.0

## Usage

Usage is the same as The League's OAuth client, using `\MrPropre\OAuth2\Client\Provider\EpicGames` as the provider.

### Authorization Code Flow

```php
require __DIR__ . '/vendor/autoload.php';

use MrPropre\OAuth2\Client\Provider\EpicGames;
use League\OAuth2\Client\OptionProvider\HttpBasicAuthOptionProvider;

session_start(); // Remove if session.auto_start=1 in php.ini

$provider = new EpicGames([
'clientId' => '{epicgames-client-id}',
'clientSecret' => '{epicgames-client-secret}',
'redirectUri' => 'https://example.com/callback-url',
], [
'optionProvider' => new HttpBasicAuthOptionProvider()
]);

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;

// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {

unset($_SESSION['oauth2state']);
exit('Invalid state');

} else {

// Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);

// Optional: Now you have a token you can look up a users profile data
try {

// We got an access token, let's now get the user's details
$user = $provider->getResourceOwner($token);

// Use these details to create a new profile
printf('Hello %s!', $user->getUsername());

} catch (\Exception $e) {

// Failed to get user details
exit('Something went wrong: ' . $e->getMessage());
}

// Use this to interact with an API on the users behalf
echo $token->getToken();
}
```

### Managing Scopes

When creating your Epic Games authorization URL, you can specify the state and scopes your application may authorize.

```php
$options = [
'state' => 'OPTIONAL_CUSTOM_CONFIGURED_STATE',
'scope' => ['basic_profile','friends_list','presence'] // array or string
];

$authorizationUrl = $provider->getAuthorizationUrl($options);
```
If neither are defined, the provider will utilize internal defaults.

At the time of authoring this documentation, the [following scopes are available](https://dev.epicgames.com/docs/services/en-US/EpicAccountServices/GettingStarted/index.html#applicationpermissions).

- basic_profile
- presence
- friends_list

## Testing

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

## Contributing

Please see [CONTRIBUTING](https://github.com/MrPropre/oauth2-epicgames/blob/master/CONTRIBUTING.md) for details.


## Credits

- [Adrien Alais](https://github.com/MrPropre)
- [All Contributors](https://github.com/MrPropre/oauth2-epicgames/contributors)


## License

The MIT License (MIT). Please see [License File](https://github.com/MrPropre/oauth2-epicgames/blob/master/LICENSE) for more information.
48 changes: 48 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "mrpropre/oauth2-epicgames",
"description": "Epic Games OAuth 2.0 Client Provider for The PHP League OAuth2-Client",
"type": "library",
"require": {
"league/oauth2-client": "^2.6"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.5",
"phpunit/phpunit": "^9.5",
"mockery/mockery": "^1.4"
},
"license": "MIT",
"authors": [
{
"name": "Adrien Alais",
"email": "[email protected]"
}
],
"keywords": [
"oauth",
"oauth2",
"client",
"authorization",
"authorisation",
"epicgames",
"epic games",
"fortnite"
],
"autoload": {
"psr-4": {
"MrPropre\\OAuth2\\Client\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"MrPropre\\OAuth2\\Client\\Test\\": "test/src/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"config": {
"sort-packages": true
}
}
Loading

0 comments on commit 9c16db0

Please sign in to comment.