Skip to content

Commit

Permalink
fix: fix problem with domain/issuer
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuasing committed Jan 2, 2023
1 parent 9de0a08 commit a7246f8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ package auth

import (
"context"
"fmt"
"log"
"net/http"
"net/url"
"strings"

"github.com/coreos/go-oidc/v3/oidc"
Expand All @@ -43,7 +43,7 @@ type Claims struct {
CommonName string `json:"common_name"`
}

const certificatesPath = "%scdn-cgi/access/certs"
const certificatesPath = "/cdn-cgi/access/certs"

var (
config *Config
Expand All @@ -53,11 +53,13 @@ var (
type RouteHandler = func(w http.ResponseWriter, req *http.Request, aud string)

func Route(conf *Config) RouteHandler {
if !strings.HasSuffix(conf.Domain, "/") {
conf.Domain = conf.Domain + "/"
}
conf.Domain = strings.TrimSuffix(conf.Domain, "/")
config = conf
remoteKeySet = oidc.NewRemoteKeySet(context.TODO(), fmt.Sprintf(certificatesPath, conf.Domain))
jwksURL, err := url.JoinPath(conf.Domain, certificatesPath)
if err != nil {
log.Fatalf("failed to join domain and certificates path: %v", err)
}
remoteKeySet = oidc.NewRemoteKeySet(context.TODO(), jwksURL)

return func(w http.ResponseWriter, req *http.Request, aud string) {
token := req.Header.Get("Cf-Access-Jwt-Assertion")
Expand Down

0 comments on commit a7246f8

Please sign in to comment.