Laravel AT Protocol Client (alpha & unstable)
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Register ScopeGate and atp.scope middleware

+26 -4
+26 -4
src/AtpClientServiceProvider.php
··· 2 2 3 3 namespace SocialDept\AtpClient; 4 4 5 + use Illuminate\Routing\Router; 5 6 use Illuminate\Support\Facades\Route; 6 7 use Illuminate\Support\ServiceProvider; 7 8 use SocialDept\AtpClient\Auth\ClientMetadataManager; ··· 9 10 use SocialDept\AtpClient\Auth\DPoPNonceManager; 10 11 use SocialDept\AtpClient\Auth\OAuthEngine; 11 12 use SocialDept\AtpClient\Auth\ScopeChecker; 13 + use SocialDept\AtpClient\Auth\ScopeGate; 12 14 use SocialDept\AtpClient\Auth\TokenRefresher; 13 15 use SocialDept\AtpClient\Enums\ScopeEnforcementLevel; 16 + use SocialDept\AtpClient\Http\Middleware\RequiresScopeMiddleware; 14 17 use SocialDept\AtpClient\Console\GenerateOAuthKeyCommand; 15 18 use SocialDept\AtpClient\Contracts\CredentialProvider; 16 19 use SocialDept\AtpClient\Contracts\KeyStore; ··· 64 67 ); 65 68 }); 66 69 70 + // Register ScopeGate for AtpScope facade 71 + $this->app->singleton('atp-scope', function ($app) { 72 + return new ScopeGate( 73 + $app->make(SessionManager::class), 74 + $app->make(ScopeChecker::class), 75 + ); 76 + }); 77 + 67 78 // Register main client facade accessor 68 79 $this->app->bind('atp-client', function ($app) { 69 80 return new class($app) ··· 123 134 } 124 135 125 136 $this->registerRoutes(); 137 + $this->registerMiddleware(); 138 + } 139 + 140 + /** 141 + * Register middleware aliases 142 + */ 143 + protected function registerMiddleware(): void 144 + { 145 + /** @var Router $router */ 146 + $router = $this->app->make(Router::class); 147 + $router->aliasMiddleware('atp.scope', RequiresScopeMiddleware::class); 126 148 } 127 149 128 150 /** ··· 144 166 ->name('atp.oauth.jwks'); 145 167 }); 146 168 147 - // Register standard .well-known endpoint 148 - Route::get('.well-known/oauth-client-metadata', ClientMetadataController::class) 149 - ->name('atp.oauth.well-known'); 169 + // Register recommended client id convention (see: https://atproto.com/guides/oauth#clients) 170 + Route::get('oauth-client-metadata.json', ClientMetadataController::class) 171 + ->name('atp.oauth.json'); 150 172 } 151 173 152 174 /** ··· 156 178 */ 157 179 public function provides(): array 158 180 { 159 - return ['atp-client']; 181 + return ['atp-client', 'atp-scope']; 160 182 } 161 183 }