debugging for analyzing token

This commit is contained in:
Wolfgang Hottgenroth 2023-11-06 18:15:03 +01:00
parent c4317b7503
commit 5828a9a5a2
Signed by: wn
GPG Key ID: 836E9E1192A6B132
6 changed files with 23 additions and 5 deletions

View File

@ -25,6 +25,7 @@ func main() {
http.HandleFunc("/", server.RootHandler)
// Start
log.Info("wn test01 variant")
log.WithField("config", config).Debug("Starting with config")
log.Infof("Listening on :%d", config.Port)
log.Info(http.ListenAndServe(fmt.Sprintf(":%d", config.Port), nil))

View File

@ -326,7 +326,7 @@ func (c *Config) setupProvider(name string) error {
}
// Setup
err = p.Setup()
err = p.Setup(log)
if err != nil {
return err
}

View File

@ -8,6 +8,8 @@ import (
"net/http"
"golang.org/x/oauth2"
"github.com/sirupsen/logrus"
)
// GenericOAuth provider
@ -29,7 +31,7 @@ func (o *GenericOAuth) Name() string {
}
// Setup performs validation and setup
func (o *GenericOAuth) Setup() error {
func (o *GenericOAuth) Setup(log *logrus.Logger) error {
// Check parmas
if o.AuthURL == "" || o.TokenURL == "" || o.UserURL == "" || o.ClientID == "" || o.ClientSecret == "" {
return errors.New("providers.generic-oauth.auth-url, providers.generic-oauth.token-url, providers.generic-oauth.user-url, providers.generic-oauth.client-id, providers.generic-oauth.client-secret must be set")

View File

@ -6,6 +6,8 @@ import (
"fmt"
"net/http"
"net/url"
"github.com/sirupsen/logrus"
)
// Google provider
@ -26,7 +28,7 @@ func (g *Google) Name() string {
}
// Setup performs validation and setup
func (g *Google) Setup() error {
func (g *Google) Setup(log *logrus.Logger) error {
if g.ClientID == "" || g.ClientSecret == "" {
return errors.New("providers.google.client-id, providers.google.client-secret must be set")
}

View File

@ -6,6 +6,8 @@ import (
"github.com/coreos/go-oidc"
"golang.org/x/oauth2"
"github.com/sirupsen/logrus"
)
// OIDC provider
@ -18,6 +20,8 @@ type OIDC struct {
provider *oidc.Provider
verifier *oidc.IDTokenVerifier
log *logrus.Logger
}
// Name returns the name of the provider
@ -26,7 +30,9 @@ func (o *OIDC) Name() string {
}
// Setup performs validation and setup
func (o *OIDC) Setup() error {
func (o *OIDC) Setup(log *logrus.Logger) error {
o.log = log
// Check parms
if o.IssuerURL == "" || o.ClientID == "" || o.ClientSecret == "" {
return errors.New("providers.oidc.issuer-url, providers.oidc.client-id, providers.oidc.client-secret must be set")
@ -70,6 +76,7 @@ func (o *OIDC) ExchangeCode(redirectURI, code string) (string, error) {
if err != nil {
return "", err
}
o.log.WithField("accessToken", token.AccessToken).Debug("getUser")
// Extract ID token
rawIDToken, ok := token.Extra("id_token").(string)
@ -90,10 +97,15 @@ func (o *OIDC) GetUser(token string) (User, error) {
return user, err
}
o.log.WithField("idToken", idToken).Debug("getUser")
// Extract custom claims
if err := idToken.Claims(&user); err != nil {
return user, err
}
o.log.WithField("user", user).Debug("getUser")
return user, nil
}

View File

@ -5,6 +5,7 @@ import (
// "net/url"
"golang.org/x/oauth2"
"github.com/sirupsen/logrus"
)
// Providers contains all the implemented providers
@ -20,7 +21,7 @@ type Provider interface {
GetLoginURL(redirectURI, state string) string
ExchangeCode(redirectURI, code string) (string, error)
GetUser(token string) (User, error)
Setup() error
Setup(*logrus.Logger) error
}
type token struct {