Skip to content

Commit

Permalink
fix: Fail safe, if optional endpoints are not given (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Apr 9, 2024
1 parent 8a21d38 commit 06f37f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
23 changes: 19 additions & 4 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"time"

jose "github.com/go-jose/go-jose/v3"
"github.com/go-jose/go-jose/v3"
"github.com/zitadel/logging"
"github.com/zitadel/oidc/v3/pkg/crypto"
httphelper "github.com/zitadel/oidc/v3/pkg/http"
Expand Down Expand Up @@ -97,7 +97,12 @@ func CallEndSessionEndpoint(ctx context.Context, request any, authFn any, caller
ctx, span := Tracer.Start(ctx, "CallEndSessionEndpoint")
defer span.End()

req, err := httphelper.FormRequest(ctx, caller.GetEndSessionEndpoint(), request, Encoder, authFn)
endpoint := caller.GetEndSessionEndpoint()
if endpoint == "" {
return nil, fmt.Errorf("end session %w", ErrEndpointNotSet)
}

req, err := httphelper.FormRequest(ctx, endpoint, request, Encoder, authFn)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -143,7 +148,12 @@ func CallRevokeEndpoint(ctx context.Context, request any, authFn any, caller Rev
ctx, span := Tracer.Start(ctx, "CallRevokeEndpoint")
defer span.End()

req, err := httphelper.FormRequest(ctx, caller.GetRevokeEndpoint(), request, Encoder, authFn)
endpoint := caller.GetRevokeEndpoint()
if endpoint == "" {
return fmt.Errorf("revoke %w", ErrEndpointNotSet)
}

req, err := httphelper.FormRequest(ctx, endpoint, request, Encoder, authFn)
if err != nil {
return err
}
Expand Down Expand Up @@ -218,7 +228,12 @@ func CallDeviceAuthorizationEndpoint(ctx context.Context, request *oidc.ClientCr
ctx, span := Tracer.Start(ctx, "CallDeviceAuthorizationEndpoint")
defer span.End()

req, err := httphelper.FormRequest(ctx, caller.GetDeviceAuthorizationEndpoint(), request, Encoder, authFn)
endpoint := caller.GetDeviceAuthorizationEndpoint()
if endpoint == "" {
return nil, fmt.Errorf("device authorization %w", ErrEndpointNotSet)
}

req, err := httphelper.FormRequest(ctx, endpoint, request, Encoder, authFn)
if err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/client/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package client

import "errors"

var ErrEndpointNotSet = errors.New("endpoint not set")

0 comments on commit 06f37f8

Please sign in to comment.