Skip to content

Commit 37a8782

Browse files
authored
Add Online Scout Manager (OSM) provider (#1418)
1 parent c4db726 commit 37a8782

File tree

5 files changed

+176
-0
lines changed

5 files changed

+176
-0
lines changed

monorepo-builder.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ parameters:
144144
src/Notion: 'git@github.com:SocialiteProviders/Notion.git'
145145
src/Nuvemshop: 'git@github.com:SocialiteProviders/Nuvemshop.git'
146146
src/OAuthgen: 'git@github.com:SocialiteProviders/OAuthgen.git'
147+
src/OnlineScoutManager: 'git@github.com:SocialiteProviders/OnlineScoutManager.git'
147148
src/OSChina: 'git@github.com:SocialiteProviders/OSChina.git'
148149
src/Odnoklassniki: 'git@github.com:SocialiteProviders/Odnoklassniki.git'
149150
src/Okta: 'git@github.com:SocialiteProviders/Okta.git'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace SocialiteProviders\OnlineScoutManager;
4+
5+
use SocialiteProviders\Manager\SocialiteWasCalled;
6+
7+
class OnlineScoutManagerExtendSocialite
8+
{
9+
public function handle(SocialiteWasCalled $socialiteWasCalled): void
10+
{
11+
$socialiteWasCalled->extendSocialite('onlinescoutmanager', Provider::class);
12+
}
13+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace SocialiteProviders\OnlineScoutManager;
4+
5+
use GuzzleHttp\RequestOptions;
6+
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
7+
use SocialiteProviders\Manager\OAuth2\User;
8+
9+
class Provider extends AbstractProvider
10+
{
11+
public const IDENTIFIER = 'ONLINESCOUTMANAGER';
12+
13+
public const URL = 'https://www.onlinescoutmanager.co.uk';
14+
15+
protected $scopes = [
16+
'section:badge:read',
17+
'section:event:read',
18+
'section:programme:read',
19+
];
20+
21+
protected $scopeSeparator = ' ';
22+
23+
protected function getAuthUrl($state): string
24+
{
25+
return $this->buildAuthUrlFromBase(self::URL.'/oauth/authorize', $state);
26+
}
27+
28+
protected function getTokenUrl(): string
29+
{
30+
return self::URL.'/oauth/token';
31+
}
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
protected function getUserByToken($token)
37+
{
38+
$response = $this->getHttpClient()->get(self::URL.'/oauth/resource', [
39+
RequestOptions::HEADERS => [
40+
'Authorization' => 'Bearer '.$token,
41+
],
42+
]);
43+
44+
return json_decode((string) $response->getBody(), true);
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
protected function mapUserToObject(array $user)
51+
{
52+
$user_data = $user['data'];
53+
54+
return (new User)->setRaw($user)->map([
55+
'id' => $user_data['user_id'],
56+
'name' => $user_data['full_name'],
57+
'email' => $user_data['email'],
58+
'avatar' => $user_data['profile_picture_url'] ?? null,
59+
'is_leader' => $user_data['has_section_access'] ?? false
60+
]);
61+
}
62+
}

src/OnlineScoutManager/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Online Scout Manager
2+
3+
```bash
4+
composer require socialiteproviders/onlinescoutmanager
5+
```
6+
7+
## Installation & Basic Usage
8+
9+
Please see the [Base Installation Guide](https://socialiteproviders.com/usage/), then follow the provider specific instructions below.
10+
11+
### Add configuration to `config/services.php`
12+
13+
```php
14+
'onlinescoutmanager' => [
15+
'client_id' => env('OSM_CLIENT_ID'),
16+
'client_secret' => env('OSM_CLIENT_SECRET'),
17+
'redirect' => env('OSM_REDIRECT_URI'),
18+
],
19+
```
20+
21+
### Add provider event listener
22+
23+
#### Laravel 11+
24+
25+
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.
26+
27+
* Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers.
28+
29+
```php
30+
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
31+
$event->extendSocialite('onlinescoutmanager', \SocialiteProviders\OnlineScoutManager\Provider::class);
32+
});
33+
```
34+
<details>
35+
<summary>
36+
Laravel 10 or below
37+
</summary>
38+
Configure the package's listener to listen for `SocialiteWasCalled` events.
39+
40+
Add the event to your `listen[]` array in `app/Providers/EventServiceProvider`. See the [Base Installation Guide](https://socialiteproviders.com/usage/) for detailed instructions.
41+
42+
```php
43+
protected $listen = [
44+
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
45+
// ... other providers
46+
\SocialiteProviders\OnlineScoutManager\OnlineScoutManagerExtendSocialite::class.'@handle',
47+
],
48+
];
49+
```
50+
</details>
51+
52+
### Usage
53+
54+
You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed):
55+
56+
```php
57+
return Socialite::driver('onlinescoutmanager')->redirect();
58+
```
59+
60+
### Returned User fields
61+
62+
- ``id``
63+
- ``name``
64+
- ``email``
65+
- ``avatar``
66+
- ``is_leader``
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "socialiteproviders/onlinescoutmanager",
3+
"description": "OnlineScoutManager OAuth2 Provider for Laravel Socialite",
4+
"license": "MIT",
5+
"keywords": [
6+
"laravel",
7+
"oauth",
8+
"oauth2",
9+
"provider",
10+
"socialite",
11+
"onlinescoutmanager"
12+
],
13+
"authors": [
14+
{
15+
"name": "Adam Francis",
16+
"email": "me@adamfrancis.dev"
17+
}
18+
],
19+
"support": {
20+
"issues": "https://github.com/socialiteproviders/providers/issues",
21+
"source": "https://github.com/socialiteproviders/providers",
22+
"docs": "https://socialiteproviders.com/onlinescoutmanager"
23+
},
24+
"require": {
25+
"php": "^8.4",
26+
"ext-json": "*",
27+
"socialiteproviders/manager": "^4.4"
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"SocialiteProviders\\OnlineScoutManager\\": ""
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)