There are a number of Identity Management functions you can use to configure the default settings of your login/registration screens and control the behavior of Identity Management templates. They include:
|
|
This function allows you to configure Identity Management's default settings. Available settings are discussed below. |
|
|
This function triggers any Identity Management screen you want to show. The screen shown depends on how the |
|
|
This function triggers a Custom form.* |
|
|
This function logs in a user by setting a token into a cookie. This method is useful for scenarios where you need to authenticate a user without displaying a login page, such as when using the Generate user token endpoint. It is particularly beneficial for integrations where the user token is generated and validated on the backend. It takes a single argument, the user token, and upon successful login, the |
|
|
This function makes the user logout. It is typically used to create a logout button for logged in users. You can pass in a callback as a parameter if you would like an event to occur following the logout. If the checkout is single-step or passwordless, the user is redirected back to the offer after logout. |
|
|
This function allows you to retrieve additional information about a logged in user. More details are available here. |
|
|
This function allows you to update the first and last name of a user. For example, If either the first or last name properties are not defined, they will get an empty string value. |
|
|
This function returns |
|
|
This function returns a current user's custom field. Once received, the user profile data will be passed via the |
|
|
This function returns the user's language. For example if the language is set to American English, the response would be |
*The format would look like this tp.pianoId.showForm({formName: 'formName', templateId: 'templateId', variantId: 'variantId'}), where you would insert the form_id of the custom form as the value for the formName, the Piano ID Custom Form template ID as the value for the templateId and if available, a variant ID of this template as the variantId. You could also specify if the form should not be shown in case a user has already filled in all custom field values included in the form using hideIfComplete: true.
The tp.pianoId.init() function allows you to override several default Identity Management parameters while the tp.pianoId.show() function allows you to trigger various Identity Management behaviors. The parameters for these functions include:
Parameter
|
Description
|
|
|
The url of the Identity Management deployment host. You need to change this parameter only if you have configured a dedicated domain for SSO support with Piano. If you are using an app on the EU dashboard, the URL would be https://id-eu.piano.io, on the AP dashboard, the URL would be https://id-ap.piano.io, and on the AU dashboard, the URL would be https://id-au.piano.io.* |
|
|
If this parameter is set to |
|
|
This token is created when a user wants to perform a password reset. This parameter is typically used with the |
|
|
The display mode of the Identity Management templates. The default value is |
|
|
Specify the Identity Management screen to show. Possible values include |
|
|
If you're using an inline template, this is the container selector. |
|
|
The width of |
|
|
The height of |
|
|
This callback is fired when a user logs in. |
|
|
This callback is fired when a user logs out. |
|
|
This callback is fired when a user successfully logs in. |
|
|
This callback is fired when a user successfully signs up a new account. |
|
|
This callback is fired when a user updates their profile via My Account as well as when a user profile is updated during a custom form submission. |
|
|
This callback is fired when a user changes their default language. |
|
|
This callback is fired when the login screen is presented. |
|
|
This callback is fired when the registration screen is presented. |
|
|
This callback is fired upon an unsuccessful login attempt. |
|
|
This callback is fired upon an unsuccessful registration attempt. |
*For example like this:
tp.push(["init", function () {
tp.pianoId.init({
iframeUrl:"https://id-eu.piano.io"
});
tp.experience.init()
}]);
Here's what a configured version of tp.pianoId.init() might look like:
tp = window.tp || [];
tp.push(['setUsePianoIdUserProvider', true]);
tp.push(["init", function() {
tp.pianoId.init({
displayMode: 'inline',
containerSelector: '#login-form',
loggedIn: function(data) {
console.log('user ', data.user, ' logged in with token', data.token);
},
loggedOut: function() {
console.log('user logged out');
}
});
}]);
And here's what a configured version of tp.pianoId.show() might look like:
tp = window.tp || [];
tp.push(['setUsePianoIdUserProvider', true]);
tp.push(["init", function() {
tp.pianoId.show({
disableSignUp: true,
displayMode: 'inline',
screen: 'login',
containerSelector: '#login-form',
loggedIn: function(data) {
console.log('user ', data.user, ' logged in with token', data.token);
},
loggedOut: function() {
console.log('user logged out');
}
});
}]);
Another property that can be utilized for the tp.pianoId.show function is observeContainer.
tp.pianoId.show({
...
observeContainer: true
})
The observeContainer property enables observing the Identity Management container size changing for inline mode templates. It is helpful if you want to pre-initiate inline Identity Management templates inside an invisible container element.
To get custom field data from a logged-in user:
-
Create a custom form.
-
Add the required fields in the custom form.
-
Use the
form_nameparameter in the call toloadExtendedUser.
tp = window.tp || [];
tp.pianoId.loadExtendedUser({
extendedUserLoaded: function (data) {
for (var i in data.custom_field_values) {
var fieldName = data.custom_field_values[i].field_name;
var fieldValue = data.custom_field_values[i].value;
console.log("Field " + fieldName + " has value " + fieldValue);
}
}, formName: 'new_form'
});