Docs

Using Passwordless Authentication on iOS with SMS in Swift

LanguageSwift

Metadata in Rules

This article explains how to read, update and delete metadata using Rules.

Each sample rule in this article assumes that the user and their information is represented by the following JSON snippet:

Setup

Read Metadata

To read the available metadata, you will need to access the correct user property.

Open an account with Twilio

Read app_metadata

Make a decision based on the user's passwordlessroles:

Configure the connection

Read user_metadata

Similarly, you can use the color preference:

Multi-language support

Read client_metadata

clientMetadata is an optional, top-level property of the context object. Existing applications will have no value for this property.

Message syntax

Read client_metadata with the Management API

client_metadata is included amongst in the response to the GET /api/v2/clients and GET /api/v2/client/{id} endpoints

Enable your apps

Create applications with client_metadata properties

A client_metadata object can be included when creating a new application via the POST /api/v2/ applications endpoint.

Implementation

Create client_metadata properties in the dashboard

client_metadata key value pairs can also be added in the dashboard, by going to Applications. Then select the settings(the gear icon) of the application you wish to edit.

Scroll down and click the link Show Advanced Settings. Then you will be in the Application Metadata section, enter the key and value then click CREATE.

Create application metadata

Using Auth0 Lock

Update Metadata

All rules include an auth0 object (which is an instance of the node-auth0 SDK) that is capable of calling the Auth0 Management API v2. The auth0 object is preconfigured with the necessary permissions to update users.

Using your own UI

Update app_metadata

To add an administrative role to the user:

This results in the following JSON representation of the user profile details:

Update user_metadata

To add the user's fontSize preference to the user profile:

This results in the following JSON representation of the user profile details:

Update app_metadata and user_metadata simultaneously

To reduce the rule's processing time, you may update both the app_metadata and user_metadata in the same rule:

This results in the following JSON representation of the user profile details:

Update client_metadata

Application metadata can be updated using the PATCH /api/v2/clients/{id} endpoint, supplying an application object with the client_metadata property, whose value is an object containing the metadata you'd like to change.

Application Before

Request: PATCH /api/v2/client/myclientid123 with body:

Application After

Update client_metadata in the dashboard

Application metadata can also be updated in the dashboard, by going to Applications. Then select the settings(the gear icon) of the application you wish to edit.

Scroll down and click the link Show Advanced Settings. Then you will be in the Application Metadata section. For the key value, enter the name of the key you wish to edit. Then enter the new value that you want to update.

Click UPDATE. A popup window will appear to confirm your overwrite.

Confirm Update

Delete Metadata

Delete app_metadata properties and values

To delete a property, set the property's value to null.

For example, to delete the user's roles:

This results in the following JSON representation of the user profile details:

To delete a single value of a property, remove that value specifically.

For example, to remove the writer role from the user profile:

This results in the following JSON representation of the user profile details:

Note that the roles property still exists but does not contain any value.

Delete user_metadata properties and values

To delete the user's color preference:

This results in the following JSON representation of the user profile details:

Delete client_metadata properties and values

client_metadata keys can be removed by issuing a PATCH, as described above, but supplying a null for the key value. This behavior matches that of the user_metadata and app_metadata properties in the PATCH /api/v2/users/{id} endpoint.

Delete client_metadata properties and values in the dashboard

client_metadata keys can also be removed in the dashboard, by going to Applications. Then select the settings(the gear icon) of the application you wish to edit.

Scroll down and click the link Show Advanced Settings. Then you will be in the Application Metadata section, click the REMOVE button for the key/value pair you wish to delete.

Remove application metadata

Considerations

The metadata must be a valid JSON object and can not contain a dot in key field names in user_metadata, app_metadata or client_metadata.

This is not allowed:

This, however, is accepted:

If you use a key field name with a dot in it you will get an Internal Server (500) error.

As a workaround, you can convert the first example to something like this.

Or you could use a different delimiter character besides . (dot) or $ (dollar sign).

client_metadata is an object, whose keys and values are strings, with a maximum length of 255 characters. Also client_metadata is restricted to having a maximum 10 keys.

Keep reading