Merge branch 'main' into perf-introspection
This commit is contained in:
commit
c6b5544516
5 changed files with 129 additions and 51 deletions
8
go.mod
8
go.mod
|
@ -17,8 +17,8 @@ require (
|
||||||
github.com/stretchr/testify v1.8.4
|
github.com/stretchr/testify v1.8.4
|
||||||
github.com/zitadel/logging v0.5.0
|
github.com/zitadel/logging v0.5.0
|
||||||
github.com/zitadel/schema v1.3.0
|
github.com/zitadel/schema v1.3.0
|
||||||
go.opentelemetry.io/otel v1.19.0
|
go.opentelemetry.io/otel v1.20.0
|
||||||
go.opentelemetry.io/otel/trace v1.19.0
|
go.opentelemetry.io/otel/trace v1.20.0
|
||||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
|
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
|
||||||
golang.org/x/oauth2 v0.14.0
|
golang.org/x/oauth2 v0.14.0
|
||||||
golang.org/x/text v0.14.0
|
golang.org/x/text v0.14.0
|
||||||
|
@ -26,12 +26,12 @@ require (
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/go-logr/logr v1.2.4 // indirect
|
github.com/go-logr/logr v1.3.0 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/golang/protobuf v1.5.3 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
github.com/google/go-querystring v1.1.0 // indirect
|
github.com/google/go-querystring v1.1.0 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
go.opentelemetry.io/otel/metric v1.19.0 // indirect
|
go.opentelemetry.io/otel/metric v1.20.0 // indirect
|
||||||
golang.org/x/crypto v0.15.0 // indirect
|
golang.org/x/crypto v0.15.0 // indirect
|
||||||
golang.org/x/net v0.18.0 // indirect
|
golang.org/x/net v0.18.0 // indirect
|
||||||
golang.org/x/sys v0.14.0 // indirect
|
golang.org/x/sys v0.14.0 // indirect
|
||||||
|
|
18
go.sum
18
go.sum
|
@ -6,8 +6,8 @@ github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNIT
|
||||||
github.com/go-jose/go-jose/v3 v3.0.1 h1:pWmKFVtt+Jl0vBZTIpz/eAKwsm6LkIxDVVbFHKkchhA=
|
github.com/go-jose/go-jose/v3 v3.0.1 h1:pWmKFVtt+Jl0vBZTIpz/eAKwsm6LkIxDVVbFHKkchhA=
|
||||||
github.com/go-jose/go-jose/v3 v3.0.1/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8=
|
github.com/go-jose/go-jose/v3 v3.0.1/go.mod h1:RNkWWRld676jZEYoV3+XK8L2ZnNSvIsxFMht0mSX+u8=
|
||||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
|
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
|
||||||
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||||
|
@ -20,7 +20,7 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu
|
||||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
github.com/google/go-github/v31 v31.0.0 h1:JJUxlP9lFK+ziXKimTCprajMApV1ecWD4NB6CCb0plo=
|
github.com/google/go-github/v31 v31.0.0 h1:JJUxlP9lFK+ziXKimTCprajMApV1ecWD4NB6CCb0plo=
|
||||||
github.com/google/go-github/v31 v31.0.0/go.mod h1:NQPZol8/1sMoWYGN2yaALIBytu17gAWfhbweiEed3pM=
|
github.com/google/go-github/v31 v31.0.0/go.mod h1:NQPZol8/1sMoWYGN2yaALIBytu17gAWfhbweiEed3pM=
|
||||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||||
|
@ -55,12 +55,12 @@ github.com/zitadel/logging v0.5.0 h1:Kunouvqse/efXy4UDvFw5s3vP+Z4AlHo3y8wF7stXHA
|
||||||
github.com/zitadel/logging v0.5.0/go.mod h1:IzP5fzwFhzzyxHkSmfF8dsyqFsQRJLLcQmwhIBzlGsE=
|
github.com/zitadel/logging v0.5.0/go.mod h1:IzP5fzwFhzzyxHkSmfF8dsyqFsQRJLLcQmwhIBzlGsE=
|
||||||
github.com/zitadel/schema v1.3.0 h1:kQ9W9tvIwZICCKWcMvCEweXET1OcOyGEuFbHs4o5kg0=
|
github.com/zitadel/schema v1.3.0 h1:kQ9W9tvIwZICCKWcMvCEweXET1OcOyGEuFbHs4o5kg0=
|
||||||
github.com/zitadel/schema v1.3.0/go.mod h1:NptN6mkBDFvERUCvZHlvWmmME+gmZ44xzwRXwhzsbtc=
|
github.com/zitadel/schema v1.3.0/go.mod h1:NptN6mkBDFvERUCvZHlvWmmME+gmZ44xzwRXwhzsbtc=
|
||||||
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=
|
go.opentelemetry.io/otel v1.20.0 h1:vsb/ggIY+hUjD/zCAQHpzTmndPqv/ml2ArbsbfBYTAc=
|
||||||
go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY=
|
go.opentelemetry.io/otel v1.20.0/go.mod h1:oUIGj3D77RwJdM6PPZImDpSZGDvkD9fhesHny69JFrs=
|
||||||
go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE=
|
go.opentelemetry.io/otel/metric v1.20.0 h1:ZlrO8Hu9+GAhnepmRGhSU7/VkpjrNowxRN9GyKR4wzA=
|
||||||
go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8=
|
go.opentelemetry.io/otel/metric v1.20.0/go.mod h1:90DRw3nfK4D7Sm/75yQ00gTJxtkBxX+wu6YaNymbpVM=
|
||||||
go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg=
|
go.opentelemetry.io/otel/trace v1.20.0 h1:+yxVAPZPbQhbC3OfAkeIVTky6iTFpcr4SiY9om7mXSQ=
|
||||||
go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo=
|
go.opentelemetry.io/otel/trace v1.20.0/go.mod h1:HJSK7F/hA5RlzpZ0zKDCHCDHm556LCDtKaAo6JmBFUU=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
|
|
@ -54,7 +54,24 @@ type Configuration interface {
|
||||||
type IssuerFromRequest func(r *http.Request) string
|
type IssuerFromRequest func(r *http.Request) string
|
||||||
|
|
||||||
func IssuerFromHost(path string) func(bool) (IssuerFromRequest, error) {
|
func IssuerFromHost(path string) func(bool) (IssuerFromRequest, error) {
|
||||||
return issuerFromForwardedOrHost(path, false)
|
return issuerFromForwardedOrHost(path, new(issuerConfig))
|
||||||
|
}
|
||||||
|
|
||||||
|
type IssuerFromOption func(c *issuerConfig)
|
||||||
|
|
||||||
|
// WithIssuerFromCustomHeaders can be used to customize the header names used.
|
||||||
|
// The same rules apply where the first successful host is returned.
|
||||||
|
func WithIssuerFromCustomHeaders(headers ...string) IssuerFromOption {
|
||||||
|
return func(c *issuerConfig) {
|
||||||
|
for i, h := range headers {
|
||||||
|
headers[i] = http.CanonicalHeaderKey(h)
|
||||||
|
}
|
||||||
|
c.headers = headers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type issuerConfig struct {
|
||||||
|
headers []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// IssuerFromForwardedOrHost tries to establish the Issuer based
|
// IssuerFromForwardedOrHost tries to establish the Issuer based
|
||||||
|
@ -64,11 +81,18 @@ func IssuerFromHost(path string) func(bool) (IssuerFromRequest, error) {
|
||||||
// If the Forwarded header is not present, no host field is found,
|
// If the Forwarded header is not present, no host field is found,
|
||||||
// or there is a parser error the Request Host will be used as a fallback.
|
// or there is a parser error the Request Host will be used as a fallback.
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
|
||||||
func IssuerFromForwardedOrHost(path string) func(bool) (IssuerFromRequest, error) {
|
func IssuerFromForwardedOrHost(path string, opts ...IssuerFromOption) func(bool) (IssuerFromRequest, error) {
|
||||||
return issuerFromForwardedOrHost(path, true)
|
c := &issuerConfig{
|
||||||
|
headers: []string{http.CanonicalHeaderKey("forwarded")},
|
||||||
|
}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
return issuerFromForwardedOrHost(path, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func issuerFromForwardedOrHost(path string, parseForwarded bool) func(bool) (IssuerFromRequest, error) {
|
func issuerFromForwardedOrHost(path string, c *issuerConfig) func(bool) (IssuerFromRequest, error) {
|
||||||
return func(allowInsecure bool) (IssuerFromRequest, error) {
|
return func(allowInsecure bool) (IssuerFromRequest, error) {
|
||||||
issuerPath, err := url.Parse(path)
|
issuerPath, err := url.Parse(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -78,26 +102,26 @@ func issuerFromForwardedOrHost(path string, parseForwarded bool) func(bool) (Iss
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return func(r *http.Request) string {
|
return func(r *http.Request) string {
|
||||||
if parseForwarded {
|
if host, ok := hostFromForwarded(r, c.headers); ok {
|
||||||
if host, ok := hostFromForwarded(r); ok {
|
return dynamicIssuer(host, path, allowInsecure)
|
||||||
return dynamicIssuer(host, path, allowInsecure)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return dynamicIssuer(r.Host, path, allowInsecure)
|
return dynamicIssuer(r.Host, path, allowInsecure)
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func hostFromForwarded(r *http.Request) (host string, ok bool) {
|
func hostFromForwarded(r *http.Request, headers []string) (host string, ok bool) {
|
||||||
fwd, err := httpforwarded.ParseFromRequest(r)
|
for _, header := range headers {
|
||||||
if err != nil {
|
hosts, err := httpforwarded.ParseParameter("host", r.Header[header])
|
||||||
log.Printf("Err: issuer from forwarded header: %v", err) // TODO change to slog on next branch
|
if err != nil {
|
||||||
return "", false
|
log.Printf("Err: issuer from forwarded header: %v", err) // TODO change to slog on next branch
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(hosts) > 0 {
|
||||||
|
return hosts[0], true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if fwd == nil || len(fwd["host"]) == 0 {
|
return "", false
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
return fwd["host"][0], true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func StaticIssuer(issuer string) func(bool) (IssuerFromRequest, error) {
|
func StaticIssuer(issuer string) func(bool) (IssuerFromRequest, error) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package op
|
package op
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -264,9 +265,10 @@ func TestIssuerFromHost(t *testing.T) {
|
||||||
|
|
||||||
func TestIssuerFromForwardedOrHost(t *testing.T) {
|
func TestIssuerFromForwardedOrHost(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
path string
|
path string
|
||||||
target string
|
opts []IssuerFromOption
|
||||||
forwarded []string
|
target string
|
||||||
|
header map[string][]string
|
||||||
}
|
}
|
||||||
type res struct {
|
type res struct {
|
||||||
issuer string
|
issuer string
|
||||||
|
@ -279,9 +281,9 @@ func TestIssuerFromForwardedOrHost(t *testing.T) {
|
||||||
{
|
{
|
||||||
"header parse error",
|
"header parse error",
|
||||||
args{
|
args{
|
||||||
path: "/custom/",
|
path: "/custom/",
|
||||||
target: "https://issuer.com",
|
target: "https://issuer.com",
|
||||||
forwarded: []string{"~~~"},
|
header: map[string][]string{"Forwarded": {"~~~~"}},
|
||||||
},
|
},
|
||||||
res{
|
res{
|
||||||
issuer: "https://issuer.com/custom/",
|
issuer: "https://issuer.com/custom/",
|
||||||
|
@ -303,9 +305,9 @@ func TestIssuerFromForwardedOrHost(t *testing.T) {
|
||||||
args{
|
args{
|
||||||
path: "/custom/",
|
path: "/custom/",
|
||||||
target: "https://issuer.com",
|
target: "https://issuer.com",
|
||||||
forwarded: []string{
|
header: map[string][]string{"Forwarded": {
|
||||||
`by=identifier;for=identifier;proto=https`,
|
`by=identifier;for=identifier;proto=https`,
|
||||||
},
|
}},
|
||||||
},
|
},
|
||||||
res{
|
res{
|
||||||
issuer: "https://issuer.com/custom/",
|
issuer: "https://issuer.com/custom/",
|
||||||
|
@ -316,9 +318,9 @@ func TestIssuerFromForwardedOrHost(t *testing.T) {
|
||||||
args{
|
args{
|
||||||
path: "/custom/",
|
path: "/custom/",
|
||||||
target: "https://issuer.com",
|
target: "https://issuer.com",
|
||||||
forwarded: []string{
|
header: map[string][]string{"Forwarded": {
|
||||||
`by=identifier;for=identifier;host=first.com;proto=https`,
|
`by=identifier;for=identifier;host=first.com;proto=https`,
|
||||||
},
|
}},
|
||||||
},
|
},
|
||||||
res{
|
res{
|
||||||
issuer: "https://first.com/custom/",
|
issuer: "https://first.com/custom/",
|
||||||
|
@ -329,9 +331,9 @@ func TestIssuerFromForwardedOrHost(t *testing.T) {
|
||||||
args{
|
args{
|
||||||
path: "/custom/",
|
path: "/custom/",
|
||||||
target: "https://issuer.com",
|
target: "https://issuer.com",
|
||||||
forwarded: []string{
|
header: map[string][]string{"Forwarded": {
|
||||||
`by=identifier;for=identifier;host=first.com;proto=https,host=second.com`,
|
`by=identifier;for=identifier;host=first.com;proto=https,host=second.com`,
|
||||||
},
|
}},
|
||||||
},
|
},
|
||||||
res{
|
res{
|
||||||
issuer: "https://first.com/custom/",
|
issuer: "https://first.com/custom/",
|
||||||
|
@ -342,23 +344,45 @@ func TestIssuerFromForwardedOrHost(t *testing.T) {
|
||||||
args{
|
args{
|
||||||
path: "/custom/",
|
path: "/custom/",
|
||||||
target: "https://issuer.com",
|
target: "https://issuer.com",
|
||||||
forwarded: []string{
|
header: map[string][]string{"Forwarded": {
|
||||||
`by=identifier;for=identifier;host=first.com;proto=https,host=second.com`,
|
`by=identifier;for=identifier;host=first.com;proto=https,host=second.com`,
|
||||||
`by=identifier;for=identifier;host=third.com;proto=https`,
|
`by=identifier;for=identifier;host=third.com;proto=https`,
|
||||||
},
|
}},
|
||||||
},
|
},
|
||||||
res{
|
res{
|
||||||
issuer: "https://first.com/custom/",
|
issuer: "https://first.com/custom/",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"custom header first",
|
||||||
|
args{
|
||||||
|
path: "/custom/",
|
||||||
|
target: "https://issuer.com",
|
||||||
|
header: map[string][]string{
|
||||||
|
"Forwarded": {
|
||||||
|
`by=identifier;for=identifier;host=first.com;proto=https,host=second.com`,
|
||||||
|
`by=identifier;for=identifier;host=third.com;proto=https`,
|
||||||
|
},
|
||||||
|
"X-Custom-Forwarded": {
|
||||||
|
`by=identifier;for=identifier;host=custom.com;proto=https,host=custom2.com`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts: []IssuerFromOption{
|
||||||
|
WithIssuerFromCustomHeaders("x-custom-forwarded"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
res{
|
||||||
|
issuer: "https://custom.com/custom/",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
issuer, err := IssuerFromForwardedOrHost(tt.args.path)(false)
|
issuer, err := IssuerFromForwardedOrHost(tt.args.path, tt.args.opts...)(false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
req := httptest.NewRequest("", tt.args.target, nil)
|
req := httptest.NewRequest("", tt.args.target, nil)
|
||||||
if tt.args.forwarded != nil {
|
for k, v := range tt.args.header {
|
||||||
req.Header["Forwarded"] = tt.args.forwarded
|
req.Header[http.CanonicalHeaderKey(k)] = v
|
||||||
}
|
}
|
||||||
assert.Equal(t, tt.res.issuer, issuer(req))
|
assert.Equal(t, tt.res.issuer, issuer(req))
|
||||||
})
|
})
|
||||||
|
|
38
pkg/op/op.go
38
pkg/op/op.go
|
@ -173,22 +173,52 @@ type Endpoints struct {
|
||||||
// Successful logins should mark the request as authorized and redirect back to to
|
// Successful logins should mark the request as authorized and redirect back to to
|
||||||
// op.AuthCallbackURL(provider) which is probably /callback. On the redirect back
|
// op.AuthCallbackURL(provider) which is probably /callback. On the redirect back
|
||||||
// to the AuthCallbackURL, the request id should be passed as the "id" parameter.
|
// to the AuthCallbackURL, the request id should be passed as the "id" parameter.
|
||||||
|
//
|
||||||
|
// Deprecated: use [NewProvider] with an issuer function direct.
|
||||||
func NewOpenIDProvider(issuer string, config *Config, storage Storage, opOpts ...Option) (*Provider, error) {
|
func NewOpenIDProvider(issuer string, config *Config, storage Storage, opOpts ...Option) (*Provider, error) {
|
||||||
return newProvider(config, storage, StaticIssuer(issuer), opOpts...)
|
return NewProvider(config, storage, StaticIssuer(issuer), opOpts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewForwardedOpenIDProvider tries to establishes the issuer from the request Host.
|
// NewForwardedOpenIDProvider tries to establishes the issuer from the request Host.
|
||||||
|
//
|
||||||
|
// Deprecated: use [NewProvider] with an issuer function direct.
|
||||||
func NewDynamicOpenIDProvider(path string, config *Config, storage Storage, opOpts ...Option) (*Provider, error) {
|
func NewDynamicOpenIDProvider(path string, config *Config, storage Storage, opOpts ...Option) (*Provider, error) {
|
||||||
return newProvider(config, storage, IssuerFromHost(path), opOpts...)
|
return NewProvider(config, storage, IssuerFromHost(path), opOpts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewForwardedOpenIDProvider tries to establish the Issuer from a Forwarded request header, if it is set.
|
// NewForwardedOpenIDProvider tries to establish the Issuer from a Forwarded request header, if it is set.
|
||||||
// See [IssuerFromForwardedOrHost] for details.
|
// See [IssuerFromForwardedOrHost] for details.
|
||||||
|
//
|
||||||
|
// Deprecated: use [NewProvider] with an issuer function direct.
|
||||||
func NewForwardedOpenIDProvider(path string, config *Config, storage Storage, opOpts ...Option) (*Provider, error) {
|
func NewForwardedOpenIDProvider(path string, config *Config, storage Storage, opOpts ...Option) (*Provider, error) {
|
||||||
return newProvider(config, storage, IssuerFromForwardedOrHost(path), opOpts...)
|
return NewProvider(config, storage, IssuerFromForwardedOrHost(path), opOpts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newProvider(config *Config, storage Storage, issuer func(bool) (IssuerFromRequest, error), opOpts ...Option) (_ *Provider, err error) {
|
// NewProvider creates a provider with a router on it's embedded http.Handler.
|
||||||
|
// Issuer is a function that must return the issuer on every request.
|
||||||
|
// Typically [StaticIssuer], [IssuerFromHost] or [IssuerFromForwardedOrHost] can be used.
|
||||||
|
//
|
||||||
|
// The router handles a suite of endpoints (some paths can be overridden):
|
||||||
|
//
|
||||||
|
// /healthz
|
||||||
|
// /ready
|
||||||
|
// /.well-known/openid-configuration
|
||||||
|
// /oauth/token
|
||||||
|
// /oauth/introspect
|
||||||
|
// /callback
|
||||||
|
// /authorize
|
||||||
|
// /userinfo
|
||||||
|
// /revoke
|
||||||
|
// /end_session
|
||||||
|
// /keys
|
||||||
|
// /device_authorization
|
||||||
|
//
|
||||||
|
// This does not include login. Login is handled with a redirect that includes the
|
||||||
|
// request ID. The redirect for logins is specified per-client by Client.LoginURL().
|
||||||
|
// Successful logins should mark the request as authorized and redirect back to to
|
||||||
|
// op.AuthCallbackURL(provider) which is probably /callback. On the redirect back
|
||||||
|
// to the AuthCallbackURL, the request id should be passed as the "id" parameter.
|
||||||
|
func NewProvider(config *Config, storage Storage, issuer func(insecure bool) (IssuerFromRequest, error), opOpts ...Option) (_ *Provider, err error) {
|
||||||
o := &Provider{
|
o := &Provider{
|
||||||
config: config,
|
config: config,
|
||||||
storage: storage,
|
storage: storage,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue