Skip to content

Commit

Permalink
Remove wrong code
Browse files Browse the repository at this point in the history
  • Loading branch information
tknie committed Nov 4, 2024
1 parent 5b35e84 commit a427a3c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
5 changes: 0 additions & 5 deletions auth/basicauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ func BasicAuth(user string, pass string) (PrincipalInterface, error) {
return nil, err
}
evaluateRoles(principal)
_, err = GenerateJWToken(principal)
if err != nil {
log.Log.Errorf("Basic auth error... %v", err)
return nil, err
}
if log.IsDebugLevel() {
log.Log.Debugf("Create principal: %p", principal.Name)
}
Expand Down
4 changes: 2 additions & 2 deletions auth/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (webToken *WebToken) GenerateJWToken(IAt string, principal PrincipalInterfa
return "", fmt.Errorf("web token not configured properly")
}
if webToken.OAuth2 {
return webToken.GenerateOIDCToken(IAt, principal)
return webToken.generateOIDCToken(IAt, principal)
}
token, err := generateCallbackToken(IAt, principal)
if err == nil {
Expand Down Expand Up @@ -373,7 +373,7 @@ func (webToken *WebToken) JWTContainsRoles(token string, scopes []string) (Princ
log.Log.Debugf("Has role scopes %#v", scopes)
}
if webToken.OAuth2 {
return webToken.OIDCContainsRoles(token, scopes)
return webToken.checkOIDCContainsRoles(token, scopes)
}
if webToken.PassToken != "" && token == webToken.PassToken {
si := &SessionInfo{UUID: webToken.PassToken}
Expand Down
8 changes: 5 additions & 3 deletions auth/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
var oauth2Config *oauth2.Config
var provider *oidc.Provider

// InitOIDC initialize basic parameters for OIDCS authentication
func InitOIDC(auth *AuthenticationServer) error {
if auth == nil {
return errors.New("no OIDC client config given")
Expand Down Expand Up @@ -72,16 +73,17 @@ func (webToken *WebToken) InitWebTokenOIDC() error {
return nil
}

// GenerateJWToken generate JWT token using golang Jose.v2
func (webToken *WebToken) GenerateOIDCToken(IAt string, principal PrincipalInterface) (tokenString string, err error) {
// generateOIDCToken generate OIDC token using OAuth2 web instance
func (webToken *WebToken) generateOIDCToken(IAt string, principal PrincipalInterface) (tokenString string, err error) {
token, ok := principal.Session().(oauth2.Token)
if !ok {
return "", errors.New("token generate OIDC mismatch")
}
return token.AccessToken, nil
}

func (webToken *WebToken) OIDCContainsRoles(token string, scopes []string) (PrincipalInterface, error) {
// checkOIDCContainsRoles OIDCS check for roles
func (webToken *WebToken) checkOIDCContainsRoles(token string, scopes []string) (PrincipalInterface, error) {
verifier := provider.Verifier(&oidc.Config{ClientID: oauth2Config.ClientID})

// Parse and verify ID Token payload.
Expand Down

0 comments on commit a427a3c

Please sign in to comment.