fix: custom absolute endpoints
This commit is contained in:
parent
30d8dec409
commit
660519a19f
4 changed files with 41 additions and 16 deletions
|
@ -21,7 +21,7 @@ func main() {
|
||||||
Port: "9998",
|
Port: "9998",
|
||||||
}
|
}
|
||||||
storage := mock.NewAuthStorage()
|
storage := mock.NewAuthStorage()
|
||||||
handler, err := op.NewDefaultOP(ctx, config, storage, op.WithCustomTokenEndpoint("test"))
|
handler, err := op.NewDefaultOP(ctx, config, storage, op.WithCustomTokenEndpoint(op.NewEndpoint("test")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,11 +26,11 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DefaultEndpoints = &endpoints{
|
DefaultEndpoints = &endpoints{
|
||||||
Authorization: defaultAuthorizationEndpoint,
|
Authorization: NewEndpoint(defaultAuthorizationEndpoint),
|
||||||
Token: defaulTokenEndpoint,
|
Token: NewEndpoint(defaulTokenEndpoint),
|
||||||
IntrospectionEndpoint: defaultIntrospectEndpoint,
|
IntrospectionEndpoint: NewEndpoint(defaultIntrospectEndpoint),
|
||||||
Userinfo: defaultUserinfoEndpoint,
|
Userinfo: NewEndpoint(defaultUserinfoEndpoint),
|
||||||
JwksURI: defaultKeysEndpoint,
|
JwksURI: NewEndpoint(defaultKeysEndpoint),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,28 @@ package op
|
||||||
|
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
type Endpoint string
|
type Endpoint struct {
|
||||||
|
path string
|
||||||
|
url string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEndpoint(path string) Endpoint {
|
||||||
|
return Endpoint{path: path}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEndpointWithURL(path, url string) Endpoint {
|
||||||
|
return Endpoint{path: path, url: url}
|
||||||
|
}
|
||||||
|
|
||||||
func (e Endpoint) Relative() string {
|
func (e Endpoint) Relative() string {
|
||||||
return relativeEndpoint(string(e))
|
return relativeEndpoint(e.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e Endpoint) Absolute(host string) string {
|
func (e Endpoint) Absolute(host string) string {
|
||||||
return absoluteEndpoint(host, string(e))
|
if e.url != "" {
|
||||||
|
return e.url
|
||||||
|
}
|
||||||
|
return absoluteEndpoint(host, e.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e Endpoint) Validate() error {
|
func (e Endpoint) Validate() error {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/caos/oidc/pkg/op"
|
"github.com/caos/oidc/pkg/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEndpoint_Relative(t *testing.T) {
|
func TestEndpoint_Path(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
e op.Endpoint
|
e op.Endpoint
|
||||||
|
@ -14,12 +14,17 @@ func TestEndpoint_Relative(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"without starting /",
|
"without starting /",
|
||||||
op.Endpoint("test"),
|
op.NewEndpoint("test"),
|
||||||
"/test",
|
"/test",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"with starting /",
|
"with starting /",
|
||||||
op.Endpoint("/test"),
|
op.NewEndpoint("/test"),
|
||||||
|
"/test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"with url",
|
||||||
|
op.NewEndpointWithURL("/test", "http://test.com/test"),
|
||||||
"/test",
|
"/test",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -44,28 +49,34 @@ func TestEndpoint_Absolute(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"no /",
|
"no /",
|
||||||
op.Endpoint("test"),
|
op.NewEndpoint("test"),
|
||||||
args{"https://host"},
|
args{"https://host"},
|
||||||
"https://host/test",
|
"https://host/test",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"endpoint without /",
|
"endpoint without /",
|
||||||
op.Endpoint("test"),
|
op.NewEndpoint("test"),
|
||||||
args{"https://host/"},
|
args{"https://host/"},
|
||||||
"https://host/test",
|
"https://host/test",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"host without /",
|
"host without /",
|
||||||
op.Endpoint("/test"),
|
op.NewEndpoint("/test"),
|
||||||
args{"https://host"},
|
args{"https://host"},
|
||||||
"https://host/test",
|
"https://host/test",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"both /",
|
"both /",
|
||||||
op.Endpoint("/test"),
|
op.NewEndpoint("/test"),
|
||||||
args{"https://host/"},
|
args{"https://host/"},
|
||||||
"https://host/test",
|
"https://host/test",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"with url",
|
||||||
|
op.NewEndpointWithURL("test", "https://test.com/test"),
|
||||||
|
args{"https://host"},
|
||||||
|
"https://test.com/test",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue