Skip to content

Commit

Permalink
refactor: rename identity traits schema to identity schema
Browse files Browse the repository at this point in the history
Closes #531

BREAKING CHANGE: This patch renames the Identity Traits JSON Schema to Identity JSON Schema.

The identity payload has changed from

```
 {
-  "traits_schema_url": "...",
-  "traits_schema_id": "...",
+  "schema_url": "...",
+  "schema_id": "...",
 }
```

Additionally, it is now expected that your Identity JSON Schema includes a "traits" key at the
root level.

**Before (example)**

```
{
  "$id": "https://schemas.ory.sh/presets/kratos/quickstart/email-password/identity.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Person",
  "type": "object",
  "properties": {
    "email": {
      "type": "string",
      "format": "email",
      "title": "E-Mail",
      "minLength": 3,
      "ory.sh/kratos": {
        "credentials": {
          "password": {
            "identifier": true
          }
        },
        "verification": {
          "via": "email"
        },
        "recovery": {
          "via": "email"
        }
      }
    }
  },
  "required": [
    "email"
  ],
  "additionalProperties": false
}
```

**After (example)**

```
{
  "$id": "https://schemas.ory.sh/presets/kratos/quickstart/email-password/identity.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Person",
  "type": "object",
  "properties": {
    "traits": {
      "type": "object",
      "properties": {
        "email": {
          "type": "string",
          "format": "email",
          "title": "E-Mail",
          "minLength": 3,
          "ory.sh/kratos": {
            "credentials": {
              "password": {
                "identifier": true
              }
            },
            "verification": {
              "via": "email"
            },
            "recovery": {
              "via": "email"
            }
          }
        }
      },
      "required": [
        "email"
      ],
      "additionalProperties": false
    }
  }
}
```

You also need to remove the `traits` key from your ORY Kratos config like this:

```
 identity:
-   traits:
-     default_schema_url: http://test.kratos.ory.sh/default-identity.schema.json
-     schemas:
-       - id: other
-         url: http://test.kratos.ory.sh/other-identity.schema.json
+   default_schema_url: http://test.kratos.ory.sh/default-identity.schema.json
+   schemas:
+     - id: other
+       url: http://test.kratos.ory.sh/other-identity.schema.json
```

Do not forget to also update environment variables for the Identity JSON Schema as well if set.
  • Loading branch information
aeneasr committed Jul 7, 2020
1 parent 5f1f64e commit b86f271
Show file tree
Hide file tree
Showing 147 changed files with 1,484 additions and 7,435 deletions.
16 changes: 8 additions & 8 deletions .schema/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@
"type": "object",
"required": [
"id",
"traits_schema_id",
"schema_id",
"traits"
],
"properties": {
Expand All @@ -1174,17 +1174,17 @@
"$ref": "#/definitions/RecoveryAddress"
}
},
"traits": {
"$ref": "#/definitions/Traits"
},
"traits_schema_id": {
"description": "TraitsSchemaID is the ID of the JSON Schema to be used for validating the identity's traits.",
"schema_id": {
"description": "SchemaID is the ID of the JSON Schema to be used for validating the identity's traits.",
"type": "string"
},
"traits_schema_url": {
"description": "TraitsSchemaURL is the URL of the endpoint where the identity's traits schema can be fetched from.\n\nformat: url",
"schema_url": {
"description": "SchemaURL is the URL of the endpoint where the identity's traits schema can be fetched from.\n\nformat: url",
"type": "string"
},
"traits": {
"$ref": "#/definitions/Traits"
},
"verifiable_addresses": {
"description": "VerifiableAddresses contains all the addresses that can be verified by the user.",
"type": "array",
Expand Down
125 changes: 58 additions & 67 deletions .schema/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -702,79 +702,70 @@
"identity": {
"type": "object",
"properties": {
"traits": {
"type": "object",
"properties": {
"default_schema_url": {
"title": "JSON Schema URL for default identity traits",
"description": "Path to the JSON Schema which describes a default identity's traits.",
"type": "string",
"format": "uri",
"examples": [
"file://path/to/identity.traits.schema.json",
"httpss://foo.bar.com/path/to/identity.traits.schema.json"
]
},
"schemas": {
"type": "array",
"title": "Additional JSON Schemas for Identity Traits",
"examples": [
[
{
"id": "customer",
"url": "https://foo.bar.com/path/to/customer.traits.schema.json"
},
{
"id": "employee",
"url": "https://foo.bar.com/path/to/employee.traits.schema.json"
},
{
"id": "employee-v2",
"url": "https://foo.bar.com/path/to/employee.v2.traits.schema.json"
}
"default_schema_url": {
"title": "JSON Schema URL for default identity traits",
"description": "Path to the JSON Schema which describes a default identity's traits.",
"type": "string",
"format": "uri",
"examples": [
"file://path/to/identity.traits.schema.json",
"httpss://foo.bar.com/path/to/identity.traits.schema.json"
]
},
"schemas": {
"type": "array",
"title": "Additional JSON Schemas for Identity Traits",
"examples": [
[
{
"id": "customer",
"url": "https://foo.bar.com/path/to/customer.traits.schema.json"
},
{
"id": "employee",
"url": "https://foo.bar.com/path/to/employee.traits.schema.json"
},
{
"id": "employee-v2",
"url": "https://foo.bar.com/path/to/employee.v2.traits.schema.json"
}
]
],
"items": {
"type": "object",
"properties": {
"id": {
"title": "The schema's ID.",
"type": "string",
"examples": [
"employee"
]
},
"url": {
"type": "string",
"title": "Path to the JSON Schema",
"format": "uri",
"examples": [
"file://path/to/identity.traits.schema.json",
"https://foo.bar.com/path/to/identity.traits.schema.json"
]
],
"items": {
"type": "object",
"properties": {
"id": {
"title": "The schema's ID.",
"type": "string",
"examples": [
"employee"
]
},
"url": {
"type": "string",
"title": "Path to the JSON Schema",
"format": "uri",
"examples": [
"file://path/to/identity.traits.schema.json",
"https://foo.bar.com/path/to/identity.traits.schema.json"
]
}
},
"not": {
"type": "object",
"properties": {
"id": {
"type": "string",
"pattern": "^default$"
}
},
"additionalProperties": true
}
}
},
"not": {
"type": "object",
"properties": {
"id": {
"type": "string",
"pattern": "^default$"
}
},
"additionalProperties": true
}
},
"required": [
"default_schema_url"
],
"additionalProperties": false
}
}
},
"required": [
"traits"
"default_schema_url"
],
"additionalProperties": false
},
Expand Down
2 changes: 1 addition & 1 deletion continuity/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type persisterTestPayload struct {
func TestManager(t *testing.T) {
_, reg := internal.NewFastRegistryWithMocks(t)

viper.Set(configuration.ViperKeyDefaultIdentityTraitsSchemaURL, "file://./stub/identity.schema.json")
viper.Set(configuration.ViperKeyDefaultIdentitySchemaURL, "file://../test/stub/identity/empty.schema.json")
viper.Set(configuration.ViperKeyPublicBaseURL, "https://www.ory.sh")
i := identity.NewIdentity("")
require.NoError(t, reg.PrivilegedIdentityPool().CreateIdentity(context.Background(), i))
Expand Down
6 changes: 0 additions & 6 deletions continuity/stub/identity.schema.json

This file was deleted.

3 changes: 1 addition & 2 deletions contrib/quickstart/kratos/email-password/.kratos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ hashers:
key_length: 16

identity:
traits:
default_schema_url: file:///etc/config/kratos/identity.traits.schema.json
default_schema_url: file:///etc/config/kratos/identity.traits.schema.json

courier:
smtp:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@
"title": "Person",
"type": "object",
"properties": {
"email": {
"type": "string",
"format": "email",
"title": "E-Mail",
"minLength": 3,
"ory.sh/kratos": {
"credentials": {
"password": {
"identifier": true
"traits": {
"type": "object",
"properties": {
"email": {
"type": "string",
"format": "email",
"title": "E-Mail",
"minLength": 3,
"ory.sh/kratos": {
"credentials": {
"password": {
"identifier": true
}
},
"verification": {
"via": "email"
},
"recovery": {
"via": "email"
}
}
},
"verification": {
"via": "email"
},
"recovery": {
"via": "email"
}
}
},
"required": [
"email"
],
"additionalProperties": false
}
},
"required": [
"email"
],
"additionalProperties": false
}
}
4 changes: 2 additions & 2 deletions docs/docs/concepts/credentials/openid-connect-oidc-oauth2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ provider (for example [ORY Hydra](https://www.ory.sh/hydra)). "Social Sign In"
or "Sign in with ..." are common aliases for this flow.

This strategy expects that you've set up your
[Identity Traits Default JSON Schema](../identity-user-model).
[Default Identity JSON Schema](../identity-user-model).

## Configuration

Expand Down Expand Up @@ -219,7 +219,7 @@ credentials:
- provider: example
identifier: some-identity-id-4hA8gk
traits_schema_url: http://foo.bar.com/person.schema.json # This comes from the default identity schema url.
schema_url: http://foo.bar.com/person.schema.json # This comes from the default identity schema url.
traits:
email: foo@ory.sh # This is extracted from `username` using
Expand Down
Loading

0 comments on commit b86f271

Please sign in to comment.