update resource to be a url

This commit is contained in:
Olivier Chafik 2025-06-17 00:18:33 +01:00
commit 224a2e242d
No known key found for this signature in database
5 changed files with 33 additions and 92 deletions

View file

@ -295,7 +295,7 @@ describe('Authorization Handler', () => {
expect(mockProviderWithResource).toHaveBeenCalledWith(
validClient,
expect.objectContaining({
resource: 'https://api.example.com/resource',
resource: new URL('https://api.example.com/resource'),
redirectUri: 'https://example.com/callback',
codeChallenge: 'challenge123'
}),
@ -365,7 +365,7 @@ describe('Authorization Handler', () => {
expect(mockProviderWithResources).toHaveBeenCalledWith(
validClient,
expect.objectContaining({
resource: 'https://api1.example.com/resource',
resource: new URL('https://api1.example.com/resource'),
state: 'test-state'
}),
expect.any(Object)
@ -391,7 +391,7 @@ describe('Authorization Handler', () => {
expect(mockProviderPost).toHaveBeenCalledWith(
validClient,
expect.objectContaining({
resource: 'https://api.example.com/resource'
resource: new URL('https://api.example.com/resource')
}),
expect.any(Object)
);

View file

@ -142,7 +142,7 @@ export function authorizationHandler({ provider, rateLimit: rateLimitConfig }: A
scopes: requestedScopes,
redirectUri: redirect_uri,
codeChallenge: code_challenge,
resource,
resource: resource ? new URL(resource) : undefined,
}, res);
} catch (error) {
// Post-redirect errors - redirect with error parameters

View file

@ -42,13 +42,13 @@ export interface OAuthServerProvider {
authorizationCode: string,
codeVerifier?: string,
redirectUri?: string,
resource?: string
resource?: URL
): Promise<OAuthTokens>;
/**
* Exchanges a refresh token for an access token.
*/
exchangeRefreshToken(client: OAuthClientInformationFull, refreshToken: string, scopes?: string[], resource?: string): Promise<OAuthTokens>;
exchangeRefreshToken(client: OAuthClientInformationFull, refreshToken: string, scopes?: string[], resource?: URL): Promise<OAuthTokens>;
/**
* Verifies an access token and returns information about it.

View file

@ -112,7 +112,7 @@ describe("Proxy OAuth Server Provider", () => {
codeChallenge: 'test-challenge',
state: 'test-state',
scopes: ['read', 'write'],
resource: 'https://api.example.com/resource'
resource: new URL('https://api.example.com/resource')
},
mockResponse
);

View file

@ -134,7 +134,7 @@ export class ProxyOAuthServerProvider implements OAuthServerProvider {
// Add optional standard OAuth parameters
if (params.state) searchParams.set("state", params.state);
if (params.scopes?.length) searchParams.set("scope", params.scopes.join(" "));
if (params.resource) searchParams.set("resource", params.resource);
if (params.resource) searchParams.set("resource", params.resource.href);
targetUrl.search = searchParams.toString();
res.redirect(targetUrl.toString());
@ -154,7 +154,7 @@ export class ProxyOAuthServerProvider implements OAuthServerProvider {
authorizationCode: string,
codeVerifier?: string,
redirectUri?: string,
resource?: string
resource?: URL
): Promise<OAuthTokens> {
const params = new URLSearchParams({
grant_type: "authorization_code",
@ -199,7 +199,7 @@ export class ProxyOAuthServerProvider implements OAuthServerProvider {
client: OAuthClientInformationFull,
refreshToken: string,
scopes?: string[],
resource?: string
resource?: URL
): Promise<OAuthTokens> {
const params = new URLSearchParams({