-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOAuthConfig.php
80 lines (68 loc) · 2.03 KB
/
OAuthConfig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
declare(strict_types=1);
namespace Revolution\Bluesky\Socialite;
use Closure;
use Illuminate\Support\Facades\Route;
use Revolution\Bluesky\Socialite\Key\JsonWebKeySet;
class OAuthConfig
{
protected static ?Closure $metadataUsing = null;
protected static ?Closure $jwksUsing = null;
/**
* Overrides the `client-metadata.json` response.
*
* ```
* // AppServiceProvider::boot()
*
* OAuthConfig::clientMetadataUsing(function() {
* return [];
* });
* ```
*/
public static function clientMetadataUsing(?callable $callback): void
{
static::$metadataUsing = is_callable($callback) ? $callback(...) : null;
}
public static function clientMetadata(): mixed
{
if (is_callable(static::$metadataUsing)) {
return call_user_func(static::$metadataUsing);
}
if (Route::has('bluesky.oauth.redirect')) {
$redirect = route('bluesky.oauth.redirect');
} else {
$redirect = 'http://127.0.0.1:8000/';
}
return collect((array) config('bluesky.oauth.metadata'))
->merge(
[
'client_id' => route('bluesky.oauth.client-metadata'),
'jwks_uri' => route('bluesky.oauth.jwks'),
'redirect_uris' => [url(config('bluesky.oauth.redirect') ?? $redirect)],
],
)->reject(fn ($item) => is_null($item))
->toArray();
}
/**
* Overrides the `jwks.json` response.
*
* ```
* // AppServiceProvider::boot()
*
* OAuthConfig::jwksUsing(function() {
* return [];
* });
* ```
*/
public static function jwksUsing(?callable $callback): void
{
static::$jwksUsing = is_callable($callback) ? $callback(...) : null;
}
public static function jwks(): mixed
{
if (is_callable(static::$jwksUsing)) {
return call_user_func(static::$jwksUsing);
}
return JsonWebKeySet::load()->toArray();
}
}