Skip to content

Commit

Permalink
feat: adding entraid login
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Sep 6, 2024
1 parent b913ce2 commit 5d095fa
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
GITHUB_KEY=
GITHUB_SECRET=
SERVICE_LENS_ENTRAID_CLIENT_ID=
SERVICE_LENS_ENTRAID_CLIENT_SECRET=
SERVICE_LENS_ENTRAID_TENANT_ID=
SERVICE_LENS_ENTRAID_CALLBACK_URL=
SERVICE_LENS_ADDR=
POSTGRES_URL=
SERVICE_LENS_DATABASE_TABLE_PREFIX=
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/kelseyhightower/envconfig"
"github.com/zeiss/fiber-goth/adapters"
"github.com/zeiss/fiber-goth/providers"
"github.com/zeiss/fiber-goth/providers/entraid"
"github.com/zeiss/fiber-goth/providers/github"
reload "github.com/zeiss/fiber-reload"
seed "github.com/zeiss/gorm-seed"
Expand Down Expand Up @@ -86,6 +87,7 @@ func NewWebSrv(cfg *cfg.Config) *WebSrv {
func (s *WebSrv) Start(ctx context.Context, ready server.ReadyFunc, run server.RunFunc) func() error {
return func() error {
providers.RegisterProvider(github.New(s.cfg.Flags.GitHubClientID, s.cfg.Flags.GitHubClientSecret, s.cfg.Flags.GitHubCallbackURL))
providers.RegisterProvider(entraid.New(s.cfg.Flags.EntraIDClientID, s.cfg.Flags.EntraIDClientSecret, s.cfg.Flags.EntraIDCallbackURL, entraid.TenantType(s.cfg.Flags.EntraIDTenantID)))

conn, err := gorm.Open(postgres.Open(config.Flags.DatabaseURI), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
Expand Down
11 changes: 8 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ require (
github.com/yuin/goldmark v1.7.4
github.com/yuin/goldmark-emoji v1.0.3
github.com/zeiss/fiber-authz v1.0.33
github.com/zeiss/fiber-goth v1.2.11
github.com/zeiss/fiber-goth v1.2.12
github.com/zeiss/fiber-htmx v1.3.24-0.20240904185607-c49c36d17bba
github.com/zeiss/fiber-reload v0.1.0
github.com/zeiss/gorm-seed v0.1.2
github.com/zeiss/pkg v0.1.8-0.20240823051228-d40ebe6703e0
github.com/zeiss/pkg v0.1.8-0.20240906201119-75c76d920f4f
go.abhg.dev/goldmark/mermaid v0.5.0
golang.org/x/mod v0.21.0
gorm.io/driver/postgres v1.5.9
Expand Down Expand Up @@ -84,6 +84,8 @@ require (
github.com/ghodss/yaml v1.0.0 // indirect
github.com/ghostiam/protogetter v0.3.6 // indirect
github.com/go-critic/go-critic v0.11.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
Expand Down Expand Up @@ -172,7 +174,7 @@ require (
github.com/nunnatsa/ginkgolinter v0.16.2 // indirect
github.com/oapi-codegen/fiber-middleware v1.0.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/openfga/go-sdk v0.5.0 // indirect
github.com/openfga/go-sdk v0.6.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down Expand Up @@ -231,6 +233,9 @@ require (
gitlab.com/bosi/decorder v0.4.2 // indirect
go-simpler.org/musttag v0.12.2 // indirect
go-simpler.org/sloglint v0.7.2 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
Expand Down
23 changes: 15 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ github.com/ghostiam/protogetter v0.3.6 h1:R7qEWaSgFCsy20yYHNIJsU9ZOb8TziSRRxuAOT
github.com/ghostiam/protogetter v0.3.6/go.mod h1:7lpeDnEJ1ZjL/YtyoN99ljO4z0pd3H0d18/t2dPBxHw=
github.com/go-critic/go-critic v0.11.4 h1:O7kGOCx0NDIni4czrkRIXTnit0mkyKOCePh3My6OyEU=
github.com/go-critic/go-critic v0.11.4/go.mod h1:2QAdo4iuLik5S9YG0rT4wcZ8QxwHYkrr6/2MWAiv/vc=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
Expand Down Expand Up @@ -360,8 +363,8 @@ github.com/onsi/ginkgo/v2 v2.20.0 h1:PE84V2mHqoT1sglvHc8ZdQtPcwmvvt29WLEEO3xmdZw
github.com/onsi/ginkgo/v2 v2.20.0/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/openfga/go-sdk v0.5.0 h1:1IuAu6Xf4eBxgc2AyMfosK7QzApxuZ5yi7jmFaftnl0=
github.com/openfga/go-sdk v0.5.0/go.mod h1:AoMnFlPw65sU/7O4xOPpCb2vXA8ZD9K9xp2hZjcvt4g=
github.com/openfga/go-sdk v0.6.0 h1:AzfIByBk2niW5gbN5fm9A8WnDz/vW8wT1Zv4cZwWbww=
github.com/openfga/go-sdk v0.6.0/go.mod h1:L4ss/4HEMmehyV2WIuBEPMdeh686MqIEJcnoUk3Lhd8=
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
Expand Down Expand Up @@ -524,18 +527,16 @@ github.com/yuin/goldmark-emoji v1.0.3 h1:aLRkLHOuBR2czCY4R8olwMjID+tENfhyFDMCRhb
github.com/yuin/goldmark-emoji v1.0.3/go.mod h1:tTkZEbwu5wkPmgTcitqddVxY9osFZiavD+r4AzQrh1U=
github.com/zeiss/fiber-authz v1.0.33 h1:KZnVTxG+VoQLowoCqoMwam/5H4PVu89rn9ZJ2AGOtCE=
github.com/zeiss/fiber-authz v1.0.33/go.mod h1:oVkhY0X9/xFa0Pu3BuEU8ubE7pAQmIjFMUwUGD2pQqc=
github.com/zeiss/fiber-goth v1.2.11 h1:24EiIKF1iPrmlspbW/BylcqVyj4Ltwzmx9DM7pRs6R4=
github.com/zeiss/fiber-goth v1.2.11/go.mod h1:9NuXxIeKZgmk3dfl7HWbZK/eAfukvjMCHHacGo0m84Y=
github.com/zeiss/fiber-htmx v1.3.24-0.20240830194917-8ae3f011df63 h1:407mho6pz8SOH7SZE1Gx5TqBTdQOAIrrzI7/1pSrZY0=
github.com/zeiss/fiber-htmx v1.3.24-0.20240830194917-8ae3f011df63/go.mod h1:uRVFTXMn4/nvTeU6eYX+FiEEAsHzAovQeql0HHPC4qQ=
github.com/zeiss/fiber-goth v1.2.12 h1:Wr1VSqEfBY0GSuG/2pIclSKo0fGTT/uPZvF2rJxYdwk=
github.com/zeiss/fiber-goth v1.2.12/go.mod h1:GhiYbTqTIQK1D5Jntav6/WlJDqW4t3wvNZUEofjUeBQ=
github.com/zeiss/fiber-htmx v1.3.24-0.20240904185607-c49c36d17bba h1:T5bjioLlW0H9s981UaHaWtjr0ex0ZGunojhFvTJf+oI=
github.com/zeiss/fiber-htmx v1.3.24-0.20240904185607-c49c36d17bba/go.mod h1:uRVFTXMn4/nvTeU6eYX+FiEEAsHzAovQeql0HHPC4qQ=
github.com/zeiss/fiber-reload v0.1.0 h1:iiZzbHj2EntILhbF74HRZPDSLrvURmwTbUqGlKfo0h4=
github.com/zeiss/fiber-reload v0.1.0/go.mod h1:eUvohuk2nDjGCUtejTW5db5M28FZNJDtVEAZDZwq0Rg=
github.com/zeiss/gorm-seed v0.1.2 h1:XksLz/IXC1ejUgbl5dHC2/vQAqD2LNZMhZMz2w+E7fY=
github.com/zeiss/gorm-seed v0.1.2/go.mod h1:Tli6ekFpRjtQY8S6VoNiLgRnX1DVEvHJkf+UI85kV+E=
github.com/zeiss/pkg v0.1.8-0.20240823051228-d40ebe6703e0 h1:XeYJSeE7wHJ5JtnZZR2UD4Cf5HQljUuM2Bb5RloQQMs=
github.com/zeiss/pkg v0.1.8-0.20240823051228-d40ebe6703e0/go.mod h1:+oCr9cBeG3Eq37zzzPET8z2REQoA5C29+agQfLX5KZk=
github.com/zeiss/pkg v0.1.8-0.20240906201119-75c76d920f4f h1:yPGs8YwIYC/2qS9cOHmwo1uMOZQfC2XgJu98demSY4E=
github.com/zeiss/pkg v0.1.8-0.20240906201119-75c76d920f4f/go.mod h1:QVWTdonZRsTedmLwUg1YTJj66aBexDP2SA6ZxyfxSmg=
gitlab.com/bosi/decorder v0.4.2 h1:qbQaV3zgwnBZ4zPMhGLW4KZe7A7NwxEhJx39R3shffo=
gitlab.com/bosi/decorder v0.4.2/go.mod h1:muuhHoaJkA9QLcYHq4Mj8FJUwDZ+EirSHRiaTcTf6T8=
go-simpler.org/assert v0.9.0 h1:PfpmcSvL7yAnWyChSjOz6Sp6m9j5lyK8Ok9pEL31YkQ=
Expand All @@ -546,6 +547,12 @@ go-simpler.org/sloglint v0.7.2 h1:Wc9Em/Zeuu7JYpl+oKoYOsQSy2X560aVueCW/m6IijY=
go-simpler.org/sloglint v0.7.2/go.mod h1:US+9C80ppl7VsThQclkM7BkCHQAzuz8kHLsW3ppuluo=
go.abhg.dev/goldmark/mermaid v0.5.0 h1:mDkykpSPJ+5wCQ8bSXgzJ2KQskjXkI5Ndxz7JYDHW38=
go.abhg.dev/goldmark/mermaid v0.5.0/go.mod h1:OCyk2o85TX2drWHH+HRy6bih2yZlUwbbv/R1MMh1YLs=
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
go.uber.org/automaxprocs v1.5.3 h1:kWazyxZUrS3Gs4qUpbwo5kEIMGe/DAvi5Z4tl2NW4j8=
go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
Expand Down
4 changes: 4 additions & 0 deletions internal/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ type Flags struct {
GitHubCallbackURL string `envconfig:"SERVICE_LENS_GITHUB_CALLBACK_URL" default:""`
GitHubClientID string `envconfig:"SERVICE_LENS_GITHUB_CLIENT_ID" default:""`
GitHubClientSecret string `envconfig:"SERVICE_LENS_GITHUB_CLIENT_SECRET" default:""`
EntraIDClientID string `envconfig:"SERVICE_LENS_ENTRAID_CLIENT_ID" default:""`
EntraIDClientSecret string `envconfig:"SERVICE_LENS_ENTRAID_CLIENT_SECRET" default:""`
EntraIDCallbackURL string `envconfig:"SERVICE_LENS_ENTRAID_CALLBACK_URL" default:""`
EntraIDTenantID string `envconfig:"SERVICE_LENS_ENTRAID_TENANT_ID" default:""`
}

// NewFlags returns a new instance of Flags.
Expand Down
16 changes: 16 additions & 0 deletions internal/controllers/login/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ func (l *IndexLoginController) Get() error {
cards.TitleProps{},
htmx.Text("Sign in to your account"),
),
htmx.Div(
htmx.ClassNames{
"mt-4": true,
},
links.Button(
links.LinkProps{
ClassNames: htmx.ClassNames{
"w-full": true,
"btn-primary": true,
"btn-outline": true,
},
Href: "/login/entraid",
},
htmx.Text("Login on Microsoft Entra ID"),
),
),
htmx.Div(
htmx.ClassNames{
"mt-4": true,
Expand Down

0 comments on commit 5d095fa

Please sign in to comment.