code refactoring
This commit is contained in:
32
server/openid/config.go
Normal file
32
server/openid/config.go
Normal file
@@ -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,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package openid
|
package openid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -10,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"github.com/coreos/go-oidc"
|
"github.com/coreos/go-oidc"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,29 +23,6 @@ var (
|
|||||||
verifier *oidc.IDTokenVerifier
|
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) {
|
func Login(w http.ResponseWriter, r *http.Request) {
|
||||||
var (
|
var (
|
||||||
state = uuid.NewString()
|
state = uuid.NewString()
|
||||||
|
|||||||
Reference in New Issue
Block a user