diff --git a/.RELEASE.md b/.RELEASE.md new file mode 100644 index 0000000..f6ce06d --- /dev/null +++ b/.RELEASE.md @@ -0,0 +1 @@ +- Fix Authentik endpoints ([#244](https://github.com/pilcrowonpaper/arctic/issues/244)). diff --git a/package.json b/package.json index 54414ed..e49d98f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "arctic", "type": "module", - "version": "3.1.0", + "version": "3.1.1", "description": "OAuth 2.0 clients for popular providers", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/providers/authentik.ts b/src/providers/authentik.ts index 02029bf..d1bc08f 100644 --- a/src/providers/authentik.ts +++ b/src/providers/authentik.ts @@ -11,9 +11,9 @@ export class Authentik { private client: OAuth2Client; constructor(baseURL: string, clientId: string, clientSecret: string | null, redirectURI: string) { - this.authorizationEndpoint = joinURIAndPath(baseURL, "/application/o/authorize"); - this.tokenEndpoint = joinURIAndPath(baseURL, "/application/o/token"); - this.tokenRevocationEndpoint = joinURIAndPath(baseURL, "/application/o/revoke"); + this.authorizationEndpoint = joinURIAndPath(baseURL, "/application/o/authorize/"); + this.tokenEndpoint = joinURIAndPath(baseURL, "/application/o/token/"); + this.tokenRevocationEndpoint = joinURIAndPath(baseURL, "/application/o/revoke/"); this.client = new OAuth2Client(clientId, clientSecret, redirectURI); } diff --git a/src/request.test.ts b/src/request.test.ts new file mode 100644 index 0000000..2c7f7ea --- /dev/null +++ b/src/request.test.ts @@ -0,0 +1,21 @@ +import * as vitest from "vitest"; + +import { joinURIAndPath } from "./request.js"; + +vitest.test("joinBaseURIAndPath()", () => { + vitest.expect(joinURIAndPath("https://example.com", "/hi")).toBe("https://example.com/hi"); + vitest.expect(joinURIAndPath("https://example.com/", "/hi")).toBe("https://example.com/hi"); + vitest.expect(joinURIAndPath("https://example.com/", "hi")).toBe("https://example.com/hi"); + vitest.expect(joinURIAndPath("https://example.com", "hi")).toBe("https://example.com/hi"); + vitest.expect(joinURIAndPath("https://example.com", "/hi/")).toBe("https://example.com/hi/"); + + vitest + .expect(joinURIAndPath("https://example.com", "/hi", "/bye")) + .toBe("https://example.com/hi/bye"); + vitest + .expect(joinURIAndPath("https://example.com", "hi", "bye")) + .toBe("https://example.com/hi/bye"); + vitest + .expect(joinURIAndPath("https://example.com", "/hi/", "/bye/")) + .toBe("https://example.com/hi/bye/"); +}); diff --git a/src/request.ts b/src/request.ts index 6870bb4..9b82926 100644 --- a/src/request.ts +++ b/src/request.ts @@ -5,8 +5,7 @@ import { trimLeft, trimRight } from "./utils.js"; export function joinURIAndPath(base: string, ...path: string[]): string { let joined = trimRight(base, "/"); for (const part of path) { - joined += "/"; - joined += trimRight(trimLeft(part, "/"), "/"); + joined = trimRight(joined, "/") + "/" + trimLeft(part, "/"); } return joined; }