From 6b960ffdf7fb3a0b392c51c7285cbd0d8df78d9b Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Thu, 4 Sep 2025 10:32:21 -0700 Subject: [PATCH 1/2] Add GitLab OAuth2 provider Closes: Adds GitLab authentication support to OpenAuth --- packages/openauth/src/provider/gitlab.ts | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 packages/openauth/src/provider/gitlab.ts diff --git a/packages/openauth/src/provider/gitlab.ts b/packages/openauth/src/provider/gitlab.ts new file mode 100644 index 00000000..850d0b5c --- /dev/null +++ b/packages/openauth/src/provider/gitlab.ts @@ -0,0 +1,45 @@ +/** + * Use this provider to authenticate with Gitlab. + * + * ```ts {5-8} + * import { GitlabProvider } from "@openauthjs/openauth/provider/gitlab" + * + * export default issuer({ + * providers: { + * gitlab: GitlabProvider({ + * clientId: "1234567890", + * clientSecret: "0987654321" + * }) + * } + * }) + * ``` + * + * @packageDocumentation + */ + +import { Oauth2Provider, Oauth2WrappedConfig } from "./oauth2.js" + +export interface GitlabConfig extends Oauth2WrappedConfig {} + +/** + * Create a Gitlab OAuth2 provider. + * + * @param config - The config for the provider. + * @example + * ```ts + * GitlabProvider({ + * clientId: "1234567890", + * clientSecret: "0987654321" + * }) + * ``` + */ +export function GitlabProvider(config: GitlabConfig) { + return Oauth2Provider({ + ...config, + type: "gitlab", + endpoint: { + authorization: "https://gitlab.com/oauth/authorize", + token: "https://gitlab.com/oauth/token", + }, + }) +} From f439255473f40c2aef833627ff5b184bfcc217a9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 4 Sep 2025 18:25:26 +0000 Subject: [PATCH 2/2] auto: format code --- packages/openauth/src/scopes.ts | 5 ++++- packages/openauth/test/scopes.test.ts | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/openauth/src/scopes.ts b/packages/openauth/src/scopes.ts index e513becc..74875294 100644 --- a/packages/openauth/src/scopes.ts +++ b/packages/openauth/src/scopes.ts @@ -2,7 +2,10 @@ export function parseScopes(scope: string | null | undefined) { return scope?.split(" ").filter((s) => s) } -export function validateScopes(tokenReq?: string | null, authorizeReq?: string[]) { +export function validateScopes( + tokenReq?: string | null, + authorizeReq?: string[], +) { if (!authorizeReq?.length || tokenReq === null || tokenReq === undefined) { return authorizeReq } diff --git a/packages/openauth/test/scopes.test.ts b/packages/openauth/test/scopes.test.ts index eaada3a5..27897673 100644 --- a/packages/openauth/test/scopes.test.ts +++ b/packages/openauth/test/scopes.test.ts @@ -28,13 +28,13 @@ describe("validate", () => { expect(validateScopes(undefined, ["foo"])).toEqual(["foo"]) expect(validateScopes(null, ["foo"])).toEqual(["foo"]) expect(validateScopes("foo", ["foo"])).toEqual(["foo"]) - expect(validateScopes("foo bar", ["foo","bar"])).toEqual(["foo", "bar"]) - expect(validateScopes("bar foo", ["foo","bar"])).toEqual(["bar", "foo"]) + expect(validateScopes("foo bar", ["foo", "bar"])).toEqual(["foo", "bar"]) + expect(validateScopes("bar foo", ["foo", "bar"])).toEqual(["bar", "foo"]) }) test("narrower scopes", () => { expect(validateScopes("", ["foo"])).toBeEmpty() - expect(validateScopes("foo", ["foo","bar"])).toEqual(["foo"]) + expect(validateScopes("foo", ["foo", "bar"])).toEqual(["foo"]) expect(validateScopes("foo", ["foo", "bar"])).toEqual(["foo"]) })