# Gitlab OAuth

**URL:** <https://discuss.write.as/t/gitlab-oauth/1165>\
**Category:** Development\
**Created:** [March 11, 2020, 9:32am UTC](https://discuss.write.as/t/gitlab-oauth/1165 "2020-03-11T09:32:10Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![paddatrapper](https://discuss.write.as/user_avatar/discuss.write.as/paddatrapper/32/483_2.png) [@paddatrapper](https://discuss.write.as/u/paddatrapper)\
**Post date:** [March 11, 2020, 9:32am UTC](https://discuss.write.as/t/gitlab-oauth/1165/1 "2020-03-11T09:32:10Z")

</div>

As outlined by @matt [here](https://discuss.write.as/t/feature-suggestion-login-with-an-account-from-other-websites-e-g-mastodon-github-etc/872/8), I tend to implement OAuth authentication against generic Gitlab instances to support the Debian Social team’s use case

---

<div class="post-metadata">

**Author:** ![paddatrapper](https://discuss.write.as/user_avatar/discuss.write.as/paddatrapper/32/483_2.png) [@paddatrapper](https://discuss.write.as/u/paddatrapper)\
**Post date:** [March 11, 2020, 10:05am UTC](https://discuss.write.as/t/gitlab-oauth/1165/2 "2020-03-11T10:05:33Z")

</div>

I am running into issues with `make install`, as it fails to compile effects.less. Anyone have any ideas?

```auto
lessc app.less --clean-css="--s1 --advanced" ../static/css/write.css
ParseError: Unrecognised input in /home/kyle/projects/go/writefreely/less/effects.less on line 34, column 1:
33 @-ms-keyframes fadeIn { 0% { opacity: 0; position: static; } 100% { opacity: 1; }}
34 @-keyframes fadeIn { 0% { opacity: 0; position: static; } 100% { opacity: 1; }}
35 

make: *** [Makefile:5: all] Error 1

```

---

<div class="post-metadata">

**Author:** ![paddatrapper](https://discuss.write.as/user_avatar/discuss.write.as/paddatrapper/32/483_2.png) [@paddatrapper](https://discuss.write.as/u/paddatrapper)\
**Post date:** [March 11, 2020, 10:08am UTC](https://discuss.write.as/t/gitlab-oauth/1165/3 "2020-03-11T10:08:03Z")

</div>

Removing the two `@-keyframes` lines worked, but then ran into:

```auto
lessc app.less --clean-css="--s1 --advanced" ../static/css/write.css
Error: Cannot find module 'clean-css'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at tree.Ruleset.toCSS (/usr/lib/nodejs/less/lib/less/parser.js:608:40)
    at /usr/lib/nodejs/less/bin/lessc:357:32
    at tree.importVisitor.finish [as _finish] (/usr/lib/nodejs/less/lib/less/parser.js:669:28)
    at tree.importVisitor.subFinish [as _finish] (/usr/lib/nodejs/less/lib/less/import-visitor.js:63:47)
    at tree.importVisitor.run (/usr/lib/nodejs/less/lib/less/import-visitor.js:25:22)
    at /usr/lib/nodejs/less/lib/less/import-visitor.js:72:38
make[2]: *** [Makefile:5: all] Error 2

```

---

<div class="post-metadata">

**Author:** ![paddatrapper](https://discuss.write.as/user_avatar/discuss.write.as/paddatrapper/32/483_2.png) [@paddatrapper](https://discuss.write.as/u/paddatrapper)\
**Post date:** [March 11, 2020, 10:11am UTC](https://discuss.write.as/t/gitlab-oauth/1165/4 "2020-03-11T10:11:34Z")

</div>

Fixed by installing the `cleancss` package. Filed a bug with the Debian `node-less` package to fix the dependency

---

<div class="post-metadata">

**Author:** ![paddatrapper](https://discuss.write.as/user_avatar/discuss.write.as/paddatrapper/32/483_2.png) [@paddatrapper](https://discuss.write.as/u/paddatrapper)\
**Post date:** [March 11, 2020, 11:33am UTC](https://discuss.write.as/t/gitlab-oauth/1165/5 "2020-03-11T11:33:18Z")

</div>

I can successfully run writefreely after building, but none of the static assets load. I am building and running within the git repo. I can’t see any errors or anything, it just doesn’t style the page at all.

I have started implementing the GItlab OAuth changes and opened a WIP [PR](https://github.com/writeas/writefreely/pull/277). However, trying to click on the ‘Login with GitLab’ link results in a 404 error, which I am stuck trying to trace down…

---

<div class="post-metadata">

**Author:** ![matt](https://discuss.write.as/user_avatar/discuss.write.as/matt/32/2760_2.png) [@matt](https://discuss.write.as/u/matt)\
**Post date:** [March 11, 2020, 1:05pm UTC](https://discuss.write.as/t/gitlab-oauth/1165/6 "2020-03-11T13:05:20Z")

</div>

What do you get when you load `http://your.instance/css/write.css`?

I’ve checked out your pull request and am looking into the 404 issue. For one thing, looks like there’s still some old Slack and Write.as auth code inside `configureGitlabOauth()` – see lines 179 and 182. But I’m still seeing a 404 after that, so digging some more…

---

<div class="post-metadata">

**Author:** ![matt](https://discuss.write.as/user_avatar/discuss.write.as/matt/32/2760_2.png) [@matt](https://discuss.write.as/u/matt)\
**Post date:** [March 11, 2020, 1:08pm UTC](https://discuss.write.as/t/gitlab-oauth/1165/7 "2020-03-11T13:08:39Z")

</div>

Ah, it’s the capital G in the string returned by `GetProvider()` inside `oauth_gitlab.go`. The result of that method is used for the route – so currently `/oauth/Gitlab` would work, but not `/oauth/gitlab`.

---

<div class="post-metadata">

**Author:** ![paddatrapper](https://discuss.write.as/user_avatar/discuss.write.as/paddatrapper/32/483_2.png) [@paddatrapper](https://discuss.write.as/u/paddatrapper)\
**Post date:** [March 11, 2020, 1:31pm UTC](https://discuss.write.as/t/gitlab-oauth/1165/8 "2020-03-11T13:31:55Z")

</div>

> [@matt](#):
>
> What do you get when you load `http://your.instance/css/write.css` ?

As the entire page source:

```auto
[object Object]

```

> [@matt](#):
>
> I’ve checked out your pull request and am looking into the 404 issue. For one thing, looks like there’s still some old Slack and Write.as auth code inside `configureGitlabOauth()` – see lines 179 and 182. But I’m still seeing a 404 after that, so digging some more…

Fixed. I also noticed the issue with line 179 is also present in the WriteAs configure, so fixed that too

> [@matt](#):
>
> Ah, it’s the capital G in the string returned by `GetProvider()` inside `oauth_gitlab.go` . The result of that method is used for the route – so currently `/oauth/Gitlab` would work, but not `/oauth/gitlab` .

Ah, makes sense. Fixed and will continue testing

---

<div class="post-metadata">

**Author:** ![paddatrapper](https://discuss.write.as/user_avatar/discuss.write.as/paddatrapper/32/483_2.png) [@paddatrapper](https://discuss.write.as/u/paddatrapper)\
**Post date:** [March 11, 2020, 1:53pm UTC](https://discuss.write.as/t/gitlab-oauth/1165/9 "2020-03-11T13:53:34Z")

</div>

It seems, while a configuration option, SQLite isn’t actually supported by writefreely, thanks to the following error:

```auto
state, err := h.DB.GenerateOAuthState(ctx, h.oauthClient.GetProvider(), h.oauthClient.GetClientID())

unable to record oauth client state: no such function: NOW

```

SQLite [seems](https://www.techonthenet.com/sqlite/functions/now.php) to expect `date('now')` instead

---

<div class="post-metadata">

**Author:** ![matt](https://discuss.write.as/user_avatar/discuss.write.as/matt/32/2760_2.png) [@matt](https://discuss.write.as/u/matt)\
**Post date:** [March 11, 2020, 2:07pm UTC](https://discuss.write.as/t/gitlab-oauth/1165/10 "2020-03-11T14:07:39Z")

</div>

I’ll fix that and push the changes up. Just a minute

---

<div class="post-metadata">

**Author:** ![matt](https://discuss.write.as/user_avatar/discuss.write.as/matt/32/2760_2.png) [@matt](https://discuss.write.as/u/matt)\
**Post date:** [March 11, 2020, 2:28pm UTC](https://discuss.write.as/t/gitlab-oauth/1165/11 "2020-03-11T14:28:37Z")

</div>

Oof, GitHub is a pain. Here’s the diff for you to apply to fix that:

```diff
diff --git a/database.go b/database.go
index cea7a97..6beea1a 100644
--- a/database.go
+++ b/database.go
@@ -2512,7 +2512,7 @@ func (db *datastore) GetCollectionLastPostTime(id int64) (*time.Time, error) {
 
 func (db *datastore) GenerateOAuthState(ctx context.Context, provider, clientID string) (string, error) {
        state := store.Generate62RandomString(24)
- _, err := db.ExecContext(ctx, "INSERT INTO oauth_client_states (state, provider, client_id, used, created_at) VALUES (?, ?, ?, FALSE, NOW())", state, provider, clientID)
+ _, err := db.ExecContext(ctx, "INSERT INTO oauth_client_states (state, provider, client_id, used, created_at) VALUES (?, ?, ?, FALSE, "+db.now()+")", state, provider, clientID)
        if err != nil {
                return "", fmt.Errorf("unable to record oauth client state: %w", err)
        }

```

---

<div class="post-metadata">

**Author:** ![matt](https://discuss.write.as/user_avatar/discuss.write.as/matt/32/2760_2.png) [@matt](https://discuss.write.as/u/matt)\
**Post date:** [March 11, 2020, 2:51pm UTC](https://discuss.write.as/t/gitlab-oauth/1165/12 "2020-03-11T14:51:48Z")

</div>

I’ll hand this over to @ngerakines now – he can give you feedback and help you work through the rest. Feel free to continue the conversation here and on that PR.

---

<div class="post-metadata">

**Author:** ![ngerakines](https://discuss.write.as/user_avatar/discuss.write.as/ngerakines/32/368_2.png) [@ngerakines](https://discuss.write.as/u/ngerakines)\
**Post date:** [March 11, 2020, 2:53pm UTC](https://discuss.write.as/t/gitlab-oauth/1165/13 "2020-03-11T14:53:40Z")

</div>

@paddatrapper, I put some comments in the PR. There were a few things that I didn’t see, but wasn’t sure if you’ve gotten to them or not yet.

---

<div class="post-metadata">

**Author:** ![paddatrapper](https://discuss.write.as/user_avatar/discuss.write.as/paddatrapper/32/483_2.png) [@paddatrapper](https://discuss.write.as/u/paddatrapper)\
**Post date:** [March 12, 2020, 9:02am UTC](https://discuss.write.as/t/gitlab-oauth/1165/14 "2020-03-12T09:02:22Z")

</div>

@ngerakines thanks. I have made the changes and can now successfully authenticate against GitLab OAuth
