Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Jun 17, 2022
1 parent 92236d9 commit b7fea62
Show file tree
Hide file tree
Showing 44 changed files with 913 additions and 1,018 deletions.
6 changes: 6 additions & 0 deletions client/.snapshots/TestClientSDK-case=id_can_not_be_set.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Payload": {
"error": "The request was malformed or contained invalid parameters",
"error_description": "It is no longer possible to set an OAuth2 Client ID as a user. The system will generate a unique ID for you."
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"client_id": "0f1bb84e-4405-4e93-950b-cdae88c5dbf6",
"client_name": "",
"client_secret": "averylongsecret",
"redirect_uris": [
Expand All @@ -23,6 +22,5 @@
"userinfo_signed_response_alg": "none",
"metadata": {
"foo": "bar"
},
"registration_client_uri": "http://localhost:4444/oauth2/register/0f1bb84e-4405-4e93-950b-cdae88c5dbf6"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"error": "The request was malformed or contained invalid parameters",
"error_description": "Only UUID V4 (e.g. 8dcd6868-e294-4180-aa36-fbad26de79a6) can be chosen as OAuth2 Client IDs but got: not-a-uuid"
"error_description": "It is no longer possible to set an OAuth2 Client ID as a user. The system will generate a unique ID for you."
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"error": "The request was malformed or contained invalid parameters",
"error_description": "It is no longer possible to set an OAuth2 Client ID as a user. The system will generate a unique ID for you."
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"body": {
"client_id": "0e837115-5105-4da7-a85e-ac286c2ef50e",
"client_name": "",
"redirect_uris": [
"http://localhost:3000/cb"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"body": {
"client_id": "0e837115-5105-4da7-a85e-ac286c2ef50e",
"client_name": "",
"redirect_uris": [
"http://localhost:3000/cb"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"body": {
"client_id": "c614c65a-72f3-4dd4-8217-f4c6343533dc",
"client_name": "",
"client_secret": "averylongsecret",
"redirect_uris": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"body": {
"client_id": "b33d7cff-ecc9-4acf-9ce7-67436bc763d4",
"client_name": "",
"redirect_uris": [
"http://localhost:3000/cb",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"client_name": "",
"client_secret": "01bbf13a-ae3e-44d5-b4b4-dd78137041be",
"redirect_uris": null,
"grant_types": null,
"response_types": null,
Expand Down

This file was deleted.

This file was deleted.

2 changes: 2 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type Client struct {
NID uuid.UUID `db:"nid" faker:"-" json:"-"`

// ID is the id for this client.
//
// The ID is autogenerated and immutable.
LegacyClientID string `json:"client_id" db:"id"`

// DEPRECATED: This field is deprecated and will be removed. It serves
Expand Down
15 changes: 4 additions & 11 deletions client/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import (
"net/http"
"time"

"github.com/gofrs/uuid"

"github.com/ory/x/uuidx"

"github.com/ory/x/urlx"
Expand Down Expand Up @@ -152,26 +150,22 @@ func (h *Handler) CreateDynamicRegistration(w http.ResponseWriter, r *http.Reque

func (h *Handler) CreateClient(r *http.Request, validator func(context.Context, *Client) error, isDynamic bool) (*Client, error) {
var c Client

if err := json.NewDecoder(r.Body).Decode(&c); err != nil {
return nil, err
}

if isDynamic {
c.LegacyClientID = ""
if c.Secret != "" {
return nil, errorsx.WithStack(herodot.ErrBadRequest.WithReasonf("It is not allowed to choose your own OAuth2 Client secret."))
}
}

c.ID = uuidx.NewV4()
if c.LegacyClientID == "" {
c.LegacyClientID = c.ID.String()
if len(c.LegacyClientID) > 0 {
return nil, errorsx.WithStack(herodot.ErrBadRequest.WithReason("It is no longer possible to set an OAuth2 Client ID as a user. The system will generate a unique ID for you."))
}

if _, err := uuid.FromString(c.LegacyClientID); err != nil {
return nil, errorsx.WithStack(herodot.ErrBadRequest.WithReasonf("Only UUID V4 (e.g. 8dcd6868-e294-4180-aa36-fbad26de79a6) can be chosen as OAuth2 Client IDs but got: %s", c.LegacyClientID))
}
c.ID = uuidx.NewV4()
c.LegacyClientID = c.ID.String()

if len(c.Secret) == 0 {
secretb, err := x.GenerateSecret(26)
Expand Down Expand Up @@ -497,7 +491,6 @@ func (h *Handler) List(w http.ResponseWriter, r *http.Request, ps httprouter.Par
// default: jsonError
func (h *Handler) Get(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var id = ps.ByName("id")

c, err := h.r.ClientManager().GetConcreteClient(r.Context(), id)
if err != nil {
h.r.Writer().WriteError(w, r, err)
Expand Down
Loading

0 comments on commit b7fea62

Please sign in to comment.