Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions monorepo-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ parameters:
src/LinkedIn: 'git@github.com:SocialiteProviders/LinkedIn.git'
src/Live: 'git@github.com:SocialiteProviders/Microsoft-Live.git'
src/LifeScienceLogin: 'git@github.com:SocialiteProviders/LifeScienceLogin.git'
src/LinuxDo: 'git@github.com:SocialiteProviders/LinuxDo.git'
src/MailChimp: 'git@github.com:SocialiteProviders/MailChimp.git'
src/Mailru: 'git@github.com:SocialiteProviders/Mailru.git'
src/MakerLog: 'git@github.com:SocialiteProviders/MakerLog.git'
Expand Down
19 changes: 19 additions & 0 deletions src/LinuxDo/LinuxDoExtendSocialite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace SocialiteProviders\LinuxDo;

use SocialiteProviders\Manager\SocialiteWasCalled;

class LinuxDoExtendSocialite
{
/**
* Register the provider.
*
* @param \SocialiteProviders\Manager\SocialiteWasCalled $socialiteWasCalled
* @return void
*/
public function handle(SocialiteWasCalled $socialiteWasCalled): void
{
$socialiteWasCalled->extendSocialite('linuxdo', Provider::class);
}
}
65 changes: 65 additions & 0 deletions src/LinuxDo/Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace SocialiteProviders\LinuxDo;

use GuzzleHttp\RequestOptions;
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
use SocialiteProviders\Manager\OAuth2\User;

class Provider extends AbstractProvider
{
const IDENTIFIER = 'LINUXDO';

protected $scopes = ['user'];

protected function getAuthUrl($state): string
{
return $this->buildAuthUrlFromBase('https://connect.linux.do/oauth2/authorize', $state);
}

protected function getTokenUrl(): string
{
return 'https://connect.linux.do/oauth2/token';
}

/**
* {@inheritdoc}
*/
protected function getUserByToken($token)
{
$response = $this->getHttpClient()->get('https://connect.linux.do/api/user', [
RequestOptions::HEADERS => [
'Authorization' => 'Bearer ' . $token,
],
]);

return json_decode((string)$response->getBody(), true);
}

/**
* {@inheritdoc}
*/
protected function mapUserToObject(array $user)
{
$login = $user['login'];
$avatar_url = $user['avatar_url'];

return (new User)->setRaw($user)->map([
'id' => $user['id'],
'sub' => $user['sub'],
'username' => $user['username'],
'login' => $login,
'name' => $user['name'],
'email' => $user['email'],
'avatar_url' => $avatar_url,
'avatar_template' => $user['avatar_template'],
'active' => $user['active'],
'trust_level' => $user['trust_level'],
'silenced' => $user['silenced'],
'external_ids' => $user['external_ids'],
'api_key' => $user['api_key'],
'nickname' => $login,
'avatar' => $avatar_url,
]);
}
}
58 changes: 58 additions & 0 deletions src/LinuxDo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# LinuxDo

```bash
composer require socialiteproviders/linuxdo
```

## Installation & Basic Usage

Please see the [Base Installation Guide](https://socialiteproviders.com/usage/), then follow the provider specific instructions below.

### Add configuration to `config/services.php`

```php
'linuxdo' => [
'client_id' => env('LINUXDO_CLIENT_ID'),
'client_secret' => env('LINUXDO_CLIENT_SECRET'),
'redirect' => env('LINUXDO_REDIRECT_URI')
],
```

### Add provider event listener

#### Laravel 11+

In Laravel 11, the default `EventServiceProvider` provider was removed. Instead, add the listener using the `listen` method on the `Event` facade, in your `AppServiceProvider` `boot` method.

* Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers.

```php
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
$event->extendSocialite('linuxdo', \SocialiteProviders\LinuxDo\Provider::class);
});
```
<details>
<summary>
Laravel 10 or below
</summary>
Configure the package's listener to listen for `SocialiteWasCalled` events.

Add the event to your `listen[]` array in `app/Providers/EventServiceProvider`. See the [Base Installation Guide](https://socialiteproviders.com/usage/) for detailed instructions.

```php
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// ... other providers
\SocialiteProviders\LinuxDo\LinuxDoExtendSocialite::class.'@handle',
],
];
```
</details>

### Usage

You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed):

```php
return Socialite::driver('linuxdo')->redirect();
```
29 changes: 29 additions & 0 deletions src/LinuxDo/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "socialiteproviders/linuxdo",
"description": "LinuxDo OAuth2 Provider for Laravel Socialite",
"license": "MIT",
"keywords": [
"linuxdo",
"laravel",
"oauth",
"oauth2",
"provider",
"socialite"
],
"authors": [
{
"name": "puzzle9",
"email": "happypuzzle@126.com"
}
],
"require": {
"php": "^8.0",
"ext-json": "*",
"socialiteproviders/manager": "^4.4"
},
"autoload": {
"psr-4": {
"SocialiteProviders\\LinuxDo\\": ""
}
}
}