Skip to content

Commit

Permalink
fix: oauth client metadata as object in CRD (ory#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlytvyn committed Jun 3, 2021
1 parent 8b8746d commit d9eeaac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
9 changes: 7 additions & 2 deletions api/v1alpha1/oauth2client_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"

"github.com/ory/hydra-maester/hydra"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -120,8 +121,10 @@ type OAuth2ClientSpec struct {
// Indication which authentication method shoud be used for the token endpoint
TokenEndpointAuthMethod TokenEndpointAuthMethod `json:"tokenEndpointAuthMethod,omitempty"`

// +kubebuilder:validation:Type=object
//
// Metadata is abritrary data
Metadata json.RawMessage `json:"metadata,omitempty"`
Metadata apiextensionsv1.JSON `json:"metadata,omitempty"`
}

// +kubebuilder:validation:Enum=client_credentials;authorization_code;implicit;refresh_token
Expand Down Expand Up @@ -182,6 +185,8 @@ func init() {

// ToOAuth2ClientJSON converts an OAuth2Client into a OAuth2ClientJSON object that represents an OAuth2 client digestible by ORY Hydra
func (c *OAuth2Client) ToOAuth2ClientJSON() *hydra.OAuth2ClientJSON {
meta, _ := json.Marshal(c.Spec.Metadata)

return &hydra.OAuth2ClientJSON{
ClientName: c.Spec.ClientName,
GrantTypes: grantToStringSlice(c.Spec.GrantTypes),
Expand All @@ -193,7 +198,7 @@ func (c *OAuth2Client) ToOAuth2ClientJSON() *hydra.OAuth2ClientJSON {
Scope: c.Spec.Scope,
Owner: fmt.Sprintf("%s/%s", c.Name, c.Namespace),
TokenEndpointAuthMethod: string(c.Spec.TokenEndpointAuthMethod),
Metadata: c.Spec.Metadata,
Metadata: meta,
}
}

Expand Down
7 changes: 1 addition & 6 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions config/crd/bases/hydra.ory.sh_oauth2clients.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ spec:
type: object
metadata:
description: Metadata is abritrary data
format: byte
type: string
type: object
x-kubernetes-preserve-unknown-fields: true
postLogoutRedirectUris:
description: PostLogoutRedirectURIs is an array of the post logout
redirect URIs allowed for the application
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/stretchr/testify v1.6.1
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
k8s.io/api v0.20.2
k8s.io/apiextensions-apiserver v0.20.1
k8s.io/apimachinery v0.20.2
k8s.io/client-go v0.20.2
k8s.io/utils v0.0.0-20210305010621-2afb4311ab10
Expand Down

0 comments on commit d9eeaac

Please sign in to comment.