-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan
committed
Nov 14, 2022
1 parent
dfd4f61
commit ecc1a23
Showing
599 changed files
with
25,477 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"go.lintTool":"golangci-lint", | ||
"go.lintFlags": [ | ||
"--fast" | ||
], | ||
"gopls": { | ||
"buildFlags": ["-tags=integration"] | ||
}, | ||
"nuxt.isNuxtApp": false, | ||
"go.buildFlags": [ | ||
"-tags=integration" | ||
], | ||
"go.testTags": "integration", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Build Schema Spy Documentation", | ||
"type": "shell", | ||
"command": "java -jar C:\\bin\\schemaspy.jar -t sqlite-xerial -db dev.db --outputDirectory .dev\\schema -u main -dp C:\\bin\\sqlite.jar -debug -s main -cat '%'" | ||
}, | ||
{ | ||
"label": "Start mailslurper", | ||
"type": "shell", | ||
"command": "mailslurper" | ||
} | ||
|
||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM golang:1.19-buster as builder | ||
WORKDIR /app | ||
COPY go.* ./ | ||
RUN go mod download | ||
COPY . ./ | ||
RUN go build -v -o gotrxx | ||
|
||
FROM gcr.io/distroless/base-debian11:nonroot | ||
WORKDIR /app | ||
COPY --from=builder /app/gotrxx /app/gotrxx | ||
USER nonroot:nonroot | ||
CMD ["/app/gotrxx"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Copyright (c) 2022, Jan | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
<p align="center"> | ||
<img alt="gotrxx" height="125" src="./docs/assets/logo.svg"> | ||
</p> | ||
<a name="readme-top"></a> | ||
<p align="center"> | ||
<strong>gotrxx</strong> is a <a href="https://github.com/netlify/gotrue">gotrue</a> API-compatible authorization server written in go, with support for OAuth <strong>Authorization Code Grant with PKCE</strong>, <strong>Client Credentials Grant</strong> and <strong>Password Grant</strong> (for gotrue compatibility). | ||
</p> | ||
|
||
[](https://goreportcard.com/report/github.com/eisenwinter/fiql-sql-adapter) [](https://github.com/eisenwinter/fiql-sql-adapter/actions/workflows/go.yml) [](https://www.repostatus.org/#wip) [](https://opensource.org/licenses/BSD-2-Clause) | ||
|
||
|
||
# gotrxx | ||
|
||
> **Warning** | ||
> I am moving stuff to github right now, a lot still needs furhter testing and polishing and docs are lacking | ||
## Whats in the box | ||
|
||
- **Authorization Code Grant** with Proof Key of Exchange for all your SPA and public needs. | ||
- **Client Credentials Grant** for all your Backend and confidential client needs. | ||
- **Password Grant** for gotrue compatibility | ||
- **Discovery Endpoint** although it does **not** support OpenID-connect it has a discovery endpoint for convenient use with [oidc-client-ts](https://github.com/authts/oidc-client-ts) | ||
- **Flexible signing and verification choice** (HS256, HS384, HS512, RS256, RS384, RS512) token signing and verification (very special thanks to [jwx](https://github.com/lestrrat-go/jwx)) | ||
- **jwk** Endpoint when using RS* signing | ||
- **Localization** of the pages | ||
- **Administration Endpoints** which can be enabled if needed and wanted | ||
- **2FA** with TOTP - works with MS Authenticator, Google Authenticator and Authy and others[^1] | ||
- **Roles** for optional ACL implementations | ||
- optional **Invite Only Setup** with pre-defined roles and application authorizations | ||
- optional **Clicky Clicky Admin UI** gotrxx-admin | ||
|
||
[^1]: Can not be used with Password Grant | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## Usecase | ||
|
||
This authorization server can be used for either a restricted pool of people (like I do for my family and friends) or for public use. | ||
The main reason for this to exist is that I wanted to limit the access to applications to certain users, but still be able to make | ||
access-for-everyone applications as well. | ||
|
||
Use this **if** | ||
- you want an easy setup authorization server with OAuth support | ||
- you have clients, friends, or family you wanna share certain (pre-approved) applications with them | ||
- you don't need OpenID-connect | ||
- a full-blown solution (ory, keycloak, identity server) is way too much | ||
- want to set up a self-hosted Netlify CMS setup with something else then gotrue | ||
- want an authorizations server that works with either SQLite, Postgres or MariaDB/MySQL | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## Why | ||
|
||
Well, I went a bit overboard. It all started when a family member of mine wanted to edit the static site I made for her and I went on to set up a self-hosted | ||
version of netlify CMS. And things did not go as I wanted. Fast-forward - we are here after maniacally coding for weeks (okay it's been on and off for months at this point) because I disliked a few minor things about gotrue[^2]. | ||
|
||
[^2]: gotrue still is a good and well-thought-out solution tough (only love) | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## Quickstart | ||
|
||
### Building from source | ||
|
||
gotrxx is written and tested against Go 1.18+ | ||
|
||
``` | ||
git clone [redacted] | ||
``` | ||
|
||
``` | ||
go build main.go -o gotrxx | ||
``` | ||
|
||
adapt the supplied `config.yml` to your needs and you are ready. | ||
|
||
For further setup please refer to the documentation [link-redacted]. | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## Docker Images | ||
|
||
Yes. We have em. | ||
|
||
``` | ||
docker run -v ./config.yml:/app/config.yml:ro gotrxx:latest | ||
``` | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## Documentation | ||
|
||
If you want a deeper dive check out the documentation | ||
[link redacted] | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## MFA | ||
|
||
NOTE: the password flow will fail if you enable MFA on a user | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## OpenIDConnect | ||
|
||
No. | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## Thanks and shout-outs to | ||
|
||
Thank everyone who wrote anything I used, this list in no special order. | ||
|
||
go-chi for their awsome router | ||
- github.com/go-chi/chi/ | ||
|
||
lestrrat for the awsome jwx libraries (wich do a lot of the heavy lifting) | ||
- github.com/lestrrat-go/jwx | ||
|
||
jaytaylor for not having me make plain text templates as well | ||
- github.com/jaytaylor/html2text | ||
|
||
spf13 for cobra and viper | ||
- github.com/spf13/cobra | ||
- github.com/spf13/viper | ||
|
||
Masterminds for squirrel | ||
- github.com/Masterminds/squirrel | ||
|
||
jmoiron for sqlx | ||
- github.com/jmoiron/sqlx | ||
|
||
joho for godotenv | ||
- github.com/joho/godotenv | ||
|
||
jeremywohl for flatten | ||
- github.com/jeremywohl/flatten | ||
|
||
mattn for the sqlite driver | ||
- github.com/mattn/go-sqlite3 | ||
|
||
go-mail ... for mails | ||
- github.com/go-mail/mail | ||
|
||
adlio for the migrations | ||
- github.com/adlio/schema | ||
|
||
11ty - for making me not regret my static template choice twice | ||
- https://www.11ty.dev/ | ||
|
||
AnandChowdhary for the language icons | ||
- github.com/AnandChowdhary/language-icons | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
### Special thanks | ||
|
||
Well, and of course ``gotrue``, this main inspiration to start this. | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
## Contributing | ||
|
||
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue for further questions or recommendations. | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> | ||
|
||
|
||
## License | ||
|
||
Distributed under the BSD-2-Clause license. See `LICENSE.txt` for more information. | ||
|
||
<p align="right">(<a href="#readme-top">back to top</a>)</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# https://taskfile.dev | ||
|
||
version: '3' | ||
|
||
vars: | ||
EXE: gotrxx{{exeExt}} | ||
tasks: | ||
default: | ||
cmds: | ||
- task -l | ||
|
||
dev:provision: | ||
desc: "sets up the workspace and gets dependecies" | ||
cmds: | ||
- mkdir -p bin | ||
- mkdir -p .dev | ||
- go mod download | ||
- task: test:misc:certificates | ||
- task: templates:restore | ||
|
||
build: | ||
desc: "build the compiled binary" | ||
cmds: | ||
- go build -v -o bin/{{.EXE}} | ||
|
||
assets:sass: | ||
desc: "Rebuilds the sass unminified" | ||
cmds: | ||
- sass templates/static/sass/main.sass templates/static/css/main.css | ||
assets:sass:minified: | ||
desc: "Rebuilds the sass minified" | ||
cmds: | ||
- sass templates/static/sass/main.sass templates/static/css/main.css --style compressed | ||
|
||
lint:golangci: | ||
desc: "Runs golang ci linter" | ||
cmds: | ||
- golangci-lint --verbose run | ||
silent: true | ||
|
||
lint:goreportcard: | ||
desc: "Runs goreportcard" | ||
cmds: | ||
- goreportcard-cli -v | ||
silent: true | ||
|
||
lint:gofmt: | ||
desc: "Runs gofmt with -s -w" | ||
cmds: | ||
- gofmt -s -w ./.. | ||
silent: true | ||
|
||
lint:wrapcheck: | ||
desc: "Run wrapcheck" | ||
cmds: | ||
- wrapcheck ./... | ||
silent: true | ||
|
||
lint:staticcheck: | ||
desc: "Run staticcheck" | ||
cmds: | ||
- staticcheck ./... | ||
silent: true | ||
|
||
templates:dev: | ||
desc: "Runs 11ty dev server for template styling" | ||
dir: template_dev | ||
cmds: | ||
- yarn dev | ||
silent: true | ||
|
||
templates:restore: | ||
desc: "restores node deps" | ||
dir: template_dev | ||
cmds: | ||
- yarn | ||
|
||
docs:serve: | ||
desc: "Serves the docs" | ||
cmds: | ||
- docsify serve docs | ||
silent: true | ||
|
||
test:misc:certificates: | ||
desc: "Generate test certificates" | ||
cmds: | ||
- openssl genrsa -out .dev/id_rsa 4096 && openssl rsa -in .dev/id_rsa -RSAPublicKey_out -out .dev/id_rsa.pub | ||
silent: true | ||
|
||
test: | ||
desc: "Runs unit tests" | ||
cmds: | ||
- go test -v ./... | ||
|
||
test:integration:sqlite: | ||
desc: "Integration tests for the sqlite db" | ||
cmds: | ||
- go test -tags=integration -count=1 -v ./... | ||
env: | ||
INTEGRATION_TEST_DB_TYPE: sqlite | ||
INTEGRATION_TEST_DB_DSN: :memory:?cache=shared | ||
silent: true | ||
|
||
test:integration:sqlite:coverage: | ||
desc: "Integration tests for the sqlite db" | ||
cmds: | ||
- go test -coverprofile=coverage.out -tags=integration -count=1 -v ./... | ||
- go tool cover -html=coverage.out | ||
env: | ||
INTEGRATION_TEST_DB_TYPE: sqlite | ||
INTEGRATION_TEST_DB_DSN: :memory:?cache=shared | ||
silent: true | ||
|
||
test:integration:mariadb: | ||
desc: "Integration tests for the maria/mysql db (runs on mariadb:10.9.2)" | ||
cmds: | ||
- docker start gotrxx-mariadb || docker run -d -p 3306:3306 --name gotrxx-mariadb --env MARIADB_DATABASE=gotrxx --env MARIADB_USER=example --env MARIADB_PASSWORD=example --env MARIADB_ROOT_PASSWORD=secret-example docker.io/library/mariadb:10.9.2 | ||
- go test -tags=integration -count=1 -v ./... | ||
# - docker stop gotrxx-mariadb | ||
env: | ||
INTEGRATION_TEST_DB_TYPE: mysql | ||
INTEGRATION_TEST_DB_DSN: example:example@tcp(localhost:3306)/gotrxx | ||
silent: true | ||
|
||
test:integration:pg: | ||
desc: "Integration tests for the postgres db (runs on postgres:14.5)" | ||
cmds: | ||
- docker start gotrxx-pg || docker run -d -p 5432:5432 --name gotrxx-pg --env POSTGRES_USER=example --env POSTGRES_PASSWORD=example --env POSTGRES_DB=gotrxx docker.io/library/postgres:14.5 | ||
- go test -tags=integration -count=1 -v ./... | ||
# - docker stop gotrxx-pg | ||
env: | ||
INTEGRATION_TEST_DB_TYPE: pg | ||
INTEGRATION_TEST_DB_DSN: postgres://example:example@localhost:5432/gotrxx | ||
silent: true |
Oops, something went wrong.