diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8791d9f --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.yml] +indent_style = space +indent_size = 2 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..157ff0c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +vendor/ +composer.lock diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1c443f0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Socialite + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fe51dc0 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Instagram Provider + +## Installation + +``` +composer require socialite-manager/line-provider +``` + +## Usage + +```php +use Socialite\Provider\LineProvider; +use Socialite\Socialite; + +Socialite::driver(LineProvider::class, $config); +``` diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..fe95703 --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "socialite-manager/line-provider", + "description": "line provider", + "license": "MIT", + "require": { + "socialite-manager/socialite": "^1.0" + }, + "require-dev": { + "phpstan/phpstan": "^0.9.2", + "squizlabs/php_codesniffer": "^3.0" + }, + "autoload": { + "psr-4": { + "Socialite\\Provider\\": "src/" + } + }, + "scripts": { + "check": [ + "@cs-check", + "@analyse" + ], + "cs-check": "phpcs --standard=PSR2 --colors -p ./src", + "cs-fix": "phpcbf --standard=PSR2 --colors ./src", + "analyse": "phpstan analyse -l max src" + } +} diff --git a/src/LineProvider.php b/src/LineProvider.php new file mode 100644 index 0000000..fff3fcf --- /dev/null +++ b/src/LineProvider.php @@ -0,0 +1,65 @@ +buildAuthUrlFromBase( + 'https://access.line.me/dialog/oauth/weblogin', $state + ); + } + + /** + * {@inheritdoc} + */ + protected function getTokenUrl() + { + return 'https://api.line.me/v2/oauth/accessToken'; + } + + /** + * {@inheritdoc} + */ + protected function getUserByToken(string $token) + { + $response = $this->getHttpClient()->get( + 'https://api.line.me/v2/profile', [ + 'headers' => [ + 'Authorization' => 'Bearer ' . $token, + ], + ]); + return json_decode($response->getBody()->getContents(), true); + } + + /** + * {@inheritdoc} + */ + protected function mapUserToObject(array $user) + { + return (new User())->setRaw($user)->map([ + 'id' => $user['userId'], + 'nickname' => null, + 'name' => $user['displayName'], + 'email' => null, + 'avatar' => $user['pictureUrl'] ?? null, + ]); + } + + /** + * {@inheritdoc} + */ + protected function getTokenFields(string $code) + { + return array_merge(parent::getTokenFields($code), [ + 'grant_type' => 'authorization_code', + ]); + } +}