Skip to content

Commit

Permalink
fix: move to v0alpha2 api spec
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Sep 7, 2022
1 parent 6376135 commit a364db4
Show file tree
Hide file tree
Showing 65 changed files with 1,402 additions and 3,312 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ sdk: .bin/swagger .bin/ory node_modules
-p file://.schema/openapi/patches/security.yaml \
spec/swagger.json spec/api.json

rm -rf "internal/httpclient"
npm run openapi-generator-cli -- generate -i "spec/api.json" \
-g go \
-o "internal/httpclient" \
Expand Down
20 changes: 10 additions & 10 deletions client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type adminCreateOAuth2Client struct {
Body Client
}

// swagger:route POST /admin/clients v1 adminCreateOAuth2Client
// swagger:route POST /admin/clients v0alpha2 adminCreateOAuth2Client
//
// Create an OAuth 2.0 Client
//
Expand Down Expand Up @@ -124,7 +124,7 @@ type dynamicClientRegistrationCreateOAuth2Client struct {
Body Client
}

// swagger:route POST /oauth2/register v1 dynamicClientRegistrationCreateOAuth2Client
// swagger:route POST /oauth2/register v0alpha2 dynamicClientRegistrationCreateOAuth2Client
//
// Register an OAuth 2.0 Client using the OpenID / OAuth2 Dynamic Client Registration Management Protocol
//
Expand Down Expand Up @@ -233,7 +233,7 @@ type adminUpdateOAuth2Client struct {
Body Client
}

// swagger:route PUT /admin/clients/{id} v1 adminUpdateOAuth2Client
// swagger:route PUT /admin/clients/{id} v0alpha2 adminUpdateOAuth2Client
//
// Update an OAuth 2.0 Client
//
Expand Down Expand Up @@ -301,7 +301,7 @@ type dynamicClientRegistrationUpdateOAuth2Client struct {
Body Client
}

// swagger:route PUT /oauth2/register/{id} v1 dynamicClientRegistrationUpdateOAuth2Client
// swagger:route PUT /oauth2/register/{id} v0alpha2 dynamicClientRegistrationUpdateOAuth2Client
//
// Update an OAuth 2.0 Client using the OpenID / OAuth2 Dynamic Client Registration Management Protocol
//
Expand Down Expand Up @@ -388,7 +388,7 @@ type adminPatchOAuth2Client struct {
Body openapix.JSONPatchDocument
}

// swagger:route PATCH /admin/clients/{id} v1 adminPatchOAuth2Client
// swagger:route PATCH /admin/clients/{id} v0alpha2 adminPatchOAuth2Client
//
// Patch an OAuth 2.0 Client
//
Expand Down Expand Up @@ -470,7 +470,7 @@ type adminListOAuth2Clients struct {
Owner string `json:"owner"`
}

// swagger:route GET /admin/clients v1 adminListOAuth2Clients
// swagger:route GET /admin/clients v0alpha2 adminListOAuth2Clients
//
// List OAuth 2.0 Clients
//
Expand Down Expand Up @@ -539,7 +539,7 @@ type adminGetOAuth2Client struct {
ID string `json:"id"`
}

// swagger:route GET /admin/clients/{id} v1 adminGetOAuth2Client
// swagger:route GET /admin/clients/{id} v0alpha2 adminGetOAuth2Client
//
// Get an OAuth 2.0 Client
//
Expand Down Expand Up @@ -580,7 +580,7 @@ type dynamicClientRegistrationGetOAuth2Client struct {
ID string `json:"id"`
}

// swagger:route GET /oauth2/register/{id} v1 dynamicClientRegistrationGetOAuth2Client
// swagger:route GET /oauth2/register/{id} v0alpha2 dynamicClientRegistrationGetOAuth2Client
//
// Get an OAuth 2.0 Client using the OpenID / OAuth2 Dynamic Client Registration Management Protocol
//
Expand Down Expand Up @@ -643,7 +643,7 @@ type adminDeleteOAuth2Client struct {
ID string `json:"id"`
}

// swagger:route DELETE /admin/clients/{id} v1 adminDeleteOAuth2Client
// swagger:route DELETE /admin/clients/{id} v0alpha2 adminDeleteOAuth2Client
//
// Deletes an OAuth 2.0 Client
//
Expand Down Expand Up @@ -781,7 +781,7 @@ type dynamicClientRegistrationDeleteOAuth2Client struct {
ID string `json:"id"`
}

// swagger:route DELETE /oauth2/register/{id} v1 dynamicClientRegistrationDeleteOAuth2Client
// swagger:route DELETE /oauth2/register/{id} v0alpha2 dynamicClientRegistrationDeleteOAuth2Client
//
// Deletes an OAuth 2.0 Client using the OpenID / OAuth2 Dynamic Client Registration Management Protocol
//
Expand Down
42 changes: 21 additions & 21 deletions client/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func TestClientSDK(t *testing.T) {
c.GetConfig().Servers = hydra.ServerConfigurations{{URL: server.URL}}

t.Run("case=client default scopes are set", func(t *testing.T) {
result, _, err := c.V1Api.AdminCreateOAuth2Client(ctx).OAuth2Client(hydra.OAuth2Client{}).Execute()
result, _, err := c.V0alpha2Api.AdminCreateOAuth2Client(ctx).OAuth2Client(hydra.OAuth2Client{}).Execute()
require.NoError(t, err)
assert.EqualValues(t, conf.DefaultClientScope(ctx), strings.Split(*result.Scope, " "))

_, err = c.V1Api.AdminDeleteOAuth2Client(ctx, *result.ClientId).Execute()
_, err = c.V0alpha2Api.AdminDeleteOAuth2Client(ctx, *result.ClientId).Execute()
require.NoError(t, err)
})

Expand All @@ -115,7 +115,7 @@ func TestClientSDK(t *testing.T) {
// createClient.SecretExpiresAt = 10

// returned client is correct on Create
result, _, err := c.V1Api.AdminCreateOAuth2Client(ctx).OAuth2Client(createClient).Execute()
result, _, err := c.V0alpha2Api.AdminCreateOAuth2Client(ctx).OAuth2Client(createClient).Execute()
require.NoError(t, err)
assert.NotEmpty(t, result.UpdatedAt)
assert.NotEmpty(t, result.CreatedAt)
Expand All @@ -129,31 +129,31 @@ func TestClientSDK(t *testing.T) {

// secret is not returned on GetOAuth2Client
compareClient.ClientSecret = x.ToPointer("")
gresult, _, err := c.V1Api.AdminGetOAuth2Client(context.Background(), *createClient.ClientId).Execute()
gresult, _, err := c.V0alpha2Api.AdminGetOAuth2Client(context.Background(), *createClient.ClientId).Execute()
require.NoError(t, err)
assertx.EqualAsJSONExcept(t, compareClient, gresult, append(defaultIgnoreFields, "client_secret"))

// get client will return The request could not be authorized
gresult, _, err = c.V1Api.AdminGetOAuth2Client(context.Background(), "unknown").Execute()
gresult, _, err = c.V0alpha2Api.AdminGetOAuth2Client(context.Background(), "unknown").Execute()
require.Error(t, err)
assert.Empty(t, gresult)
assert.True(t, strings.Contains(err.Error(), "404"), err.Error())

// listing clients returns the only added one
results, _, err := c.V1Api.AdminListOAuth2Clients(context.Background()).PageSize(100).Execute()
results, _, err := c.V0alpha2Api.AdminListOAuth2Clients(context.Background()).PageSize(100).Execute()
require.NoError(t, err)
assert.Len(t, results, 1)
assertx.EqualAsJSONExcept(t, compareClient, results[0], append(defaultIgnoreFields, "client_secret"))

// SecretExpiresAt gets overwritten with 0 on Update
compareClient.ClientSecret = createClient.ClientSecret
uresult, _, err := c.V1Api.AdminUpdateOAuth2Client(context.Background(), *createClient.ClientId).OAuth2Client(createClient).Execute()
uresult, _, err := c.V0alpha2Api.AdminUpdateOAuth2Client(context.Background(), *createClient.ClientId).OAuth2Client(createClient).Execute()
require.NoError(t, err)
assertx.EqualAsJSONExcept(t, compareClient, uresult, append(defaultIgnoreFields, "client_secret"))

// create another client
updateClient := createTestClient("foo")
uresult, _, err = c.V1Api.AdminUpdateOAuth2Client(context.Background(), *createClient.ClientId).OAuth2Client(updateClient).Execute()
uresult, _, err = c.V0alpha2Api.AdminUpdateOAuth2Client(context.Background(), *createClient.ClientId).OAuth2Client(updateClient).Execute()
require.NoError(t, err)
assert.NotEqual(t, updateClient.ClientId, uresult.ClientId)
updateClient.ClientId = uresult.ClientId
Expand All @@ -162,34 +162,34 @@ func TestClientSDK(t *testing.T) {
// again, test if secret is not returned on Get
compareClient = updateClient
compareClient.ClientSecret = x.ToPointer("")
gresult, _, err = c.V1Api.AdminGetOAuth2Client(context.Background(), *updateClient.ClientId).Execute()
gresult, _, err = c.V0alpha2Api.AdminGetOAuth2Client(context.Background(), *updateClient.ClientId).Execute()
require.NoError(t, err)
assertx.EqualAsJSONExcept(t, compareClient, gresult, append(defaultIgnoreFields, "client_secret"))

// client can not be found after being deleted
_, err = c.V1Api.AdminDeleteOAuth2Client(context.Background(), *updateClient.ClientId).Execute()
_, err = c.V0alpha2Api.AdminDeleteOAuth2Client(context.Background(), *updateClient.ClientId).Execute()
require.NoError(t, err)

_, _, err = c.V1Api.AdminGetOAuth2Client(context.Background(), *updateClient.ClientId).Execute()
_, _, err = c.V0alpha2Api.AdminGetOAuth2Client(context.Background(), *updateClient.ClientId).Execute()
require.Error(t, err)
})

t.Run("case=public client is transmitted without secret", func(t *testing.T) {
result, _, err := c.V1Api.AdminCreateOAuth2Client(context.Background()).OAuth2Client(hydra.OAuth2Client{
result, _, err := c.V0alpha2Api.AdminCreateOAuth2Client(context.Background()).OAuth2Client(hydra.OAuth2Client{
TokenEndpointAuthMethod: x.ToPointer("none"),
}).Execute()
require.NoError(t, err)

assert.Equal(t, "", x.FromPointer[string](result.ClientSecret))

result, _, err = c.V1Api.AdminCreateOAuth2Client(context.Background()).OAuth2Client(createTestClient("")).Execute()
result, _, err = c.V0alpha2Api.AdminCreateOAuth2Client(context.Background()).OAuth2Client(createTestClient("")).Execute()
require.NoError(t, err)

assert.Equal(t, "secret", x.FromPointer[string](result.ClientSecret))
})

t.Run("case=id can not be set", func(t *testing.T) {
_, res, err := c.V1Api.AdminCreateOAuth2Client(context.Background()).OAuth2Client(hydra.OAuth2Client{ClientId: x.ToPointer(uuidx.NewV4().String())}).Execute()
_, res, err := c.V0alpha2Api.AdminCreateOAuth2Client(context.Background()).OAuth2Client(hydra.OAuth2Client{ClientId: x.ToPointer(uuidx.NewV4().String())}).Execute()
require.Error(t, err)
body, err := ioutil.ReadAll(res.Body)
require.NoError(t, err)
Expand All @@ -202,14 +202,14 @@ func TestClientSDK(t *testing.T) {
value := "http://foo.bar"

client := createTestClient("")
created, _, err := c.V1Api.AdminCreateOAuth2Client(context.Background()).OAuth2Client(client).Execute()
created, _, err := c.V0alpha2Api.AdminCreateOAuth2Client(context.Background()).OAuth2Client(client).Execute()
require.NoError(t, err)
client.ClientId = created.ClientId

expected := deepcopy.Copy(client).(hydra.OAuth2Client)
expected.RedirectUris = append(expected.RedirectUris, value)

result, _, err := c.V1Api.AdminPatchOAuth2Client(context.Background(), *client.ClientId).JsonPatch([]hydra.JsonPatch{{Op: op, Path: path, Value: value}}).Execute()
result, _, err := c.V0alpha2Api.AdminPatchOAuth2Client(context.Background(), *client.ClientId).JsonPatch([]hydra.JsonPatch{{Op: op, Path: path, Value: value}}).Execute()
require.NoError(t, err)
expected.CreatedAt = result.CreatedAt
expected.UpdatedAt = result.UpdatedAt
Expand All @@ -224,11 +224,11 @@ func TestClientSDK(t *testing.T) {
value := "foo"

client := createTestClient("")
created, res, err := c.V1Api.AdminCreateOAuth2Client(context.Background()).OAuth2Client(client).Execute()
created, res, err := c.V0alpha2Api.AdminCreateOAuth2Client(context.Background()).OAuth2Client(client).Execute()
require.NoError(t, err, "%s", ioutilx.MustReadAll(res.Body))
client.ClientId = created.ClientId

_, _, err = c.V1Api.AdminPatchOAuth2Client(context.Background(), *client.ClientId).JsonPatch([]hydra.JsonPatch{{Op: op, Path: path, Value: value}}).Execute()
_, _, err = c.V0alpha2Api.AdminPatchOAuth2Client(context.Background(), *client.ClientId).JsonPatch([]hydra.JsonPatch{{Op: op, Path: path, Value: value}}).Execute()
require.Error(t, err)
})

Expand All @@ -238,13 +238,13 @@ func TestClientSDK(t *testing.T) {
value := "http://foo.bar"

client := createTestClient("")
created, _, err := c.V1Api.AdminCreateOAuth2Client(context.Background()).OAuth2Client(client).Execute()
created, _, err := c.V0alpha2Api.AdminCreateOAuth2Client(context.Background()).OAuth2Client(client).Execute()
require.NoError(t, err)
client.ClientId = created.ClientId

result1, _, err := c.V1Api.AdminPatchOAuth2Client(context.Background(), *client.ClientId).JsonPatch([]hydra.JsonPatch{{Op: op, Path: path, Value: value}}).Execute()
result1, _, err := c.V0alpha2Api.AdminPatchOAuth2Client(context.Background(), *client.ClientId).JsonPatch([]hydra.JsonPatch{{Op: op, Path: path, Value: value}}).Execute()
require.NoError(t, err)
result2, _, err := c.V1Api.AdminPatchOAuth2Client(context.Background(), *client.ClientId).JsonPatch([]hydra.JsonPatch{{Op: op, Path: path, Value: value}}).Execute()
result2, _, err := c.V0alpha2Api.AdminPatchOAuth2Client(context.Background(), *client.ClientId).JsonPatch([]hydra.JsonPatch{{Op: op, Path: path, Value: value}}).Execute()
require.NoError(t, err)

// secret hashes shouldn't change between these PUT calls
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_create_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ To encrypt an auto-generated OAuth2 Client Secret, use flags `+"`--pgp-key`"+`,

secret := flagx.MustGetString(cmd, flagClientSecret)
//nolint:bodyclose
client, _, err := m.V1Api.AdminCreateOAuth2Client(cmd.Context()).OAuth2Client(clientFromFlags(cmd)).Execute()
client, _, err := m.V0alpha2Api.AdminCreateOAuth2Client(cmd.Context()).OAuth2Client(clientFromFlags(cmd)).Execute()
if err != nil {
return cmdx.PrintOpenAPIError(cmd, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_create_jwks.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewCreateJWKSCmd(parent *cobra.Command) *cobra.Command {
}

//nolint:bodyclose
jwks, _, err := m.V1Api.AdminCreateJsonWebKeySet(context.Background(), args[0]).AdminCreateJsonWebKeySetBody(hydra.AdminCreateJsonWebKeySetBody{
jwks, _, err := m.V0alpha2Api.AdminCreateJsonWebKeySet(context.Background(), args[0]).AdminCreateJsonWebKeySetBody(hydra.AdminCreateJsonWebKeySetBody{
Alg: flagx.MustGetString(cmd, alg),
Kid: kid,
Use: flagx.MustGetString(cmd, use),
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_delete_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ To delete OAuth 2.0 Clients with the owner of "foo@bar.com", run:
)

for _, c := range args {
_, err := m.V1Api.AdminDeleteOAuth2Client(cmd.Context(), c).Execute() //nolint:bodyclose
_, err := m.V0alpha2Api.AdminDeleteOAuth2Client(cmd.Context(), c).Execute() //nolint:bodyclose
if err != nil {
failed[c] = cmdx.PrintOpenAPIError(cmd, err)
continue
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_delete_jwks.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewDeleteJWKSCommand(root *cobra.Command) *cobra.Command {
)

for _, c := range args {
_, err = m.V1Api.AdminDeleteJsonWebKeySet(context.Background(), c).Execute() //nolint:bodyclose
_, err = m.V0alpha2Api.AdminDeleteJsonWebKeySet(context.Background(), c).Execute() //nolint:bodyclose
if err != nil {
return cmdx.PrintOpenAPIError(cmd, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_delete_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewDeleteAccessTokensCmd(parent *cobra.Command) *cobra.Command {
}

clientID := args[0]
_, err = client.V1Api.AdminDeleteOAuth2Token(cmd.Context()).ClientId(clientID).Execute() //nolint:bodyclose
_, err = client.V0alpha2Api.AdminDeleteOAuth2Token(cmd.Context()).ClientId(clientID).Execute() //nolint:bodyclose
if err != nil {
return cmdx.PrintOpenAPIError(cmd, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_get_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewGetClientsCmd(root *cobra.Command) *cobra.Command {

clients := make([]hydra.OAuth2Client, 0, len(args))
for _, id := range args {
client, _, err := m.V1Api.AdminGetOAuth2Client(cmd.Context(), id).Execute() //nolint:bodyclose
client, _, err := m.V0alpha2Api.AdminGetOAuth2Client(cmd.Context(), id).Execute() //nolint:bodyclose
if err != nil {
return cmdx.PrintOpenAPIError(cmd, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_get_jwks.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewGetJWKSCmd(root *cobra.Command) *cobra.Command {

var sets outputJSONWebKeyCollection
for _, set := range args {
key, _, err := m.V1Api.AdminGetJsonWebKeySet(cmd.Context(), set).Execute() //nolint:bodyclose
key, _, err := m.V0alpha2Api.AdminGetJsonWebKeySet(cmd.Context(), set).Execute() //nolint:bodyclose
if err != nil {
return cmdx.PrintOpenAPIError(cmd, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_import_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Please be aware that this command does not update existing clients. If the clien

for src, cc := range clients {
for _, c := range cc {
result, _, err := m.V1Api.AdminCreateOAuth2Client(cmd.Context()).OAuth2Client(c).Execute() //nolint:bodyclose
result, _, err := m.V0alpha2Api.AdminCreateOAuth2Client(cmd.Context()).OAuth2Client(c).Execute() //nolint:bodyclose
if err != nil {
failed[src] = cmdx.PrintOpenAPIError(cmd, err)
continue
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_import_jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ the imported keys will be added to that set. Otherwise, a new set will be create
failed := make(map[string]error)
for src, kk := range keys {
for _, k := range kk {
result, _, err := m.V1Api.AdminUpdateJsonWebKey(cmd.Context(), k.Kid, set).JsonWebKey(k).Execute() //nolint:bodyclose
result, _, err := m.V0alpha2Api.AdminUpdateJsonWebKey(cmd.Context(), k.Kid, set).JsonWebKey(k).Execute() //nolint:bodyclose
if err != nil {
failed[src] = cmdx.PrintOpenAPIError(cmd, err)
continue
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_introspect_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewIntrospectTokenCmd(parent *cobra.Command) *cobra.Command {
return err
}

result, _, err := client.V1Api.AdminIntrospectOAuth2Token(cmd.Context()).
result, _, err := client.V0alpha2Api.AdminIntrospectOAuth2Token(cmd.Context()).
Token(args[0]).
Scope(strings.Join(flagx.MustGetStringSlice(cmd, "scope"), " ")).Execute() //nolint:bodyclose
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_list_clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewListClientsCmd(root *cobra.Command) *cobra.Command {
return err
}

list, resp, err := m.V1Api.AdminListOAuth2Clients(cmd.Context()).PageSize(int64(pageSize)).PageToken(pageToken).Execute()
list, resp, err := m.V0alpha2Api.AdminListOAuth2Clients(cmd.Context()).PageSize(int64(pageSize)).PageToken(pageToken).Execute()
if err != nil {
return cmdx.PrintOpenAPIError(cmd, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_revoke_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Please provide a Client ID and Client Secret using flags --client-id and --clien
}

token := args[0]
_, err = client.V1Api.RevokeOAuth2Token(
_, err = client.V0alpha2Api.RevokeOAuth2Token(
context.WithValue(cmd.Context(), hydra.ContextBasicAuth, hydra.BasicAuth{
UserName: clientID,
Password: clientSecret,
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_update_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ To encrypt an auto-generated OAuth2 Client Secret, use flags `+"`--pgp-key`"+`,
id := args[0]
cc := clientFromFlags(cmd)

client, _, err := m.V1Api.AdminUpdateOAuth2Client(context.Background(), id).OAuth2Client(cc).Execute() //nolint:bodyclose
client, _, err := m.V0alpha2Api.AdminUpdateOAuth2Client(context.Background(), id).OAuth2Client(cc).Execute() //nolint:bodyclose
if err != nil {
return cmdx.PrintOpenAPIError(cmd, err)
}
Expand Down
Loading

0 comments on commit a364db4

Please sign in to comment.