Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopeocchi committed Jul 23, 2024
1 parent ed437ec commit 31e3cfa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
32 changes: 32 additions & 0 deletions server/openid/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package openid

import (
"context"

"github.com/coreos/go-oidc"
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
"golang.org/x/oauth2"
)

func Configure() {
if !config.Instance().UseOpenId {
return
}

provider, err := oidc.NewProvider(context.Background(), config.Instance().OpenIdProviderURL)
if err != nil {
panic(err)
}

oauth2Config = oauth2.Config{
ClientID: config.Instance().OpenIdClientId,
ClientSecret: config.Instance().OpenIdClientSecret,
RedirectURL: config.Instance().OpenIdRedirectURL,
Endpoint: provider.Endpoint(),
Scopes: []string{oidc.ScopeOpenID, "profile", "email"},
}

verifier = provider.Verifier(&oidc.Config{
ClientID: config.Instance().OpenIdClientId,
})
}
25 changes: 0 additions & 25 deletions server/openid/handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package openid

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -10,7 +9,6 @@ import (

"github.com/coreos/go-oidc"
"github.com/google/uuid"
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
"golang.org/x/oauth2"
)

Expand All @@ -25,29 +23,6 @@ var (
verifier *oidc.IDTokenVerifier
)

func Configure() {
if !config.Instance().UseOpenId {
return
}

provider, err := oidc.NewProvider(context.Background(), config.Instance().OpenIdProviderURL)
if err != nil {
panic(err)
}

oauth2Config = oauth2.Config{
ClientID: config.Instance().OpenIdClientId,
ClientSecret: config.Instance().OpenIdClientSecret,
RedirectURL: config.Instance().OpenIdRedirectURL,
Endpoint: provider.Endpoint(),
Scopes: []string{oidc.ScopeOpenID, "profile", "email"},
}

verifier = provider.Verifier(&oidc.Config{
ClientID: config.Instance().OpenIdClientId,
})
}

func Login(w http.ResponseWriter, r *http.Request) {
var (
state = uuid.NewString()
Expand Down

0 comments on commit 31e3cfa

Please sign in to comment.