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

OIDC #168

Draft
wants to merge 97 commits into
base: main
Choose a base branch
from
Draft

OIDC #168

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
ea7bc41
chore(oidc): generate migration
kloenk Aug 11, 2024
2d2a6b8
chore(oidc): implement backend routes for one oidc provider named oidc
kloenk Aug 12, 2024
4cb4d20
feat(oidc): Add OIDC authentication framework
kloenk Aug 12, 2024
b6c2650
Translated using Weblate (Swedish)
weblate Aug 12, 2024
695b6d6
Added translation using Weblate (Chinese (Traditional))
weblate Aug 13, 2024
fc95d2c
Translated using Weblate (Chinese (Traditional))
weblate Aug 13, 2024
639f795
[LANGUAGE UPDATE] Frontend translations for Italian and German (#170)
lukasitaly Aug 14, 2024
43676ab
Translated using Weblate (French)
weblate Aug 15, 2024
39163f3
Translated using Weblate (French)
weblate Aug 16, 2024
f0a3780
Added translation using Weblate (Spanish)
weblate Aug 22, 2024
0348da3
Translated using Weblate (Spanish)
weblate Aug 22, 2024
40cbccf
Translated using Weblate (Spanish)
weblate Aug 22, 2024
7891af3
Translated using Weblate (Spanish)
weblate Aug 22, 2024
050f22f
Translated using Weblate (Spanish)
weblate Aug 22, 2024
66882d6
Translated using Weblate (Spanish)
weblate Aug 22, 2024
cffe57b
Added translation using Weblate (Russian)
weblate Aug 24, 2024
fe880cc
Translated using Weblate (Russian)
weblate Aug 24, 2024
33ee208
Translated using Weblate (Russian)
weblate Aug 24, 2024
b56b5d2
Translated using Weblate (Russian)
weblate Aug 25, 2024
1688773
adding email validator (#178)
RomuloGatto Aug 25, 2024
f22bce7
Translated using Weblate (Russian)
weblate Aug 28, 2024
593da25
fix: CSV export not including item notes (#180)
LarssonOliver Aug 28, 2024
7647ea9
added the ability to add a photo in the item creation modal (#173)
cjmielke Aug 29, 2024
7114f26
Translated using Weblate (French)
weblate Aug 29, 2024
52a44da
Translated using Weblate (French)
weblate Aug 29, 2024
0dacc97
Translated using Weblate (French)
weblate Aug 30, 2024
9f7a119
Translated using Weblate (Russian)
weblate Aug 31, 2024
c2d0cce
Translated using Weblate (Turkish)
weblate Aug 31, 2024
ea57981
Translated using Weblate (Turkish)
weblate Aug 31, 2024
d72437d
Update config.mts
tankerkiller125 Sep 1, 2024
7baf58a
Translated using Weblate (Turkish)
weblate Sep 1, 2024
3e6f4b3
Added translation using Weblate (Chinese (Simplified))
weblate Sep 1, 2024
5497a10
Translated using Weblate (Chinese (Simplified))
weblate Sep 1, 2024
7b14694
Translated using Weblate (Chinese (Simplified))
weblate Sep 1, 2024
6051e1f
Translated using Weblate (Chinese (Simplified))
weblate Sep 1, 2024
760cc8e
Translated using Weblate (Chinese (Simplified))
weblate Sep 1, 2024
1601e52
Translated using Weblate (Chinese (Simplified))
weblate Sep 1, 2024
3a949ae
Translated using Weblate (Chinese (Simplified))
weblate Sep 1, 2024
343e56b
Translated using Weblate (Chinese (Simplified))
weblate Sep 1, 2024
3c273b3
Translated using Weblate (Chinese (Simplified))
weblate Sep 1, 2024
85e5c7e
Translated using Weblate (Chinese (Simplified))
weblate Sep 1, 2024
dbe77ea
Translated using Weblate (Chinese (Simplified))
weblate Sep 2, 2024
09358aa
Translated using Weblate (Chinese (Traditional))
weblate Sep 3, 2024
02c0453
Translated using Weblate (French)
weblate Sep 4, 2024
b06d670
Added translation using Weblate (Slovenian)
weblate Sep 5, 2024
4ef7529
Translated using Weblate (Slovenian)
weblate Sep 5, 2024
526799c
Added translation using Weblate (Catalan)
weblate Sep 5, 2024
c3628e3
Translated using Weblate (French)
weblate Sep 5, 2024
67c5006
fix: styles on home page (#193)
tonyaellie Sep 5, 2024
1e81b4b
feat: improve loading state for creation and fix types for adding ima…
tonyaellie Sep 5, 2024
0ab95fb
feat: compare filter values on a unique field instead of by reference…
tonyaellie Sep 5, 2024
7c855cf
fix: regional languages not matching correctly
tankerkiller125 Sep 5, 2024
0946310
Added translation using Weblate (Polish)
weblate Sep 5, 2024
80d5682
Translated using Weblate (German)
weblate Sep 5, 2024
d0b9f74
Translated using Weblate (Polish)
weblate Sep 5, 2024
c0e2aa5
Merge pull request #197
tonyaellie Sep 5, 2024
25c7652
Merge pull request #185
tonyaellie Sep 5, 2024
6b59838
Translated using Weblate (Polish)
weblate Sep 6, 2024
25d7204
Added translation using Weblate (Hungarian)
weblate Sep 6, 2024
15925de
feat: add eslint-plugin-tailwindcss (#199)
tonyaellie Sep 6, 2024
ffb538e
Translated using Weblate (Hungarian)
weblate Sep 7, 2024
a6aafeb
fix: compare all browser languages with available offerings.
tankerkiller125 Sep 7, 2024
ec9cdb3
Merge remote-tracking branch 'origin/main'
tankerkiller125 Sep 7, 2024
209bb29
refactor: cleaned up translation matching
tankerkiller125 Sep 7, 2024
42c01ad
feat: translate tools page
tankerkiller125 Sep 7, 2024
c428a22
docs: add screenshot of home screen
tankerkiller125 Sep 7, 2024
2fee607
feat: allow the hiding of the header (#202)
tankerkiller125 Sep 7, 2024
489deda
Update README.md
tankerkiller125 Sep 7, 2024
baf8912
Added translation using Weblate (Portuguese (Brazil))
weblate Sep 7, 2024
adb4b52
Fix Registration Disabled button in login page (#203)
edward-shen Sep 8, 2024
f113de1
docs: add demo link to doc site
tankerkiller125 Sep 8, 2024
cf2edc8
fix: Use region specific chinese (instead of simplified vs traditional)
tankerkiller125 Sep 8, 2024
b37cf24
feat: user selectable language
tankerkiller125 Sep 8, 2024
5de649d
feat: update PNPM dependencies
tankerkiller125 Sep 8, 2024
93f13b1
chore: update go dependencies
tankerkiller125 Sep 8, 2024
dafc6aa
update links (#206)
tonyaellie Sep 9, 2024
fb62f51
feat: refresh search on include archived change (#208)
tonyaellie Sep 9, 2024
b18f0c7
feat: make ItemViewTable headers customisable
tonyaellie Sep 9, 2024
19c6d4d
Translated using Weblate (Chinese (Simplified))
weblate Sep 10, 2024
9e3f82f
fix: action should run at midnight for nightly builds
tankerkiller125 Sep 10, 2024
784cc40
Translated using Weblate (German)
weblate Sep 11, 2024
073aade
feat: show item is archived in more places (#210)
tonyaellie Sep 11, 2024
404791a
Translated using Weblate (French)
weblate Sep 12, 2024
8ef1b8b
docs: add installation page
Gabrinator Sep 13, 2024
a6e4929
docs: update navigation
Gabrinator Sep 13, 2024
f8482b1
docs: fix typo in index.md
Gabrinator Sep 13, 2024
88dc943
docs: added Configure Homebox Page
Gabrinator Sep 13, 2024
5fc7b3e
docs: update quick-stard.md
Gabrinator Sep 13, 2024
6800c21
Merge pull request #221 from Gabrinator/update-docs
katosdev Sep 13, 2024
405d0c7
Merge pull request #212 from tonyaellie/make-ItemViewTable-headers-cu…
katosdev Sep 13, 2024
214b16a
chore: update go dependencies
tankerkiller125 Sep 14, 2024
4d93784
chore(oidc): generate migration
kloenk Aug 11, 2024
74172cc
chore(oidc): implement backend routes for one oidc provider named oidc
kloenk Aug 12, 2024
d03a3e1
feat(oidc): Add OIDC authentication framework
kloenk Aug 12, 2024
68bbddd
chore: update go dependencies
tankerkiller125 Sep 14, 2024
e1dd5ed
Merge remote-tracking branch 'kloenk/oidc' into fork/kloenk/oidc
tankerkiller125 Sep 14, 2024
62adbb0
fix: minor merge error
tankerkiller125 Sep 14, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish-rootless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Docker publish rootless

on:
schedule:
- cron: '00 6 * * *'
- cron: '00 0 * * *'
push:
branches: [ "main" ]
paths:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Docker publish

on:
schedule:
- cron: '00 6 * * *'
- cron: '00 0 * * *'
push:
branches: [ "main" ]
paths:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

<h1 align="center" style="margin-top: -10px"> HomeBox </h1>
<p align="center" style="width: 100;">
<a href="https://homebox.sysadminsmedia.com">Docs</a>
<a href="https://homebox.software/en/">Docs</a>
|
<a href="https://homebox.fly.dev">Demo</a>
<a href="https://demo.homebox.software">Demo</a>
|
<a href="https://discord.gg/aY4DCkpNA9">Discord</a>
</p>
Expand All @@ -24,7 +24,7 @@ Check out screenshots of the project [here](https://imgur.com/a/5gLWt2j).

## Quick Start

[Configuration & Docker Compose](https://homebox.sysadminsmedia.com/en/quick-start.html)
[Configuration & Docker Compose](https://homebox.software/en/quick-start.html)

```bash
# If using the rootless image, ensure data
Expand Down
39 changes: 39 additions & 0 deletions backend/app/api/providers/extractors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package providers

import (
"errors"
"github.com/sysadminsmedia/homebox/backend/internal/core/services"
"net/http"

"github.com/hay-kot/httpkit/server"
Expand Down Expand Up @@ -53,3 +54,41 @@ func getLoginForm(r *http.Request) (LoginForm, error) {

return loginForm, nil
}

func getOAuthForm(r *http.Request) (services.OAuthValidate, error) {
var oauthForm services.OAuthValidate
switch r.Header.Get("Content-Type") {
case "application/x-www-form-urlencoded":
err := r.ParseForm()
if err != nil {
return oauthForm, errors.New("failed to parse form")
}

oauthForm.Issuer = r.PostFormValue("issuer")
oauthForm.Code = r.PostFormValue("code")
oauthForm.State = r.PostFormValue("state")
case "application/json":
err := server.Decode(r, &oauthForm)
if err != nil {
log.Err(err).Msg("failed to decode OAuth form")
return oauthForm, err
}
default:
return oauthForm, errors.New("invalid content type")
}

if oauthForm.Issuer == "" || oauthForm.Code == "" {
return oauthForm, validate.NewFieldErrors(
validate.FieldError{
Field: "iss",
Error: "Issuer is empty",
},
validate.FieldError{
Field: "code",
Error: "Code is missing",
},
)
}

return oauthForm, nil
}
67 changes: 67 additions & 0 deletions backend/app/api/providers/oauth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package providers

import (
"context"
"errors"
"fmt"
"github.com/coreos/go-oidc/v3/oidc"
"github.com/rs/zerolog/log"
"github.com/sysadminsmedia/homebox/backend/internal/core/services"
"golang.org/x/oauth2"
"net/http"
"os"
"strings"
)

type OAuthProvider struct {
name string
service *services.OAuthService
config *services.OAuthConfig
}

func NewOAuthProvider(ctx context.Context, service *services.OAuthService, name string) (*OAuthProvider, error) {
upperName := strings.ToUpper(name)
clientId := os.Getenv(fmt.Sprintf("HBOX_OAUTH_%s_ID", upperName))
clientSecret := os.Getenv(fmt.Sprintf("HBOX_OAUTH_%s_SECRET", upperName))
redirectUri := os.Getenv(fmt.Sprintf("HBOX_OAUTH_%s_REDIRECT", upperName))

providerUrl := os.Getenv(fmt.Sprintf("HBOX_OAUTH_%s_URL", upperName))
// TODO: fallback for all variabnles if no well known is supported
if providerUrl == "" {
return nil, errors.New("Provider url not given")
}
provider, err := oidc.NewProvider(ctx, providerUrl)
if err != nil {
return nil, err
}
log.Debug().Str("AuthUrl", provider.Endpoint().AuthURL).Msg("discovered oauth provider")

return &OAuthProvider{
name: name,
service: service,
config: &services.OAuthConfig{
Config: &oauth2.Config{
ClientID: clientId,
ClientSecret: clientSecret,
Endpoint: provider.Endpoint(),
RedirectURL: redirectUri,
Scopes: []string{oidc.ScopeOpenID, "profile", "email"},
},
Provider: provider,
Verifier: provider.Verifier(&oidc.Config{ClientID: clientId}),
},
}, nil
}

func (p *OAuthProvider) Name() string {
return p.name
}

func (p *OAuthProvider) Authenticate(w http.ResponseWriter, r *http.Request) (services.UserAuthTokenDetail, error) {
oauthForm, err := getOAuthForm(r)
if err != nil {
return services.UserAuthTokenDetail{}, err
}

return p.service.Login(r.Context(), p.config, oauthForm)
}
13 changes: 11 additions & 2 deletions backend/app/api/routes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"embed"
"errors"
"fmt"
Expand All @@ -16,6 +17,7 @@ import (
"io"
"mime"
"net/http"
"os"
"path"
"path/filepath"
)
Expand Down Expand Up @@ -66,12 +68,19 @@ func (a *app) mountRoutes(r *chi.Mux, chain *errchain.ErrChain, repos *repo.AllR

r.Get("/currencies", chain.ToHandlerFunc(v1Ctrl.HandleCurrency()))

providers := []v1.AuthProvider{
providerList := []v1.AuthProvider{
providers.NewLocalProvider(a.services.User),
}
if _, exist := os.LookupEnv("HBOX_OAUTH_OIDC_URL"); exist {
provider, err := providers.NewOAuthProvider(context.Background(), a.services.OAuth, "oidc")
if err != nil {
panic(err)
}
providerList = append(providerList, provider)
}

r.Post("/users/register", chain.ToHandlerFunc(v1Ctrl.HandleUserRegistration()))
r.Post("/users/login", chain.ToHandlerFunc(v1Ctrl.HandleAuthLogin(providers...)))
r.Post("/users/login", chain.ToHandlerFunc(v1Ctrl.HandleAuthLogin(providerList...)))

userMW := []errchain.Middleware{
a.mwAuthToken,
Expand Down
78 changes: 40 additions & 38 deletions backend/go.mod
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
module github.com/sysadminsmedia/homebox/backend

go 1.22

toolchain go1.22.0
go 1.23.0

require (
ariga.io/atlas v0.19.1
entgo.io/ent v0.12.5
github.com/ardanlabs/conf/v3 v3.1.7
ariga.io/atlas v0.27.0
entgo.io/ent v0.14.1
github.com/ardanlabs/conf/v3 v3.1.8
github.com/containrrr/shoutrrr v0.8.0
github.com/go-chi/chi/v5 v5.0.12
github.com/go-playground/validator/v10 v10.18.0
github.com/gocarina/gocsv v0.0.0-20231116093920-b87c2d0e983a
github.com/coreos/go-oidc/v3 v3.11.0
github.com/go-chi/chi/v5 v5.1.0
github.com/go-playground/validator/v10 v10.22.1
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/google/uuid v1.6.0
github.com/gorilla/schema v1.4.1
github.com/hay-kot/httpkit v0.0.9
github.com/mattn/go-sqlite3 v1.14.22
github.com/olahol/melody v1.1.4
github.com/hay-kot/httpkit v0.0.11
github.com/mattn/go-sqlite3 v1.14.23
github.com/olahol/melody v1.2.1
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.32.0
github.com/stretchr/testify v1.8.4
github.com/rs/zerolog v1.33.0
github.com/stretchr/testify v1.9.0
github.com/swaggo/http-swagger/v2 v2.0.2
github.com/swaggo/swag v1.16.3
github.com/yeqown/go-qrcode/v2 v2.2.2
github.com/yeqown/go-qrcode/writer/standard v1.2.2
golang.org/x/crypto v0.23.0
modernc.org/sqlite v1.29.2
github.com/yeqown/go-qrcode/v2 v2.2.4
github.com/yeqown/go-qrcode/writer/standard v1.2.4
golang.org/x/crypto v0.27.0
golang.org/x/oauth2 v0.23.0
modernc.org/sqlite v1.33.1
)

require (
Expand All @@ -34,21 +34,22 @@ require (
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fogleman/gg v1.3.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-openapi/inflect v0.19.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
github.com/go-openapi/inflect v0.21.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl/v2 v2.19.1 // indirect
github.com/hashicorp/hcl/v2 v2.22.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -59,20 +60,21 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/swaggo/files/v2 v2.0.0 // indirect
github.com/swaggo/files/v2 v2.0.1 // indirect
github.com/yeqown/reedsolomon v1.0.0 // indirect
github.com/zclconf/go-cty v1.14.1 // indirect
golang.org/x/image v0.18.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
github.com/zclconf/go-cty v1.15.0 // indirect
golang.org/x/image v0.20.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/tools v0.25.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
modernc.org/libc v1.41.0 // indirect
modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a // indirect
modernc.org/libc v1.60.1 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // indirect
)
Loading