chore: make tokenEndpointCaller public
This commit is contained in:
parent
5fb36bf4c2
commit
d6cbf10a00
2 changed files with 14 additions and 17 deletions
|
@ -15,20 +15,17 @@ import (
|
||||||
"github.com/zitadel/oidc/pkg/oidc"
|
"github.com/zitadel/oidc/pkg/oidc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var Encoder = func() httphelper.Encoder {
|
||||||
Encoder = func() httphelper.Encoder {
|
|
||||||
e := schema.NewEncoder()
|
e := schema.NewEncoder()
|
||||||
e.RegisterEncoder(oidc.SpaceDelimitedArray{}, func(value reflect.Value) string {
|
e.RegisterEncoder(oidc.SpaceDelimitedArray{}, func(value reflect.Value) string {
|
||||||
return value.Interface().(oidc.SpaceDelimitedArray).Encode()
|
return value.Interface().(oidc.SpaceDelimitedArray).Encode()
|
||||||
})
|
})
|
||||||
return e
|
return e
|
||||||
}()
|
}()
|
||||||
)
|
|
||||||
|
|
||||||
//Discover calls the discovery endpoint of the provided issuer and returns its configuration
|
// Discover calls the discovery endpoint of the provided issuer and returns its configuration
|
||||||
//It accepts an optional argument "wellknownUrl" which can be used to overide the dicovery endpoint url
|
// It accepts an optional argument "wellknownUrl" which can be used to overide the dicovery endpoint url
|
||||||
func Discover(issuer string, httpClient *http.Client, wellKnownUrl ...string) (*oidc.DiscoveryConfiguration, error) {
|
func Discover(issuer string, httpClient *http.Client, wellKnownUrl ...string) (*oidc.DiscoveryConfiguration, error) {
|
||||||
|
|
||||||
wellKnown := strings.TrimSuffix(issuer, "/") + oidc.DiscoveryEndpoint
|
wellKnown := strings.TrimSuffix(issuer, "/") + oidc.DiscoveryEndpoint
|
||||||
if len(wellKnownUrl) == 1 && wellKnownUrl[0] != "" {
|
if len(wellKnownUrl) == 1 && wellKnownUrl[0] != "" {
|
||||||
wellKnown = wellKnownUrl[0]
|
wellKnown = wellKnownUrl[0]
|
||||||
|
@ -48,16 +45,16 @@ func Discover(issuer string, httpClient *http.Client, wellKnownUrl ...string) (*
|
||||||
return discoveryConfig, nil
|
return discoveryConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type tokenEndpointCaller interface {
|
type TokenEndpointCaller interface {
|
||||||
TokenEndpoint() string
|
TokenEndpoint() string
|
||||||
HttpClient() *http.Client
|
HttpClient() *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func CallTokenEndpoint(request interface{}, caller tokenEndpointCaller) (newToken *oauth2.Token, err error) {
|
func CallTokenEndpoint(request interface{}, caller TokenEndpointCaller) (newToken *oauth2.Token, err error) {
|
||||||
return callTokenEndpoint(request, nil, caller)
|
return callTokenEndpoint(request, nil, caller)
|
||||||
}
|
}
|
||||||
|
|
||||||
func callTokenEndpoint(request interface{}, authFn interface{}, caller tokenEndpointCaller) (newToken *oauth2.Token, err error) {
|
func callTokenEndpoint(request interface{}, authFn interface{}, caller TokenEndpointCaller) (newToken *oauth2.Token, err error) {
|
||||||
req, err := httphelper.FormRequest(caller.TokenEndpoint(), request, Encoder, authFn)
|
req, err := httphelper.FormRequest(caller.TokenEndpoint(), request, Encoder, authFn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"github.com/zitadel/oidc/pkg/oidc"
|
"github.com/zitadel/oidc/pkg/oidc"
|
||||||
)
|
)
|
||||||
|
|
||||||
//JWTProfileExchange handles the oauth2 jwt profile exchange
|
// JWTProfileExchange handles the oauth2 jwt profile exchange
|
||||||
func JWTProfileExchange(jwtProfileGrantRequest *oidc.JWTProfileGrantRequest, caller tokenEndpointCaller) (*oauth2.Token, error) {
|
func JWTProfileExchange(jwtProfileGrantRequest *oidc.JWTProfileGrantRequest, caller TokenEndpointCaller) (*oauth2.Token, error) {
|
||||||
return CallTokenEndpoint(jwtProfileGrantRequest, caller)
|
return CallTokenEndpoint(jwtProfileGrantRequest, caller)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue