-
-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added documentation for phone number identifier
- Loading branch information
1 parent
8a88f2e
commit 2fdec76
Showing
1 changed file
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,6 +251,8 @@ and Login Flow: | |
} | ||
``` | ||
|
||
|
||
Looking at the traits from above | ||
|
||
```yaml | ||
|
@@ -321,7 +323,88 @@ the identity's identifier. The system expects `[email protected]` plus a password to | |
sign in. | ||
|
||
[Username and Password Credentials](credentials/username-email-password.mdx) | ||
contains more information and examples. | ||
contains more information and examples about credentials usage. | ||
|
||
Note that "format" field of identity schema will perform validation of given | ||
trait. In this example email address of identity will be validated using | ||
[JSONSchema](https://json-schema.org/understanding-json-schema/reference/string.html#email-addresses) | ||
ruleset. | ||
|
||
#### Phone number | ||
|
||
Ory Kratos also has phone number identity trait extension. Phone number trait | ||
will allow users to recover and verify account by SMS. For a moment this | ||
functionality is in development | ||
[#1451](https://github.com/ory/kratos/issues/1451). | ||
|
||
Let's extend identity schema from previous chapter with phone number: | ||
|
||
```json | ||
{ | ||
"$id": "http://mydomain.com/schemas/v2/customer.schema.json", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "A customer (v2)", | ||
"type": "object", | ||
"properties": { | ||
"traits": { | ||
"type": "object", | ||
"properties": { | ||
"email": { | ||
"title": "E-Mail", | ||
"type": "string", | ||
"format": "email", | ||
// This tells Ory Kratos that the field should be used as the "username" for the Username and Password Flow. | ||
"ory.sh/kratos": { | ||
"credentials": { | ||
"password": { | ||
"identifier": true | ||
} | ||
} | ||
} | ||
}, | ||
"phone": { | ||
"title": "Phone", | ||
"type": "string", | ||
"format": "tel", | ||
// Let's mark phone number as identifier. This allows the user to login with both email and phone. | ||
"ory.sh/kratos": { | ||
"credentials": { | ||
"password": { | ||
"identifier": true | ||
} | ||
} | ||
} | ||
}, | ||
"name": { | ||
"type": "object", | ||
"properties": { | ||
"first": { | ||
"type": "string" | ||
}, | ||
"last": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"favorite_animal": { | ||
"type": "string" | ||
}, | ||
"accepted_tos": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["email"], | ||
"additionalProperties": false | ||
} | ||
} | ||
} | ||
``` | ||
|
||
By using "format": "tel" field we enable validation of phone numbers using | ||
golang [port](https://github.com/nyaruka/phonenumbers) of Google's | ||
[libphonenumber](https://github.com/google/libphonenumber). | ||
|
||
There are currently no other extensions supported for Identity Traits. Further | ||
fields will be added in future releases! | ||
|