Laravel AT Protocol Client (alpha & unstable)
1<?php
2
3namespace SocialDept\AtpClient\Http\Config;
4
5use Closure;
6use SocialDept\AtpClient\Crypto\JsonWebKeySet;
7
8class OAuthMetadata
9{
10 protected static ?Closure $clientMetadataUsing = null;
11
12 protected static ?Closure $jwksUsing = null;
13
14 /**
15 * Set custom callback for client metadata
16 */
17 public static function clientMetadataUsing(?Closure $callback): void
18 {
19 static::$clientMetadataUsing = $callback;
20 }
21
22 /**
23 * Get client metadata as array
24 */
25 public static function clientMetadata(): array
26 {
27 // Get custom metadata from callback if set
28 if (static::$clientMetadataUsing) {
29 $stored = call_user_func(static::$clientMetadataUsing);
30 } else {
31 $stored = config('client.oauth.client_metadata', []);
32 }
33
34 // Base metadata that should always be present
35 $base = [
36 'client_id' => route('atp.oauth.client-metadata'),
37 'jwks_uri' => route('atp.oauth.jwks'),
38 'redirect_uris' => config('client.client.redirect_uris', []),
39 'scope' => config('client.oauth.scope', 'atproto transition:generic'),
40 'grant_types' => ['authorization_code', 'refresh_token'],
41 'response_types' => ['code'],
42 'token_endpoint_auth_method' => 'private_key_jwt',
43 'token_endpoint_auth_signing_alg' => 'ES256',
44 'application_type' => 'web',
45 'dpop_bound_access_tokens' => true,
46 ];
47
48 // Merge and filter out null values
49 return array_filter(array_merge($stored, $base), fn ($value) => ! is_null($value));
50 }
51
52 /**
53 * Set custom callback for JWKS
54 */
55 public static function jwksUsing(?Closure $callback): void
56 {
57 static::$jwksUsing = $callback;
58 }
59
60 /**
61 * Get JWKS as array
62 */
63 public static function jwks(): array
64 {
65 if (static::$jwksUsing) {
66 return call_user_func(static::$jwksUsing);
67 }
68
69 return JsonWebKeySet::load()->toArray();
70 }
71}