This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Configuring a User Preferred Notification Channel

The steps given below guide you through configuring WSO2 Identity Server to use a user-preferred notification channel (i.e., EMAIL or SMS) to send the notification for self-registration and account confirmation purposes. 

Before you begin

To learn more about self-registration and account confirmation APIs, see Extending User Self Registration and Account Confirmation.

  1. Configure the following email settings in the <IS_HOME>/repository/conf/output-event-adapters.xml file. 

    mail.smtp.fromProvide the email address of the SMTP account.
    mail.smtp.userProvide the username of the SMTP account.
    mail.smtp.passwordProvide the password of the SMTP account.
    <adapterConfig type="email">
        <!-- Comment mail.smtp.user and mail.smtp.password properties to support connecting SMTP servers which use trust
            based authentication rather username/password authentication -->
        <property key="mail.smtp.from">abcd@gmail.com</property>
        <property key="mail.smtp.user">abcd</property>
        <property key="mail.smtp.password">xxxx</property>
        <property key="mail.smtp.host">smtp.gmail.com</property>
        <property key="mail.smtp.port">587</property>
        <property key="mail.smtp.starttls.enable">true</property>
        <property key="mail.smtp.auth">true</property>
        <!-- Thread Pool Related Properties -->
        <property key="minThread">8</property>
        <property key="maxThread">100</property>
        <property key="keepAliveTimeInMillis">20000</property>
        <property key="jobQueueSize">10000</property>
    </adapterConfig>
  2. The email templates for notifications are stored in the email-admin-config.xml file found in the <IS_HOME>/repository/conf/email folder. Add the SMS templates to the .xml file with ‘sms’ prefix.
    For example, this is a sample of an email template configuration. 

    type="accountConfirmation" display="AccountConfirmation

    Add a new template with the following name format for SMS notifications. 

    type="smsAccountconfirmation" display="smsAccountconfirmation
    Sample SMS notification template
    <configuration type="smsaccountconfirmation" display="smsaccountconfirmation" locale="en_US" emailContentType="text/html">         
    <subject>WSO2 - Self Registration OTP</subject>         
    <body>Your OTP is : {{confirmation-code}}</body>         
    <footer>---</footer>     
    </configuration>

    If you are using a WSO2 Identity Server 5.7.0 WUM updated pack, SMS notifications are managed using the registry and are no longer managed using the email-admin-config.xml file. For instructions, see Managing SMS Notification Templates Using the Registry.

  3. Create a new stream and add it to the <IS_HOME>/repository/deployment/server/eventstreams folder. A sample stream is given below.

    Sample stream
    {"name": "id_gov_sms_notify_stream","version": "1.0.0" } 
  4. Create a new publisher and add it to the <IS_HOME>/repository/deployment/server/eventpublishers folder.
    For more information, see HTTP Event Publisher in the WSO2 Data Analytics Server documentation. 

    Sample publisher
    <?xml version="1.0" encoding="UTF-8"?> 
    <eventPublisher name="HTTPOutputEventAdapter" processing="enable"     statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">   
    <from streamName="id_gov_sms_notify_stream" version="1.0.0"/>
    <mapping customMapping="enable" type="json">
    <inline>
    {"api_key"="<api_key>",
    "api_secret"="<api secret>",
    "from"="NEXMO",
    "to"={{mobile}},
    "text"={{body}}             
    }
    </inline>     
    </mapping>     
    <to eventAdapterType="http">         
    <property name="http.client.method">httpPost</property>
    <property name="http.url">https://rest.nexmo.com/sms/json</property>
    </to> 
    </eventPublisher>
  5. Configure the identity-event.properties file found in the <IS_HOME>/repository/conf/identity folder to subscribe the event handler to trigger notifications.

    Sample notification handler configuration
    module.name.13=default.notification.sender 
    default.notification.sender.subscription.1=TRIGGER_SMS_NOTIFICATION 
    default.notification.sender.subscription.TRIGGER_SMS_NOTIFICATION.stream=id_gov_sms_notify_stream:1.0.0
    default.notification.sender.subscription.TRIGGER_SMS_NOTIFICATION.claim.mobile=http://wso2.org/claims/mobile 
     Click here for more information

    Stream configurations

    In the sample notification handler configuration code given above, 'stream' is a keyword. You can define the stream id as shown below. The event is then subscribed to the channel that triggers the event.

    default.notification.sender.subscription.TRIGGER_SMS_NOTIFICATION.stream=id_gov_sms_notify_stream:1.0.0

    You can also define the claim URI using the following configuration. The handler will try to read the defined claim from the current user store and send it as the given attribute name 'sample_claim" to the event stream. 'claim' is a keyword used to the set the claims and 'sample_claim' is the attribute name used as the key which holds the value of the claim.

    default.notification.sender.subscription.TRIGGER_SMS_NOTIFICATION.claim.sample_claim=http://wso2.identity/sample/claim

    You can define a property and value and pass it to the event stream using the following configuration.

    default.notification.sender.subscription.TRIGGER_SMS_NOTIFICATION.testcustomattribute=testattributevalue
  6. Add the following configurations to the identity.xml file found in the <IS_HOME> /repository/conf/identity folder within the <server> tags to resolve the notification channel. This configuration only affects the user self-registration scenario. 

    <Notification> 
    	<DefaultNotificationChannel>EMAIL</DefaultNotificationChannel> 
    	<ResolveNotificationChannels>
    		<Enable>true</Enable>
    	</ResolveNotificationChannels>
    </Notification>
    PropertyDescriptionDefault Value
    DefaultNotificationChannel

    Determines the default notification channel for the server. Currently, WSO2 IS supports EMAIL and SMS as communication channels. Providing any other value will result in errors.


    These configurations are case sensitive. Always use uppercase characters.

    EMAIL
    ResolveNotificationChannels
    Enables notification channel resolving according to the notification channel selecting criteria. Disabling the configuration will resolve the notification channel to the server default notification channel.FALSE
  7. Add the following configurations to the identity.xml file found in the <IS_HOME>/repository/conf/identity folder inside the <SelfRegistration> tags. 

    <RegisterWithVerifiedChannels>true</RegisterWithVerifiedChannels>
    <API>
           <EnableDetailedResponseBody>True</EnableDetailedResponseBody>
    </API>
    PropertyDescriptionDefault Value
    RegisterWithVerifiedChannels
    Enables self-registration after pre-confirmation of the user account, with verified claims. If the property is not enabled, account confirmation is needed even though the account is pre-confirmed.FALSE
    EnableDetailedResponseBody
    Enables detailed API responses.FALSE
  8. Restart the server to apply configurations. 

Configuring the management console

  1. Start WSO2 Identity Server and access the management console. 
  2. Click List under Main >Claims and enable the Email Verified and Phone Verified claims for the default profile by selecting the "Supported by default" checkbox for the relevant claim. 
  3. Click Add under Main > Claims and add the following identity claim to track the user preferred notification channel. 

    DO NOT change the given claim. A different claim will not be supported by the APIs.

  4. Once you have added the claim, click List under Main > Claims and enable the newly added claim by selecting the "Supported by default" checkbox.
  5. Navigate to Main > Identity Providers > Resident and expand the Account Management Policies section.
  6. Expand the User Self Registration section and configure the following properties as required. 

    FieldDescription
    Enable Self User RegistrationEnable self-registration.
    Enable Account Lock On Creation EnabledEnable account locking during self-registration.
    Enable Notification Internally ManagementSelect if you want the notification handling to be managed by the WSO2 Identity Server. If the client application handles notification sending already, unselect it. This check only applies if User Self-Registration is enabled.
    Enable reCaptchaEnable reCaptcha for self-registration. See Configuring reCaptcha for Challenge Question-Based Password Recovery for more information.
    User self registration verification link expiry time

    Set the number of minutes for which the verification link should be valid. The verification code that is provided to the user to initiate the self sign-up flow will be invalid after the time specified here has elapsed.

    Alternatively, you can configure the expiry time in the identity.xml configuration file.

    <SelfRegistration>
        <VerificationCode>
            <ExpiryTime>1440</ExpiryTime>
        </VerificationCode>
    </SelfRegistration>
    User self registration SMS OTP expiry timeSet the number of minutes for which the SMS OTP should be valid. The minimum time should be one minute.


  7. Ensure that you have set User self registration SMS OTP expiry time and provided a suitable validity time for an SMS OTP.