Skip to content
This repository was archived by the owner on Sep 28, 2019. It is now read-only.

Commit 7fdf521

Browse files
committed
Laravel 5.5 LTS support
1 parent 403af8d commit 7fdf521

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
[![StyleCI](https://styleci.io/repos/69769315/shield?branch=master)](https://styleci.io/repos/69769315)
2-
3-
# Telegram Unofficial OAuth2 Provider for Laravel Socialite
1+
# Telegram OAuth2 Provider for Laravel
42

53
**Note:** This package utilizes an unofficial service [telepass.me](https://telepass.me). Official OAuth API for Telegram does not exist.
64

5+
**Note:** This package requires php version 7.0 or higher.
6+
77
## Installation
88

99
### 0. Credentials
@@ -28,7 +28,7 @@ For example:
2828
\SocialiteProviders\Manager\ServiceProvider::class, // add
2929
];
3030
```
31-
**Note:** If you would like to use the Socialite Facade, you need to [install it](http://laravel.com/docs/5.0/authentication#social-authentication).
31+
**Note:** If you would like to use the Socialite Facade, you need to [install it](https://github.com/laravel/socialite).
3232

3333
### 3. Add the Event and Listeners
3434
- Add `SocialiteProviders\Manager\SocialiteWasCalled` event to your `listen[]` array in `<app_name>/Providers/EventServiceProvider`.
@@ -101,5 +101,16 @@ return Socialite::with('telegram')->stateless(false)->redirect();
101101
return Socialite::with('telegram')->stateless()->redirect();
102102
```
103103

104+
### Retrieving the Access Token Response Body
105+
106+
Laravel Socialite by default only allows access to the `access_token`. Which can be accessed via the `\Laravel\Socialite\User->token` public property. Sometimes you need access to the whole response body which may contain items such as a `refresh_token`.
107+
108+
You can get the access token response body, after you called the `user()` method in Socialite, by accessing the property `$user->accessTokenResponseBody`;
109+
110+
```php
111+
$user = Socialite::driver('telegram')->user();
112+
$accessTokenResponseBody = $user->accessTokenResponseBody;
113+
```
114+
104115
## Credits
105116
Thanks to the [Socialite Providers](socialiteproviders.github.io) project for documentation and provider template.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"email": "codefuhrer@gmail.com"
99
}],
1010
"require": {
11-
"php": "^5.6 || ^7.0",
12-
"socialiteproviders/manager": "~2.0"
11+
"php": ">=7.0.0",
12+
"socialiteproviders/manager": "~3.0"
1313
},
1414
"autoload": {
1515
"psr-4": {

src/Provider.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace SocialiteProviders\Telegram;
44

5+
use function json_decode, array_merge, sprintf;
6+
7+
use SocialiteProviders\Manager\OAuth2\User;
58
use Laravel\Socialite\Two\ProviderInterface;
69
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
7-
use SocialiteProviders\Manager\OAuth2\User;
810

911
class Provider extends AbstractProvider implements ProviderInterface
1012
{
@@ -34,7 +36,7 @@ protected function getAuthUrl($state)
3436
/**
3537
* {@inheritdoc}
3638
*/
37-
protected function getTokenUrl()
39+
protected function getTokenUrl(): string
3840
{
3941
return 'https://telepass.me/oauth/token';
4042
}
@@ -46,7 +48,7 @@ protected function getUserByToken($token)
4648
{
4749
$response = $this->getHttpClient()->get('https://telepass.me/api/user', [
4850
'headers' => [
49-
'Authorization' => 'Bearer '.$token,
51+
'Authorization' => sprintf('Bearer %s', $token),
5052
],
5153
]);
5254

src/TelegramExtendSocialite.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class TelegramExtendSocialite
1111
*/
1212
public function handle(SocialiteWasCalled $socialiteWasCalled)
1313
{
14-
$socialiteWasCalled->extendSocialite('telegram', __NAMESPACE__.'\Provider');
14+
$socialiteWasCalled->extendSocialite(
15+
'telegram', __NAMESPACE__.'\Provider'
16+
);
1517
}
1618
}

0 commit comments

Comments
 (0)