update resource to be a url
This commit is contained in:
parent
36f338ae23
commit
224a2e242d
5 changed files with 33 additions and 92 deletions
|
|
@ -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)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
|
|||
Loading…
Reference in a new issue