-
-
Notifications
You must be signed in to change notification settings - Fork 251
OIDC #168
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
Draft
kloenk
wants to merge
15
commits into
sysadminsmedia:main
Choose a base branch
from
kloenk:oidc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
OIDC #168
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ea7bc41
chore(oidc): generate migration
kloenk 2d2a6b8
chore(oidc): implement backend routes for one oidc provider named oidc
kloenk 4cb4d20
feat(oidc): Add OIDC authentication framework
kloenk 4d93784
chore(oidc): generate migration
kloenk 74172cc
chore(oidc): implement backend routes for one oidc provider named oidc
kloenk d03a3e1
feat(oidc): Add OIDC authentication framework
kloenk 68bbddd
chore: update go dependencies
tankerkiller125 e1dd5ed
Merge remote-tracking branch 'kloenk/oidc' into fork/kloenk/oidc
tankerkiller125 62adbb0
fix: minor merge error
tankerkiller125 34e7f0a
Merge branch 'main' into oidc
tankerkiller125 7ebcfc6
fix: Merge issues
tankerkiller125 e8f4667
fix: Use proper configuration options
tankerkiller125 e261987
Merge remote-tracking branch 'origin/main' into oidc
tankerkiller125 734be53
Some actual merge fixes
tankerkiller125 21f18fe
Fix SQL migrations
tankerkiller125 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,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) | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should use the config system that is already implemented in Homebox.
See backend/internal/sys/config/conf.go
It makes use of a nice library: https://pkg.go.dev/github.com/ardanlabs/conf/v3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have already been corrected (which is why the review thing says "Outdated")