Skip to content

Commit

Permalink
Reuse existing extractIssuerURL function
Browse files Browse the repository at this point in the history
Signed-off-by: Priya Wadhwa <priya@chainguard.dev>
  • Loading branch information
priyawadhwa committed Mar 1, 2023
1 parent 36ed587 commit 5dcf8b6
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions pkg/identity/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,17 @@ package identity

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"strings"

"github.com/coreos/go-oidc/v3/oidc"
"github.com/sigstore/fulcio/pkg/config"
)

func extractIssuer(token string) (string, error) {
parts := strings.Split(token, ".")
if len(parts) != 3 {
return "", fmt.Errorf("oidc: malformed jwt, expected 3 parts got %d", len(parts))
}
raw, err := base64.RawURLEncoding.DecodeString(parts[1])
if err != nil {
return "", fmt.Errorf("oidc: malformed jwt payload: %w", err)
}
var payload struct {
Issuer string `json:"iss"`
}

if err := json.Unmarshal(raw, &payload); err != nil {
return "", fmt.Errorf("oidc: failed to unmarshal claims: %w", err)
}
return payload.Issuer, nil
}

// We do this to bypass needing actual OIDC tokens for unit testing.
var Authorize = actualAuthorize

func actualAuthorize(ctx context.Context, token string) (*oidc.IDToken, error) {
issuer, err := extractIssuer(token)
issuer, err := extractIssuerURL(token)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5dcf8b6

Please sign in to comment.