Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mosaxiv committed Mar 21, 2018
0 parents commit 59e366d
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
vendor/
composer.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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);
```
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
65 changes: 65 additions & 0 deletions src/LineProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Socialite\Provider;

use Socialite\Two\AbstractProvider;
use Socialite\Two\User;

class LineProvider extends AbstractProvider
{
/**
* {@inheritdoc}
*/
protected function getAuthUrl(string $state)
{
return $this->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',
]);
}
}

0 comments on commit 59e366d

Please sign in to comment.