@@ -65,7 +65,7 @@ def __init__(self, settings: GitHubOAuthSettings, github_callback_url: str):
65
65
self .clients : dict [str , OAuthClientInformationFull ] = {}
66
66
self .auth_codes : dict [str , AuthorizationCode ] = {}
67
67
self .tokens : dict [str , AccessToken ] = {}
68
- self .state_mapping : dict [str , dict [str , str ]] = {}
68
+ self .state_mapping : dict [str , dict [str , str | None ]] = {}
69
69
# Maps MCP tokens to GitHub tokens
70
70
self .token_mapping : dict [str , str ] = {}
71
71
@@ -87,6 +87,7 @@ async def authorize(self, client: OAuthClientInformationFull, params: Authorizat
87
87
"code_challenge" : params .code_challenge ,
88
88
"redirect_uri_provided_explicitly" : str (params .redirect_uri_provided_explicitly ),
89
89
"client_id" : client .client_id ,
90
+ "resource" : params .resource , # RFC 8707
90
91
}
91
92
92
93
# Build GitHub authorization URL
@@ -110,6 +111,12 @@ async def handle_github_callback(self, code: str, state: str) -> str:
110
111
code_challenge = state_data ["code_challenge" ]
111
112
redirect_uri_provided_explicitly = state_data ["redirect_uri_provided_explicitly" ] == "True"
112
113
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
113
120
114
121
# Exchange code for token with GitHub
115
122
async with create_mcp_http_client () as client :
@@ -144,6 +151,7 @@ async def handle_github_callback(self, code: str, state: str) -> str:
144
151
expires_at = time .time () + 300 ,
145
152
scopes = [self .settings .mcp_scope ],
146
153
code_challenge = code_challenge ,
154
+ resource = resource , # RFC 8707
147
155
)
148
156
self .auth_codes [new_code ] = auth_code
149
157
@@ -180,6 +188,7 @@ async def exchange_authorization_code(
180
188
client_id = client .client_id ,
181
189
scopes = authorization_code .scopes ,
182
190
expires_at = int (time .time ()) + 3600 ,
191
+ resource = authorization_code .resource , # RFC 8707
183
192
)
184
193
185
194
# Find GitHub token for this client
0 commit comments