Skip to content

Commit bc94314

Browse files
authored
Merge pull request #478 from karlomikus/develop
Feature release
2 parents 928b356 + 0957b77 commit bc94314

File tree

8 files changed

+156
-0
lines changed

8 files changed

+156
-0
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# v5.3.0
2+
## New
3+
- Added PocketId as a SSO provider
4+
```
5+
# Setup via:
6+
POCKETID_BASE_URL=
7+
POCKETID_CLIENT_ID=
8+
POCKETID_CLIENT_SECRET=
9+
POCKETID_REDIRECT_URI=
10+
```
11+
- Added import support for `cocktailexplorer.co`
12+
13+
# v5.2.5
14+
## Fixes
15+
- Fixed menu item having wrong thumb path
16+
117
# v5.2.4
218
## Fixes
319
- Fixed wrong thumbnail URL getting synced into search engine

app/Providers/AppServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function boot()
3939
$event->extendSocialite('authentik', \SocialiteProviders\Authentik\Provider::class);
4040
$event->extendSocialite('authelia', \SocialiteProviders\Authelia\Provider::class);
4141
$event->extendSocialite('keycloak', \SocialiteProviders\Keycloak\Provider::class);
42+
$event->extendSocialite('pocketid', \Kami\Cocktail\Services\Auth\PocketIdProvider::class);
4243
});
4344

4445
if (DB::getDriverName() === 'sqlite') {

app/Scraper/Manager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ final class Manager
3030
\Kami\Cocktail\Scraper\Sites\MakeMeACocktail::class,
3131
\Kami\Cocktail\Scraper\Sites\KindredCocktails::class,
3232
\Kami\Cocktail\Scraper\Sites\CraftedPour::class,
33+
\Kami\Cocktail\Scraper\Sites\CocktailExplorer::class,
3334
];
3435

3536
public function __construct(private readonly string $url)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kami\Cocktail\Scraper\Sites;
6+
7+
use Kami\RecipeUtils\AmountValue;
8+
use Kami\RecipeUtils\RecipeIngredient;
9+
use Symfony\Component\DomCrawler\Crawler;
10+
11+
class CocktailExplorer extends DefaultScraper
12+
{
13+
public static function getSupportedUrls(): array
14+
{
15+
return [
16+
'https://www.cocktailexplorer.co',
17+
];
18+
}
19+
20+
public function ingredients(): array
21+
{
22+
$result = $this->crawler->filter('.video__recipe__ingredients li')->each(function (Crawler $node): RecipeIngredient {
23+
$amount = $node->filter('.video__recipe__ingredient__quantity')->attr('data-ingredient-amount');
24+
$unit = $node->filter('.video__recipe__ingredient__quantity')->attr('data-ingredient-unit');
25+
$ingredient = $node->filter('strong')->text();
26+
27+
return new RecipeIngredient(
28+
name: $ingredient,
29+
amount: AmountValue::fromString($amount),
30+
units: $unit,
31+
source: $node->text(),
32+
);
33+
});
34+
35+
return $result;
36+
}
37+
}

app/Services/Auth/OauthProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum OauthProvider: string
1818
case Authentik = 'authentik';
1919
case Authelia = 'authelia';
2020
case Keycloak = 'keycloak';
21+
case PocketId = 'pocketid';
2122

2223
public function getPrettyName(): string
2324
{
@@ -28,6 +29,7 @@ public function getPrettyName(): string
2829
self::Authentik => 'Authentik',
2930
self::Authelia => 'Authelia',
3031
self::Keycloak => 'Keycloak',
32+
self::PocketId => 'PocketId',
3133
};
3234
}
3335
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kami\Cocktail\Services\Auth;
6+
7+
use Laravel\Socialite\Contracts\Provider;
8+
use SocialiteProviders\Manager\SocialiteWasCalled;
9+
10+
class PocketIdExtendSocialite
11+
{
12+
public function handle(SocialiteWasCalled $socialiteWasCalled): void
13+
{
14+
$socialiteWasCalled->extendSocialite('pocketid', Provider::class);
15+
}
16+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kami\Cocktail\Services\Auth;
6+
7+
use Illuminate\Support\Arr;
8+
use GuzzleHttp\RequestOptions;
9+
use SocialiteProviders\Manager\OAuth2\User;
10+
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
11+
12+
class PocketIdProvider extends AbstractProvider
13+
{
14+
public const IDENTIFIER = 'POCKETID';
15+
16+
/**
17+
* @var array<string>
18+
*/
19+
protected $scopes = ['openid profile email'];
20+
21+
/**
22+
* @return array<string>
23+
*/
24+
public static function additionalConfigKeys(): array
25+
{
26+
return ['base_url'];
27+
}
28+
29+
protected function getBaseUrl(): string
30+
{
31+
return rtrim($this->getConfig('base_url'), '/');
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
protected function getAuthUrl($state)
38+
{
39+
return $this->buildAuthUrlFromBase($this->getBaseUrl() . '/authorize', $state);
40+
}
41+
42+
/**
43+
* {@inheritdoc}
44+
*/
45+
protected function getTokenUrl()
46+
{
47+
return $this->getBaseUrl() . '/api/oidc/token';
48+
}
49+
50+
/**
51+
* @return array<mixed>
52+
*/
53+
protected function getUserByToken($token): array
54+
{
55+
$response = $this->getHttpClient()->get($this->getBaseUrl() . '/api/oidc/userinfo', [
56+
RequestOptions::HEADERS => [
57+
'Authorization' => 'Bearer '.$token,
58+
],
59+
]);
60+
61+
return json_decode((string) $response->getBody(), true);
62+
}
63+
64+
/**
65+
* @param array<mixed> $user
66+
*/
67+
protected function mapUserToObject(array $user): User
68+
{
69+
return (new User())->setRaw($user)->map([
70+
'id' => Arr::get($user, 'sub'),
71+
'nickname' => Arr::get($user, 'preferred_username'),
72+
'name' => Arr::get($user, 'name'),
73+
'email' => Arr::get($user, 'email'),
74+
]);
75+
}
76+
}

config/services.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,11 @@
7070
'base_url' => env('KEYCLOAK_BASE_URL'),
7171
'realms' => env('KEYCLOAK_REALM'),
7272
],
73+
74+
'pocketid' => [
75+
'base_url' => env('POCKETID_BASE_URL'),
76+
'client_id' => env('POCKETID_CLIENT_ID'),
77+
'client_secret' => env('POCKETID_CLIENT_SECRET'),
78+
'redirect' => env('POCKETID_REDIRECT_URI')
79+
],
7380
];

0 commit comments

Comments
 (0)