@@ -114,11 +114,14 @@ class OAuthServerConfig {
114114 final Uri tokenEndpoint;
115115 final Uri userInfoEndpoint;
116116 final List <String > requiredScopes;
117+
117118 /// Canonical server URI for resource parameter and audience validation
118119 /// Must be HTTPS and match the actual server URI
119120 final String serverUri;
121+
120122 /// Authorization server metadata endpoint
121123 final Uri ? authServerMetadataEndpoint;
124+
122125 /// Allowed redirect URIs for validation
123126 final List <String > allowedRedirectUris;
124127
@@ -168,8 +171,8 @@ class OAuthServerConfig {
168171 Uri .parse ('https://www.googleapis.com/oauth2/v2/userinfo' ),
169172 requiredScopes: requiredScopes,
170173 serverUri: serverUri,
171- authServerMetadataEndpoint:
172- Uri . parse ( 'https://accounts.google.com/.well-known/openid-configuration' ),
174+ authServerMetadataEndpoint: Uri . parse (
175+ 'https://accounts.google.com/.well-known/openid-configuration' ),
173176 allowedRedirectUris: allowedRedirectUris,
174177 );
175178 }
@@ -193,11 +196,13 @@ class OAuthTokenInfo {
193196
194197 bool get isExpired => DateTime .now ().isAfter (expiresAt);
195198
196- String get userId => userInfo['id' ]? .toString () ?? userInfo['sub' ]? .toString () ?? 'unknown' ;
197- String get username => userInfo['login' ]? .toString () ??
198- userInfo['name' ]? .toString () ??
199- userInfo['email' ]? .toString () ??
200- 'unknown' ;
199+ String get userId =>
200+ userInfo['id' ]? .toString () ?? userInfo['sub' ]? .toString () ?? 'unknown' ;
201+ String get username =>
202+ userInfo['login' ]? .toString () ??
203+ userInfo['name' ]? .toString () ??
204+ userInfo['email' ]? .toString () ??
205+ 'unknown' ;
201206}
202207
203208/// OAuth validator for MCP servers
@@ -362,7 +367,8 @@ class OAuthServerValidator {
362367 'redirect_uri' : redirectUri,
363368 'grant_type' : 'authorization_code' ,
364369 'code_verifier' : codeVerifier, // PKCE requirement
365- 'resource' : config.serverUri, // MCP spec requirement for audience validation
370+ 'resource' :
371+ config.serverUri, // MCP spec requirement for audience validation
366372 };
367373
368374 final response = await http.post (
@@ -574,7 +580,8 @@ class OAuthServerTransport implements Transport {
574580 _sessionTokens[sessionId] = tokenInfo;
575581 }
576582
577- print ('✓ Authenticated request from ${tokenInfo .username } (${tokenInfo .userId })' );
583+ print (
584+ '✓ Authenticated request from ${tokenInfo .username } (${tokenInfo .userId })' );
578585
579586 // Forward to inner transport
580587 await _innerTransport.handleRequest (req, parsedBody);
@@ -839,7 +846,8 @@ Future<void> main(List<String> args) async {
839846 print (' -out server_cert.pem -days 365 -nodes \\ ' );
840847 print (' -subj "/CN=localhost"' );
841848 print ('' );
842- print ('For production, use a reverse proxy with proper TLS certificates.' );
849+ print (
850+ 'For production, use a reverse proxy with proper TLS certificates.' );
843851 print ('Falling back to HTTP mode...' );
844852 print ('' );
845853 httpServer = await HttpServer .bind (host, port);
@@ -857,12 +865,14 @@ Future<void> main(List<String> args) async {
857865 print (' ✅ Token audience validation' );
858866 print (' ✅ Redirect URI validation' );
859867 print (' ✅ OAuth metadata discovery' );
860- print (' ${useHttps ? "✅" : "⚠️ " } HTTPS ${useHttps ? "enabled" : "not enabled (use --https)" }' );
868+ print (
869+ ' ${useHttps ? "✅" : "⚠️ " } HTTPS ${useHttps ? "enabled" : "not enabled (use --https)" }' );
861870 print ('' );
862871 print ('Usage:' );
863872 print (' 1. Obtain OAuth access token from provider' );
864873 print (' 2. Make requests with: Authorization: Bearer <token>' );
865- print (' 3. Access metadata: GET $serverUri /.well-known/oauth-authorization-server' );
874+ print (
875+ ' 3. Access metadata: GET $serverUri /.well-known/oauth-authorization-server' );
866876 print ('' );
867877 print ('Server running. Press Ctrl+C to stop.\n ' );
868878
@@ -971,8 +981,8 @@ Future<void> main(List<String> args) async {
971981 } catch (e) {
972982 print ('Error handling request: $e ' );
973983 if (! request.response.headers.contentType
974- .toString ()
975- .contains ('event-stream' )) {
984+ .toString ()
985+ .contains ('event-stream' )) {
976986 request.response
977987 ..statusCode = HttpStatus .internalServerError
978988 ..write ('Internal server error' );
0 commit comments