@@ -65,7 +65,7 @@ def __init__(self, settings: GitHubOAuthSettings, github_callback_url: str):
6565 self .clients : dict [str , OAuthClientInformationFull ] = {}
6666 self .auth_codes : dict [str , AuthorizationCode ] = {}
6767 self .tokens : dict [str , AccessToken ] = {}
68- self .state_mapping : dict [str , dict [str , str ]] = {}
68+ self .state_mapping : dict [str , dict [str , str | None ]] = {}
6969 # Maps MCP tokens to GitHub tokens
7070 self .token_mapping : dict [str , str ] = {}
7171
@@ -87,6 +87,7 @@ async def authorize(self, client: OAuthClientInformationFull, params: Authorizat
8787 "code_challenge" : params .code_challenge ,
8888 "redirect_uri_provided_explicitly" : str (params .redirect_uri_provided_explicitly ),
8989 "client_id" : client .client_id ,
90+ "resource" : params .resource , # RFC 8707
9091 }
9192
9293 # Build GitHub authorization URL
@@ -110,6 +111,12 @@ async def handle_github_callback(self, code: str, state: str) -> str:
110111 code_challenge = state_data ["code_challenge" ]
111112 redirect_uri_provided_explicitly = state_data ["redirect_uri_provided_explicitly" ] == "True"
112113 client_id = state_data ["client_id" ]
114+ resource = state_data .get ("resource" ) # RFC 8707
115+
116+ # These are required values from our own state mapping
117+ assert redirect_uri is not None
118+ assert code_challenge is not None
119+ assert client_id is not None
113120
114121 # Exchange code for token with GitHub
115122 async with create_mcp_http_client () as client :
@@ -144,6 +151,7 @@ async def handle_github_callback(self, code: str, state: str) -> str:
144151 expires_at = time .time () + 300 ,
145152 scopes = [self .settings .mcp_scope ],
146153 code_challenge = code_challenge ,
154+ resource = resource , # RFC 8707
147155 )
148156 self .auth_codes [new_code ] = auth_code
149157
@@ -180,6 +188,7 @@ async def exchange_authorization_code(
180188 client_id = client .client_id ,
181189 scopes = authorization_code .scopes ,
182190 expires_at = int (time .time ()) + 3600 ,
191+ resource = authorization_code .resource , # RFC 8707
183192 )
184193
185194 # Find GitHub token for this client
0 commit comments