scope form encoding
This commit is contained in:
parent
1661b40fbe
commit
507a437c56
3 changed files with 16 additions and 7 deletions
|
@ -60,8 +60,8 @@ type ResponseType string
|
||||||
|
|
||||||
type Scopes []string
|
type Scopes []string
|
||||||
|
|
||||||
func (s *Scopes) Encode() string {
|
func (s Scopes) Encode() string {
|
||||||
return strings.Join(*s, " ")
|
return strings.Join(s, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scopes) UnmarshalText(text []byte) error {
|
func (s *Scopes) UnmarshalText(text []byte) error {
|
||||||
|
|
|
@ -5,10 +5,12 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/gorilla/schema"
|
||||||
|
|
||||||
"github.com/caos/oidc/pkg/oidc"
|
"github.com/caos/oidc/pkg/oidc"
|
||||||
"github.com/caos/oidc/pkg/oidc/grants"
|
"github.com/caos/oidc/pkg/oidc/grants"
|
||||||
|
@ -24,6 +26,16 @@ const (
|
||||||
jwtProfileKey = "urn:ietf:params:oauth:grant-type:jwt-bearer"
|
jwtProfileKey = "urn:ietf:params:oauth:grant-type:jwt-bearer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
encoder = func() utils.Encoder {
|
||||||
|
e := schema.NewEncoder()
|
||||||
|
e.RegisterEncoder(oidc.Scopes{}, func(value reflect.Value) string {
|
||||||
|
return value.Interface().(oidc.Scopes).Encode()
|
||||||
|
})
|
||||||
|
return e
|
||||||
|
}()
|
||||||
|
)
|
||||||
|
|
||||||
//RelayingParty declares the minimal interface for oidc clients
|
//RelayingParty declares the minimal interface for oidc clients
|
||||||
type RelayingParty interface {
|
type RelayingParty interface {
|
||||||
//OAuthConfig returns the oauth2 Config
|
//OAuthConfig returns the oauth2 Config
|
||||||
|
@ -334,7 +346,7 @@ func CallTokenEndpoint(request interface{}, rp RelayingParty) (newToken *oauth2.
|
||||||
}
|
}
|
||||||
|
|
||||||
func callTokenEndpoint(request interface{}, authFn interface{}, rp RelayingParty) (newToken *oauth2.Token, err error) {
|
func callTokenEndpoint(request interface{}, authFn interface{}, rp RelayingParty) (newToken *oauth2.Token, err error) {
|
||||||
req, err := utils.FormRequest(rp.OAuthConfig().Endpoint.TokenURL, request, authFn)
|
req, err := utils.FormRequest(rp.OAuthConfig().Endpoint.TokenURL, request, encoder, authFn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,6 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/schema"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -36,9 +34,8 @@ func AuthorizeBasic(user, password string) RequestAuthorization {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormRequest(endpoint string, request interface{}, authFn interface{}) (*http.Request, error) {
|
func FormRequest(endpoint string, request interface{}, encoder Encoder, authFn interface{}) (*http.Request, error) {
|
||||||
form := url.Values{}
|
form := url.Values{}
|
||||||
encoder := schema.NewEncoder()
|
|
||||||
if err := encoder.Encode(request, form); err != nil {
|
if err := encoder.Encode(request, form); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue