@@ -11,7 +11,11 @@ import type { V2CredentialHeaders } from '@/lib/api/server/routes/v2-credential-
1111import { hashApiKey } from '@/lib/api-key/crypto'
1212import { updateApiKeyLastUsed } from '@/lib/api-key/service'
1313import { ANONYMOUS_USER_ID } from '@/lib/auth/constants'
14- import { InvalidOAuthAccessTokenError , verifyOAuthAccessToken } from '@/lib/auth/oauth-access-token'
14+ import {
15+ InvalidOAuthAccessTokenError ,
16+ type OAuthAccessTokenOptions ,
17+ verifyOAuthAccessToken ,
18+ } from '@/lib/auth/oauth-access-token'
1519import { resolveWorkspaceBillingPayer } from '@/lib/billing/core/billing-attribution'
1620import { getHighestPrioritySubscription } from '@/lib/billing/core/subscription'
1721import { isAuthDisabled } from '@/lib/core/config/env-flags'
@@ -156,11 +160,14 @@ async function authenticateApiKey(apiKeyHeader: string): Promise<V2ApiKeyAuthCon
156160 * token and per user, on the user's own plan. A client that holds many tokens
157161 * for one user still shares that user's bucket.
158162 */
159- async function authenticateBearer ( token : string , resource ?: string ) : Promise < V2ApiKeyAuthContext > {
163+ async function authenticateBearer (
164+ token : string ,
165+ options : OAuthAccessTokenOptions
166+ ) : Promise < V2ApiKeyAuthContext > {
160167 let principal : OAuthAccessTokenPrincipal
161168 try {
162- principal = resource
163- ? await verifyOAuthAccessToken ( token , { resource } )
169+ principal = options . resource
170+ ? await verifyOAuthAccessToken ( token , options )
164171 : await verifyOAuthAccessToken ( token )
165172 } catch ( error ) {
166173 if ( error instanceof InvalidOAuthAccessTokenError ) {
@@ -188,7 +195,7 @@ async function authenticateBearer(token: string, resource?: string): Promise<V2A
188195 */
189196export async function authenticateV2ApiKey (
190197 credential : V2CredentialHeaders ,
191- options : { resource ?: string } = { }
198+ options : OAuthAccessTokenOptions = { }
192199) : Promise < V2ApiKeyAuthContext > {
193200 if ( isAuthDisabled ) {
194201 return {
@@ -204,7 +211,7 @@ export async function authenticateV2ApiKey(
204211 }
205212 }
206213 if ( credential . apiKey ) return authenticateApiKey ( credential . apiKey )
207- if ( credential . bearer ) return authenticateBearer ( credential . bearer , options . resource )
214+ if ( credential . bearer ) return authenticateBearer ( credential . bearer , options )
208215 if ( credential . malformedOAuthBearer ) {
209216 throw new V2ApiKeyUnauthenticatedError ( 'Invalid access token' , 'bearer' )
210217 }
0 commit comments