Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow self hosted gitlab server #13

Merged
merged 2 commits into from
Jan 13, 2022
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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

[![NPM version](https://img.shields.io/npm/v/adonis-ally-gitlab.svg)](https://www.npmjs.com/package/adonis-ally-gitlab)

A [Gitlab](https://gitlab.com/) driver for [AdonisJS Ally](https://docs.adonisjs.com/guides/auth/social)
A [Gitlab](https://gitlab.com/) driver for [AdonisJS Ally](https://docs.adonisjs.com/guides/auth/social).
You can authenticate with your self hosted gitlab or with https://gitlab.com/

## Getting started

Expand All @@ -29,6 +30,7 @@ node ace configure adonis-ally-gitlab
### 3. Validate environment variables

```ts
GITLAB_URL: Env.schema.string(),
GITLAB_CLIENT_ID: Env.schema.string(),
GITLAB_CLIENT_SECRET: Env.schema.string(),
```
Expand All @@ -40,16 +42,22 @@ const allyConfig: AllyConfig = {
// ... other drivers
gitlab: {
driver: 'gitlab',
gitlabUrl: 'https://gitlab.example.com/'
clientId: Env.get('GITLAB_CLIENT_ID'),
clientSecret: Env.get('GITLAB_CLIENT_SECRET'),
callbackUrl: 'http://localhost:3333/gitlab/callback',
},
}
```

If you don't supply gitlabUrl, https://www.gitlab.com/ will be used.

When using self hosted gitlab,
get the clientId and clientSecret from /admin/applications/ on your gitlab instance.

## Scopes

You can pass an array of scopes in your configuration, for example `['user', 'profile', 'api']`. You have a full list of scopes in the [Gitlab Oauth documentation](https://docs.gitlab.com/ee/integration/oauth_provider.html#authorized-applications)
You can pass an array of scopes in your configuration, for example `['read_user', 'profile', 'api']`. You have a full list of scopes in the [Gitlab Oauth documentation](https://docs.gitlab.com/ee/integration/oauth_provider.html#authorized-applications)

## How it works

Expand Down
7 changes: 6 additions & 1 deletion src/Gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type GitlabScopes =

export type GitlabDriverConfig = {
driver: 'gitlab'
gitlabUrl?: string
clientId: string
clientSecret: string
callbackUrl: string
Expand All @@ -53,7 +54,11 @@ export class GitlabDriver extends Oauth2Driver<GitlabAccessToken, GitlabScopes>

constructor(ctx: HttpContextContract, public config: GitlabDriverConfig) {
super(ctx, config)

if (config.gitlabUrl) {
this.authorizeUrl = config.gitlabUrl + 'oauth/authorize'
this.accessTokenUrl = config.gitlabUrl + 'oauth/token'
this.userInfoUrl = config.gitlabUrl + 'api/v4/user'
}
this.loadState()
}

Expand Down