@@ -68,6 +68,7 @@ const UserAuthProps = z.object({
6868 accessToken : z . string ( ) ,
6969 user : UserSchema ,
7070 accounts : AccountsSchema ,
71+ refreshToken : z . string ( ) . optional ( ) ,
7172} )
7273export type AuthProps = z . infer < typeof AuthProps >
7374const AuthProps = z . discriminatedUnion ( 'type' , [ AccountAuthProps , UserAuthProps ] )
@@ -153,6 +154,15 @@ export async function handleTokenExchangeCallback(
153154) : Promise < TokenExchangeCallbackResult | undefined > {
154155 // options.props contains the current props
155156 if ( options . grantType === 'refresh_token' ) {
157+ const props = AuthProps . parse ( options . props )
158+ if ( props . type === 'account_token' ) {
159+ // Refreshing an account_token should not be possible, as we only do this for user tokens
160+ throw new McpError ( 'Internal Server Error' , 500 )
161+ }
162+ if ( ! props . refreshToken ) {
163+ throw new McpError ( 'Missing refreshToken' , 500 )
164+ }
165+
156166 // handle token refreshes
157167 const {
158168 access_token : accessToken ,
@@ -161,15 +171,15 @@ export async function handleTokenExchangeCallback(
161171 } = await refreshAuthToken ( {
162172 client_id : clientId ,
163173 client_secret : clientSecret ,
164- refresh_token : options . props . refreshToken ,
174+ refresh_token : props . refreshToken ,
165175 } )
166176
167177 return {
168178 newProps : {
169179 ...options . props ,
170180 accessToken,
171181 refreshToken,
172- } ,
182+ } satisfies AuthProps ,
173183 accessTokenTTL : expires_in ,
174184 }
175185 }
@@ -279,13 +289,13 @@ export function createAuthHandlers({
279289 label : user . email ,
280290 } ,
281291 scope : oauthReqInfo . scope ,
282- // This will be available on this.props inside CASBMCP
283292 props : {
293+ type : 'user_token' ,
284294 user,
285295 accounts,
286296 accessToken,
287297 refreshToken,
288- } ,
298+ } satisfies AuthProps ,
289299 } )
290300
291301 metrics . logEvent (
0 commit comments