Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions packages/openauth/src/provider/gitlab.ts
Original file line number Diff line number Diff line change
@@ -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",
},
})
}
5 changes: 4 additions & 1 deletion packages/openauth/src/scopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions packages/openauth/test/scopes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
})

Expand Down