<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shavindu Senadheera on Medium]]></title>
        <description><![CDATA[Stories by Shavindu Senadheera on Medium]]></description>
        <link>https://medium.com/@shavinsenadeera?source=rss-2c81d5b33129------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SpPt6bLTBxt9-5fsChdhXQ.jpeg</url>
            <title>Stories by Shavindu Senadheera on Medium</title>
            <link>https://medium.com/@shavinsenadeera?source=rss-2c81d5b33129------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 16:48:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shavinsenadeera/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Part 03: Handling self-signed users]]></title>
            <link>https://medium.com/@shavinsenadeera/part-03-handling-self-signed-users-4992a443ff13?source=rss-2c81d5b33129------2</link>
            <guid isPermaLink="false">https://medium.com/p/4992a443ff13</guid>
            <dc:creator><![CDATA[Shavindu Senadheera]]></dc:creator>
            <pubDate>Sun, 22 Jun 2025 10:28:44 GMT</pubDate>
            <atom:updated>2025-06-22T10:32:34.741Z</atom:updated>
            <content:encoded><![CDATA[<p>Let me begin with a question — <strong>why do we need to handle self-registered users separately?</strong></p><p>Have you thought about it?</p><p>Let me explain.</p><p>As discussed in <a href="https://medium.com/@shavinsenadeera/part-01-configuring-sso-on-wso2-apim-with-is-integration-cce89ad14bff"><strong>Part 01</strong></a> of this series, role mapping is required to assign the appropriate permissions to users. For example, in<a href="https://medium.com/@shavinsenadeera/part-01-configuring-sso-on-wso2-apim-with-is-integration-cce89ad14bff"> Part 01</a>, we mapped <strong>roles defined in the Identity Provider (IdP)</strong> with <strong>roles in the Service Provider (SP)</strong>.</p><p>But how were these roles retrieved?<br> They were received as <strong>group claims</strong> from the Identity Server (IS) and then mapped to <strong>role claims</strong> on the API Manager (APIM) side.</p><p>This claim-based role mapping is possible because the users authenticated via the Identity Server have pre-assigned roles (like devportal_role or publisher_role) that we explicitly map to Internal/subscriber and Internal/publisher in the SP.</p><p>However, <strong>self-registered users</strong>, who register directly through the Identity Server, <strong>do not possess the IdP roles</strong> such as devportal_role or publisher_role. As a result, we would need to manually assign these roles to each user — a process that quickly becomes inefficient and difficult to manage at scale.</p><p>To address this challenge, we need a more streamlined and automated solution.<br>In this Medium blog, we’ll explore how to handle self-registered users effectively and ensure they receive the necessary roles seamlessly.</p><h3>Prerequisites</h3><h4>Enabling Self-Regsitration feature on Identity Server.</h4><ol><li>Log in to the Carbon Management Console of the Identity Server.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qQcvSsSLv26LJjdgpqMl-w.png" /></figure><p>2. Click on the Resident under the Identity Providers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qou026Plm0wujzw-e_B8iQ.png" /></figure><p>3. Click on the User Onboarding and expand that section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r_KsW_i8Q7f7h1KipSXJyQ.png" /></figure><p>4. Expand the Self Registration under the User Onboarding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4GeYi6pS9WiB4wKKCWLe5A.png" /></figure><p>5. Enable the user self registration.</p><p>User self registration: true ✅</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6W_kv6lUyp8zgmgfclx6IA.png" /></figure><p>Now, users will be able to see the <strong>Create Account </strong>button on the login page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*w2Z3lZrFBCV2NtRR5CTuUg.png" /><figcaption>Login Page of IS</figcaption></figure><h3>Issue of the current implementations</h3><p>Even after successfully creating and confirming the account, attempting to log in to an API Manager portal via the Identity Server will result in the following error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*k_srJsXg64Pr5iKHFY7H0g.png" /></figure><p>Let’s debug the issue. If you inspect the user’s profile, you’ll notice that the <strong>Groups</strong> attribute is empty. This is because the user only has the default roles: <strong>Internal/selfsignup</strong> and <strong>Internal/everyone</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vl_JglA-G7iewqYdniXCDw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*URflEIrHuE07ezBWBkstJw.png" /></figure><p>This issue arises specifically with self-registered users, as they are not automatically assigned the necessary roles required by the API Manager.</p><p><strong>Solution</strong></p><p>To address this, we can implement a solution using an <strong>Adaptive Authentication script</strong>. This script will dynamically assign the appropriate roles to self-registered users during the authentication flow.</p><p>Follow the steps below to apply this solution:</p><ol><li>Log in to the <strong>Carbon Management Console</strong> of the Identity Server.</li><li>Navigate to the <strong>Service Provider</strong> created in <a href="https://medium.com/@shavinsenadeera/part-01-configuring-sso-on-wso2-apim-with-is-integration-cce89ad14bff"><strong>Part 01</strong></a> of this series.</li><li>Expand the <strong>Local &amp; Outbound Authentication Configuration</strong> section.</li><li>Click on <strong>Advanced Configuration</strong> to proceed.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PCALKFy1EQkpikDIl_THIg.png" /></figure><p>5. Locate the section titled <strong>Script-Based Adaptive Authentication</strong>.</p><p>6. Expand this section to view the configuration options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vRQP1BhiohgxWNiOqoGoww.png" /></figure><p>7. Use the following script to implement the required functionality.</p><p><em>Overall Responsibility of this script:</em></p><p><em>This script:</em></p><ul><li><em>Implements </em><strong><em>multi-factor authentication (MFA)</em></strong><em>.</em></li><li><em>Enables </em><strong><em>OTP resend handling</em></strong><em>.</em></li><li><em>Ensures </em><strong><em>users who self-sign up</em></strong><em> receive required additional roles (like </em><em>devportal_role) </em><strong><em>after verifying their identity with OTP</em></strong><em>.</em></li></ul><pre>var rolesShouldHave = [&#39;Internal/selfsignup&#39;,&#39;Internal/subscriber&#39;];<br>var rolesToStepUp = [&#39;devportal_role&#39;];<br><br>var onLoginRequest = function(context) {<br>   executeStep(1, {<br>       onSuccess: function(context) {<br>           executeOtpStep(context);<br>       }<br>   });<br>};<br><br>var executeOtpStep = function(context) {<br>   // Define authentication options for step 2<br>   executeStep(2, {<br>       authenticationOptions: [{<br>           authenticator: &#39;EmailOTP&#39;<br>       }, {<br>           authenticator: &#39;SMSOTP&#39;<br>       }],<br>       authenticatorParams: {<br>           local: {<br>               &#39;EmailOTP&#39;: {<br>                   &#39;enableRetryFromAuthenticator&#39;: &#39;true&#39;<br>               },<br>               &#39;SMSOTP&#39;: {<br>                   &#39;enableRetryFromAuthenticator&#39;: &#39;true&#39;<br>               }<br>           }<br>       }<br>   }, {<br>       onSuccess: function(context) {<br>           var user = context.steps[1].subject;<br>           // Check and assign roles only after successful OTP verification<br>           var hasRoleSelfsignup = hasAnyOfTheRoles(user, rolesShouldHave);<br>           var hasRoleDevportal = hasAnyOfTheRoles(user, rolesToStepUp);<br><br>           if (hasRoleSelfsignup &amp;&amp; !hasRoleDevportal) {<br>               assignUserRoles(user, rolesToStepUp);<br>           }<br>       },<br>       onFail: function(context) {<br>           // Get the current authenticator<br>           var currentAuthenticator = context.currentAuthenticator;<br><br>           // Check if this is a resend request<br>           var resendCode = context.request.params.resendCode;<br>           Log.info(&quot;Resend code request: &quot; + resendCode + &quot; for authenticator: &quot; + currentAuthenticator);<br><br>           // Create authenticator params object<br>           var authParams = {<br>               local: {}<br>           };<br>           authParams.local[currentAuthenticator] = {<br>               &#39;enableRetryFromAuthenticator&#39;: &#39;true&#39;<br>           };<br><br>           // Retry with the same authenticator<br>           executeStep(2, {<br>               authenticationOptions: [{<br>                   authenticator: currentAuthenticator<br>               }],<br>               authenticatorParams: authParams<br>           });<br>       }<br>   });<br>};</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JE7HOSPW6JGZL4L84XYnag.png" /></figure><p>After adding the Adaptive Authentication script, update the <strong>Service Provider</strong> configuration to save the changes.</p><p>🎉 <strong>Congratulations!</strong> You’ve successfully completed all parts of this series.<br> With this setup, all user scenarios are now fully supported, ensuring seamless and secure login experiences for every user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dRrt_msBp2N12oAtAEMY8Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4992a443ff13" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 02: Configuring Email and SMS OTP— MFA for Login]]></title>
            <link>https://medium.com/@shavinsenadeera/part-02-configuring-email-and-sms-otp-mfa-for-login-d57333f1987c?source=rss-2c81d5b33129------2</link>
            <guid isPermaLink="false">https://medium.com/p/d57333f1987c</guid>
            <dc:creator><![CDATA[Shavindu Senadheera]]></dc:creator>
            <pubDate>Sun, 22 Jun 2025 03:23:46 GMT</pubDate>
            <atom:updated>2025-06-22T10:31:51.686Z</atom:updated>
            <content:encoded><![CDATA[<h3>Configuring Email OTP Configuration for Multi-Factor Authentication</h3><p>To test Email OTP functionality with the Identity Server, you can use a popular fake email server service called <strong>Mailtrap</strong>. For detailed information, please refer to its <a href="https://mailtrap.io/">official website</a>.</p><p>Once you’ve signed up and accessed your Mailtrap inbox, you’ll find the necessary SMTP details such as <strong>Host</strong>, <strong>Port</strong>, <strong>Username</strong>, and <strong>Password</strong>.</p><p>Next, open the deployment.toml file of the Identity Server and add the following configuration to set up the email output adapter accordingly.</p><pre>[output_adapter.email]<br>from_address= &quot;abcd@gmail.com&quot;<br>username= &quot;71bb01ccc14de0&quot;<br>password= &quot;a065868876be75&quot;<br>hostname= &quot;sandbox.smtp.mailtrap.io&quot;<br>port= 25</pre><p>Restart the Identity Server to apply the changes.</p><h4>Configuring and Enabling Email OTP on the Identity Server</h4><ol><li>Log in to the <strong>Carbon Management Console</strong>.</li><li>Click the <strong>Add</strong> button to create a new <strong>Identity Provider</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rLXt-GxXQdfT_ASDIq1P6A.png" /></figure><p>3. On the <strong>Add Identity Provider</strong> page, you will see a form where you can specify the name of the Identity Provider. You may choose any name based on your preference. In this example, the Identity Provider is named <strong>EmailOTP</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1WW23Y9eWA7AnmKU_TscEQ.png" /></figure><p>4. Expand the Federated Authenticators by clicking on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tixNRVyHZWdROrIgacovJg.png" /></figure><p>5. Expand the Email OTP Configuration by clicking on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*06-O4bIBOwJidWLlHXon8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b5T78CZmHHr5aiHTm7YVjQ.png" /></figure><p>7. Enable the Email OTP on IS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oVb7g7pmQSK6GoE5W0vOSg.png" /></figure><p>8. Now, navigate to the <strong>Service Provider</strong> that was created in <a href="https://medium.com/@shavinsenadeera/part-01-configuring-sso-on-wso2-apim-with-is-integration-cce89ad14bff"><strong>Part 01</strong></a> of this series.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UTTDZqd1RFY0G6UA6tz8MA.png" /></figure><p>9. Expand the Local &amp; Outbound Authentication Configuration section by clicking on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkcdRSG1dE_mo-8zr9GYRA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JTpPrycmFfNC6xILCb5aSw.png" /></figure><p>10. Click on the Advanced Configuration as highlighted in the below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*FrtqFKMJkeDr6mEExwRvHA.png" /></figure><p>11. Click on the Add Authentication Step button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sq8XOvtNWkRLeiBUD8_SGg.png" /></figure><p>12. In Step 1, expand the Local Authenticators section and select Username &amp; Password as the primary authentication method. Then, click Add Authenticator to include it as the first step in the login flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SgnCCeSRCn5DX9cn7PXEhw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*utbQKnUmXUTHoPQyGIGf_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fvyCwJcGAgVbxUTI3qptWw.png" /></figure><p>13. Click Add Authentication Step once more to include the second step in the login flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WaMNXECN-YQtNTxtWWePdg.png" /></figure><p>14. In the second step, expand the Federated Authenticators section. To configure Email OTP as the second step in the login flow, select Email OTP from the dropdown and click Add Authenticator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXkB8KRlhw426j9hY2flCA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0FyOj9E6W83dztN__1KOJw.png" /></figure><p><strong>Congratulations! 🎉 </strong>Email OTP has now been successfully configured as part of the MFA login flow. From this point forward, when a user logs in through the Identity Server, an Email OTP will be sent to the email address specified in their user profile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VChfLJcFtYKUpRhjvb-rHw.png" /></figure><h3>Configuring SMS OTP Configuration for Multi-Factor Authentication</h3><p>For a complete step-by-step guide on integrating SMS functionality in the Identity Server using Twilio, please refer to my detailed Medium blog post.</p><p><a href="https://medium.com/@shavinsenadeera/integrating-twilio-sms-otp-with-wso2-identity-server-6-1-0-b7f14803c084">How to Integrate Twilio SMS OTP Authentication with WSO2 Identity Server 6.1.0 [Complete Guide]</a></p><p><strong>🎉 We’ve successfully completed the second part of this series.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PoRYEo9AY6sDopl4" /><figcaption>Photo by <a href="https://unsplash.com/@1nimidiffa_?utm_source=medium&amp;utm_medium=referral">Nimi Diffa</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let’s proceed to <strong>Part 3</strong>, where we will address handling <strong>self-registered users</strong> within the login flow.</p><p><a href="https://medium.com/@shavinsenadeera/part-03-handling-self-signed-users-4992a443ff13">Part 03: Handling self-signed users</a></p><h3>References</h3><p>[1] — <a href="https://is.docs.wso2.com/en/6.1.0/deploy/configure-email-sending/">https://is.docs.wso2.com/en/6.1.0/deploy/configure-email-sending/</a><br>[2] — <a href="https://is.docs.wso2.com/en/6.1.0/guides/mfa/2fa-email-otp/">https://is.docs.wso2.com/en/6.1.0/guides/mfa/2fa-email-otp/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d57333f1987c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 01: Configuring SSO on WSO2 APIM with IS — Integration]]></title>
            <link>https://medium.com/@shavinsenadeera/part-01-configuring-sso-on-wso2-apim-with-is-integration-cce89ad14bff?source=rss-2c81d5b33129------2</link>
            <guid isPermaLink="false">https://medium.com/p/cce89ad14bff</guid>
            <dc:creator><![CDATA[Shavindu Senadheera]]></dc:creator>
            <pubDate>Sun, 22 Jun 2025 03:23:22 GMT</pubDate>
            <atom:updated>2025-06-22T10:30:15.416Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 01: Configuring SSO on WSO2 APIM with IS — Integration</h3><p>This guide provides a complete walkthrough for configuring <strong>Single Sign-On (SSO)</strong> using <strong>WSO2 API Manager (APIM) version 4.2.0</strong> with <strong>WSO2 Identity Server (IS) version 6.1.0</strong>.</p><p>As a first part, we are looking at the integration of the WSO2 APIM 4.2.0 with WSO2 IS 6.1.0 for Single-Sign-On.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HQCSTprPFrJ4jourNI-dWg.png" /></figure><h3>Start both APIM and IS servers</h3><p>We begin by running both the APIM 4.2.0 and IS 6.1.0 servers.</p><blockquote><em>💡 </em><strong><em>Note</em></strong><em>: If you’re hosting both servers on the same machine, ensure they use different port offsets to avoid conflicts.</em></blockquote><ul><li><strong>APIM Offset</strong>: 0</li><li><strong>IS Offset</strong>: 1</li></ul><p>To set the offset, update the following configuration:</p><h4>For WSO2 Identity Server:</h4><p>Open deployment.toml in the &lt;IS_HOME&gt;/repository/conf/ directory and add:</p><pre>[server]<br>offset = 1</pre><h4>For WSO2 API Manager:</h4><p>No changes are needed if APIM uses the default offset (0).</p><h3>Step 1: Configure APIM as a Service Provider (SP) in Identity Server</h3><h4>1.1 Access the IS Management Console</h4><p>This step includes the creating a APIM as a Service Provider on the Identity Server.</p><ul><li>Open the browser and go to the carbon portal of the Identity Server.<br><em>In my case it is “https://is.dev.wso2.com:9444/carbon” as I am using port offset as 1 for Identity Server.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pvh0Iuxegw7W9LtmVY4HfQ.png" /></figure><ul><li>Login into the Carbon Portal with credentials of the super admin.</li></ul><h3><strong><em>Adding APIM as a Service Provider in the Identity Server</em></strong></h3><h4>2. Register APIM as a Service Provider</h4><p>2.1 Click on the Add under the Service Providers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xLfqZt8aKKepE_kfIpX8Nw.png" /><figcaption>Landing page of Carbon Portal</figcaption></figure><p>2.2 After redirected to the service provider we can set the service provider name as below. You can specify any name here.</p><p><em>Then click on the “Register” button to save the changes.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zKAa_H-0eeeS-HoVj96IKA.png" /><figcaption>Creating Service Provider called “SAMLApp”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DoQksgK40eZaBtSfT7WPnw.png" /><figcaption>After Registering the Service Provider</figcaption></figure><h4>3. Upload APIM’s Certificate</h4><p>3.1 Then, we need to select the “Upload SP certificate” and here we need to upload the <strong>certificate in the Primary Keystore </strong>of the APIM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Su1dTsHIPn9bxReGVqdExA.png" /><figcaption>Service Provider — Upload SP (APIM) Certificate</figcaption></figure><blockquote><strong><em>Note 💡</em></strong></blockquote><blockquote><em>Why Certificate in the Primary Keystore?</em></blockquote><blockquote><em>Because in the APIM, the primary keystore is the one which is used to sign SAML responses, sign JWT, and OAuth ID Token as well.</em></blockquote><blockquote>You can check the primary certificate of the APIM by reffering to the keystore.primary in the deployment.toml which resides in the &lt;APIM_HOME&gt;/repository/conf.</blockquote><blockquote>Go to the &lt;APIM_HOME&gt;/repository/resources/security.</blockquote><blockquote>Export the primary certificate from the wso2carbon.jks file.<br>(here, since I am using the default wso2carbon alias I am exporting the cert with that alias)</blockquote><blockquote>keytool -exportcert -alias wso2carbon -keystore wso2carbon.jks -rfc -file primarycertapim.pem -storepass wso2carbon</blockquote><p>3.2 Upload the exported certificate in the carbon portal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BtjBgoKqllaf0IMSQ0Z87Q.png" /><figcaption>Service Provider — Uploaded the SP Certificate</figcaption></figure><h4>4. Configure Claims</h4><p>4.1 Expand the Claim Configuration section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p8cIUa7pOgWb8O6HaQfRDg.png" /></figure><p>4.2 Required claim settings for the SP:</p><p>1. Select Claim mapping Dialect</p><ul><li>Action: Select Local Claim Dialect</li></ul><p>2. Requested Claims</p><ul><li>Action: Click on the Add Claim URI button.</li><li>Local Claim: <a href="http://wso2.org/claims/groups">http://wso2.org/claims/groups</a></li><li>Mandatory Claim : Enable (✔️) the mandatory flag. This guarantees this claim is always included in SAML responses.</li></ul><p>3. Subject Claim URI</p><ul><li>Action: Select <a href="http://wso2.org/claims/username">http://wso2.org/claims/username</a>from the dropdown.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-uqImuOGwm3lCHkY6gqtBw.png" /></figure><h4>5. Enable SAML SSO</h4><p>5.1 Expand the Inbound Authentication Configuration and SAML2 Web SSO Configuration sections as below. Then click on the Configure button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XuAIZqbJm11JgKhHwmWb3Q.png" /></figure><p>5.2 This action will render the configuration page displayed in the following screenshot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aij_cnnVvUtiTZlPefkq3g.png" /></figure><p>Complete these mandatory Service Provider configurations:</p><ul><li>Issuer: SAMLApp</li><li>Assertion Consumer URLs : <a href="https://am.dev.wso2.com:9443/commonauth">https://am.dev.wso2.com:9443/commonauth</a></li><li>Response Signing Algorithm : <a href="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256">http://www.w3.org/2001/04/xmldsig-more#rsa-sha256</a></li><li>Enable Response Signing : true ✅</li><li>Enable Signature Validation in Authentication Requests and Logout Requests : true ✅</li><li>Enable Single Logout : true ✅</li><li>Enable Attribute Profile : true ✅</li><li>Include Attributes in the Response Always : true ✅</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*49sEYIpfKH3TxiRtxJwUWg.png" /></figure><p>5.3 Click on the Update button to save the changes.</p><h4>6. Roles Configurations</h4><p>When configuring Single Sign-On (SSO), it is essential to define role mappings between the Identity Provider (IdP — WSO2 Identity Server) and the Service Provider (SP — WSO2 API Manager).</p><p>To allow users to access the Developer Portal and Publisher Portal in API Manager, specific roles must be assigned:</p><ul><li><strong>Internal/subscriber</strong> — Required for logging into the Developer Portal</li><li><strong>Internal/publisher</strong> — Required for accessing the Publisher Portal</li></ul><p>These roles (<strong>Internal/subscriber</strong>, <strong>Internal/publisher</strong>) are defined within the Service Provider (APIM) but do <strong>not</strong> exist by default in the Identity Provider (IS). Therefore, corresponding roles must be created in the IdP and mapped accordingly.</p><p>In this example, we create the following roles in the Identity Server:</p><ul><li>devportal_role – mapped to Internal/subscriber</li><li>publisher_role – mapped to Internal/publisher</li></ul><p>These roles ensure the user can successfully authenticate and access the appropriate APIM portals.</p><blockquote><em>Note 💡</em></blockquote><blockquote><em>What about access to the </em><strong><em>Admin Portal</em></strong><em>? 🤔</em></blockquote><blockquote><em>To log in to the Admin Portal, the user must be assigned the </em><em>admin role. Since the </em><em>admin role exists with the same name in both the Identity Server (IS) and API Manager (APIM), there is no need to configure an explicit role mapping for this case.</em></blockquote><p>You can create these roles in the Identity Server by following the steps below:</p><p>6.1 Click on the Add button under the Users and Roles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Okl4B3ecNfzHDkTN87aEVA.png" /></figure><p>6.2 Click Add New Role button to create a new role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GUUD5_nJ1oziyvrB4k0o9w.png" /></figure><p>6.3 Create a new role devportal_role and click on a Finish to save the role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iwX2dwy7uSzxz9p__meVCA.png" /></figure><p>6.4 Similarly, you can create the publisher_role following the same process.</p><p>Next, let’s create a new user to whom we can assign the two newly created roles.</p><p>6.5 Click Add New User button to create a new role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*feULM1pkgEZJZh4xOwAbJg.png" /></figure><p>6.6 Enter the <strong>Username</strong>, <strong>Password</strong>, and <strong>Confirm Password</strong>, then click <strong>Next</strong> to proceed with assigning the appropriate roles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xRodnaLNrzKpJ_HW8rLC_w.png" /></figure><p>6.7 Assign the devportal_role and publisher_role to the newly created user, then click <strong>Finish</strong> to complete the user creation process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I5r8lSdoZjRbw51yrAkUyA.png" /></figure><h3>Step 2: Configuring the IS as a Identity Provider for WSO2 APIM</h3><h4>1. Configuring an IdP</h4><p>1.1 Access the API Manager’s Carbon Management Console by navigating to: https://&lt;hostname&gt;:&lt;port&gt;/carbon</p><p>1.2 Log in to the Carbon Management Console using the super admin credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p2QZ9b-P04RNZ80sPpm-fw.png" /></figure><p>1.3 Upon successful login, navigate to Identity Providers and click the Add button, as highlighted in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*McBMPT-MRGqP_0w6mnmsqw.png" /></figure><p>You will then be redirected to the following configuration page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f65qmD9_h4cvJAKJ3cklEA.png" /></figure><p>1.4 The form contains multiple fields; here, you can focus on completing the mandatory fields.</p><ul><li>Identity Provider Name: You may enter any name that suits your requirements. In this example, “WSO2ISIdP” is used as the Identity Provider (IdP) name.</li><li>Choose IDP certificate type: We can choose Upload IDP certificate.</li><li>Identity Provider Public Certificate: As we uploaded the Service Provider (SP) certificate to the Identity Server in steps 3.1 and 3.2, similarly, you can upload the primary keystore certificate of the Identity Server.</li></ul><p>1.5 Next, click the Register button to save and apply the Identity Provider configurations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jMI7Tc9ct6z2D6xX5cwnzA.png" /></figure><h4><strong>2. Claim Configurations</strong></h4><p>2.1 Expand the Basic Claim Configuration section under Claim Configuration by clicking on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVd5PIRxCawoo6YFx2JusA.png" /></figure><p>2.2 Select the Define Custom Claim Dialect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vu8gU2MCUKwlmmPFeEvKvQ.png" /></figure><p>2.3 Click the Add Claim Mapping to add a cliam mapping.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XPGwW92u8LEB4NNnJAM3OQ.png" /></figure><p>2.4 Next, we will map the Identity Provider (IdP) claims to the Service Provider (SP) local claims.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mea2NPZJUfUBgMG-b3Kpww.png" /></figure><p>2.5 map the roles by specifying the <strong>Role Claim URI</strong> as shown below.</p><ol><li>Identity Provider Claim URIs:</li></ol><ul><li>Identity Provider Claim URI : http://wso2.org/claims/groups</li><li>Local Claim URI : http://wso2.org/claims/roles</li></ul><p>2. Role Claim URI: http://wso2.org/claims/groups</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*45LuJ3YstJuxBZz2cWDQUA.png" /></figure><h4>3. Role Configurations</h4><p>In this step, we map the roles created on the Identity Server (IS) side (devportal_role, publisher_role) to the corresponding roles on the Service Provider (API Manager) side (Internal/subscriber, Internal/publisher):</p><ul><li>devportal_role → Internal/subscriber</li><li>publisher_role → Internal/publisher</li></ul><p>3.1 Click on the Role Configuration to expand the section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sOc_kIJ7iJlTQq0RNRRyFw.png" /></figure><p>3.2 Click the Add Role Mapping to add a role mapping.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aDty6LhESiZl2gqjYv9vqQ.png" /></figure><p>3.3 Map the IdP roles with the SP roles as illustrated in the below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5PG_EElGT3nMr_msENl4OQ.png" /></figure><h4>4. SAML Configurations</h4><p>4.1 Click on the SAML2 Web SSO Configuration under the Federated Authenticators.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hSXExzkHCGNNjxJzcGwL8w.png" /></figure><p>4.2 You will be able to see the following form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*y4DJJ1Mwb326Z7Z1w4tEwQ.png" /></figure><p>4.3 You need to fill out the following mandatory fields.</p><ul><li>Enable SAML2 Web SSO: true ✅</li><li>Service Provider Entity ID: Enter the name of the Service Provider. In this example, the application is named <strong>SAMLApp</strong>.</li><li>Identity Provider Entity ID: is.dev.wso2.com:9444</li><li>SSO URL: <a href="https://is.dev.wso2.com:9444/samlsso">https://is.dev.wso2.com:9444/samlsso</a> (replace with https://&lt;IS_hostname&gt;:&lt;IS_port&gt;/samlsso accordingly)</li><li>Enable Authentication Request Signing: true ✅</li><li>Single Logout Profile: true ✅</li><li>Enable Logout Request Signing: true ✅</li><li>Enable Authentication Response Signing: true ✅</li><li>Signature Algorithm: Select RSA with SHA256</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*4d5ZP8Trb5lnL7n4be-aGA.png" /></figure><h4>5. Just-In-Time Provisioning</h4><p>5.1 Expand the Just-In-Time Provisioning section by clicking on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D2bGdsAj3BgFE1LWwoC17Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RjuhEkCOxjfns6_ue6yFDg.png" /></figure><p>5.2 Select the Always provision to User Store Domain option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9C7tbFvo7_0TadC4SIuyg.png" /></figure><p><strong>6. Configure the Developer Portal to use Federated Authentication.</strong></p><p>6.1 Click on the List under the Service Providers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BytsI6AqoNgKSJz7XR-GSA.png" /></figure><p>6.2 Click the <strong>Edit</strong> button under the <strong>Actions</strong> column for apim_devportal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T-TpCsnTsO2l_53bMxiQzw.png" /></figure><p>6.3 Expand the Local &amp; Outbound Authentication Configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzUOl5AwsExh0B7R1R3KnA.png" /></figure><p>6.4 Enable Federated Authentication, then select the Identity Provider (IdP) you previously created from the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*up8Mk8Faq7GD9f4WaJWjmQ.png" /></figure><p>6.5 Additionally, select the option Assert identity using mapped local subject identifier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0E5TzojAfsYBC3-v1uxqxw.png" /></figure><p>Repeat the same configuration steps for the Publisher (<strong>SP name: apim_publisher</strong>) and the Admin Portal (<strong>SP name: apim_admin_portal</strong>).</p><p><strong>Congratulations! 🎉 You’ve successfully completed the first part of the integration.</strong></p><p>You should now be able to log in to all three portals.</p><p>But the end is the beginning! 😃</p><p>Let’s move on to <a href="https://medium.com/@shavinsenadeera/part-02-configuring-email-and-sms-otp-mfa-for-login-d57333f1987c"><strong>Part 2</strong></a>, where we’ll enable <strong>Multi-Factor Authentication (MFA)</strong> in the login flow.</p><p><a href="https://medium.com/@shavinsenadeera/part-02-configuring-email-and-sms-otp-mfa-for-login-d57333f1987c">Part 02: Configuring Email and SMS OTP— MFA for Login</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g-gOptptHi0qyYaZ" /><figcaption>Photo by <a href="https://unsplash.com/@awcreativeut?utm_source=medium&amp;utm_medium=referral">Adam Winger</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>References:</h3><p>[1] — <a href="https://apim.docs.wso2.com/en/4.2.0/reference/customize-product/extending-api-manager/saml2-sso/configuring-identity-server-as-idp-for-sso/">https://apim.docs.wso2.com/en/4.2.0/reference/customize-product/extending-api-manager/saml2-sso/configuring-identity-server-as-idp-for-sso/</a><br>[2] — <a href="https://apim.docs.wso2.com/en/4.2.0/install-and-setup/setup/security/configuring-keystores/configuring-keystores-in-wso2-api-manager/">https://apim.docs.wso2.com/en/4.2.0/install-and-setup/setup/security/configuring-keystores/configuring-keystores-in-wso2-api-manager/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cce89ad14bff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Integrate Twilio SMS OTP Authentication with WSO2 Identity Server 6.1.0 [Complete Guide]]]></title>
            <link>https://medium.com/@shavinsenadeera/integrating-twilio-sms-otp-with-wso2-identity-server-6-1-0-b7f14803c084?source=rss-2c81d5b33129------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7f14803c084</guid>
            <dc:creator><![CDATA[Shavindu Senadheera]]></dc:creator>
            <pubDate>Fri, 25 Apr 2025 03:40:21 GMT</pubDate>
            <atom:updated>2025-04-28T06:14:03.530Z</atom:updated>
            <content:encoded><![CDATA[<h4>Step-by-step tutorial to configure Twilio SMS-based OTP authentication in WSO2 IS 6.1.0 for secure login and SSO.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mXDI3Ib0kNiSTos5SDUGvQ.png" /></figure><h3>📄 Summary</h3><p>In this article, we’ll walk through the step-by-step process of integrating <strong>Twilio as an SMS-based OTP provider</strong> with <strong>WSO2 Identity Server 6.1.0</strong>. You’ll learn how to configure your Twilio account, generate the necessary credentials, and set up SMS OTP authentication in WSO2 IS. We’ll also cover how to handle service provider configurations, including mandatory claims like the mobile number, and how to properly define authentication steps to support SMS OTP in your login flows. Whether you’re building a secure SSO solution or simply exploring WSO2’s federated authentication capabilities, this guide will help you get started quickly and confidently.</p><h3>🔗 Setting up the Twilio Account</h3><p>To get started, head over to the official <a href="https://www.twilio.com/">Twilio</a> website and sign up using your Google account or by entering your email and the required information manually.</p><p>Once registered, you’ll be redirected to the Twilio Console, where you’ll be prompted to verify a phone number. This number can later be used to send SMS OTPs. (See the image below.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*feG16Xm-1aQRMdgqW6qmTA.png" /></figure><p>After verifying your phone number, Twilio will guide you to a page to back up your account recovery code. (Refer to the image below.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gDFcXq1pXC4dUq7PgeMQvg.png" /></figure><p>Next, you’ll be asked to provide some basic information, such as your reason for using Twilio and your billing country.</p><p>Finally, you’ll land on the Twilio Console dashboard. Here, you’ll find your <strong>Account SID</strong> and <strong>Auth Token</strong>, which are essential credentials for authenticating API requests with your Twilio account.</p><p>Twilio also provides a free trial credit of over $15, allowing you to explore and test its features.<br>(Please refer to the following images for a clearer understanding of each step.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pU5t8V_SwXlKp6U2t_SYLA.png" /></figure><h4>Sending an OTP via Twilio: What Data Do We Need?</h4><p>To send an SMS (such as an OTP) using Twilio, you’ll need to make an HTTP POST request to Twilio’s Messaging API. Here’s a sample cURL command that demonstrates how to send a message to a phone number</p><pre>curl --location --request POST &#39;https://api.twilio.com/2010-04-01/Accounts/&lt;Account_SID&gt;/Messages.json&#39; \<br>--header &#39;Authorization: Basic &lt;Base64_Encoded(Account_SID:Auth_Token)&gt;&#39; \<br>--form &#39;To=&quot;+94111111111&quot;&#39; \<br>--form &#39;Body=&quot;Hey, this is a sample message&quot;&#39; \<br>--form &#39;From=&quot;+1911111111&quot;&#39;</pre><p>Let’s break this down:</p><h4>✅ API Endpoint (URL)</h4><p>The API endpoint used to send a message is:</p><pre>https://api.twilio.com/2010-04-01/Accounts/&lt;Account_SID&gt;/Messages.json</pre><p>Replace &lt;Account_SID&gt; with your actual Twilio Account SID</p><p><strong>Example:</strong></p><p>If your Account SID is 123, the final endpoint will look like:</p><pre>https://api.twilio.com/2010-04-01/Accounts/123/Messages.json</pre><h4>🧾 Required Form Data</h4><p>Twilio requires the following form fields to send a message:</p><ul><li><strong>To</strong>: The recipient’s phone number (including the country code).<br> <em>Example: </em><em>+94111111111</em></li><li><strong>Body</strong>: The content of the SMS.<br> <em>Example: </em><em>&quot;Hey, this is your OTP code&quot;</em></li><li><strong>From</strong>: A Twilio-verified phone number (or your Twilio number) used to send the message.<br> <em>Example: </em><em>+1911111111</em></li></ul><h4>🔐 Authorization Header</h4><p>Twilio uses <strong>Basic Authentication</strong>. The authorization header must contain a Base64-encoded string of your Account SID and Auth Token, separated by a colon.</p><p><strong>Format:</strong></p><pre>Authorization: Basic &lt;Base64_Encode(Account_SID:Auth_Token)&gt;</pre><p>For example, if your credentials are:</p><ul><li><strong>Account SID</strong>: ACxxxxxxxxxxxx</li><li><strong>Auth Token</strong>: yyyyyyyyyyyyyy</li></ul><p>Then encode the string ACxxxxxxxxxxxx:yyyyyyyyyyyyyy using Base64 and include it in your Authorization header.</p><h4>🔍 Where Does the “From” Number Come From?</h4><p>You might now be wondering:<br> <em>“We have the </em><em>To and </em><em>Body fields ready — but where do we get the </em><em>From number?”</em></p><p>Unlike the To number, you <strong>can’t use just any random phone number as the </strong><strong>From number</strong> when sending messages via Twilio. Twilio requires you to use a <strong>verified or purchased phone number</strong> associated with your account. These are the only numbers allowed to send SMS through their platform.</p><h4>📌 How to Get a Valid “From” Number</h4><p>To register or obtain a phone number that can be used as the From field:</p><ol><li><strong>Go to your Twilio Console.</strong></li><li>Navigate to:<br> <strong>Phone Numbers → Manage → Active Numbers<br></strong><em>(Refer to the screenshot below for guidance.)</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sxcbifwxIfnfdS44rigP2g.png" /></figure><p>Initially, you’ll see that your account doesn’t have any active phone numbers available for sending messages.</p><h4>🛠️ Two Ways to Get a Twilio Phone Number</h4><p>Twilio provides two options:</p><h4>1. Buy a Phone Number</h4><p>This is the easiest and most straightforward option, especially for testing and demos.</p><ul><li>Click on the <strong>“Buy a number →”</strong> button.</li><li>You’ll be taken to a page where you can search for available phone numbers based on country, capabilities (SMS, Voice, etc.), or specific patterns. Please refer to the below screenshot.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vn1SXn5wuVMK5eOXY1q6YQ.png" /></figure><ul><li>Once you find a number you like, click <strong>Buy</strong> to add it to your account.</li></ul><h4>2. Port an Existing Number</h4><p>If you already own a phone number, you can request to port it to Twilio. However, <strong>porting a number requires a paid Twilio account</strong>, so this is more suitable for production use cases.</p><p>Since we’re focusing on a demo or test setup, I’ll stick with the first option: buying a number.</p><h4>✅ Verifying Your New Phone Number</h4><p>After purchasing the number:</p><ul><li>Return to <strong>Phone Numbers → Manage → Active Numbers</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vfKdPXNRf5vj-X3lTN3PMw.png" /></figure><ul><li>You’ll now see your newly purchased number listed here.</li></ul><p>This number becomes your <strong>From</strong> number for sending messages.</p><h4>🎉 You’re Ready!</h4><p>Now that you have all three required parameters:</p><ul><li><strong>To</strong>: The recipient’s phone number</li><li><strong>Body</strong>: The message content</li><li><strong>From</strong>: Your verified/purchased Twilio number</li></ul><p>You’re fully set to send OTPs or any SMS messages via Twilio’s Messaging API.</p><h3>🔗 Integrating Twilio with WSO2 Identity Server</h3><p>To enable SMS-based OTP functionality using Twilio in WSO2 Identity Server (IS), you need to configure an Identity Provider (IdP) within the WSO2 IS Carbon Management Console. Follow these steps to get it set up:</p><h4>Step 1: Log in to the Carbon Management Console</h4><p>Navigate to your WSO2 Identity Server’s Carbon Portal and log in using admin credentials (typically at https://&lt;your-server-host&gt;:&lt;your-server-port&gt;/carbon).</p><h4>Step 2: Create a New Identity Provider</h4><ol><li>In the left menu, go to: <strong>Identity Providers → Add</strong></li><li>Provide a name for the new identity provider.<br> For example: smsOTP</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mOhU9LiqEi-Yt_Z6JFjnWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1bH3tC3wSl9jf116U7zz8g.png" /></figure><h4>Step 3: Configure SMS OTP as a Federated Authenticator</h4><ol><li>Expand the <strong>“Federated Authenticators”</strong> section.</li><li>Locate and expand the <strong>“SMS OTP Configuration”</strong> option.</li></ol><p>You’ll now see several fields to fill out. Here’s what each one means and how to fill it correctly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vthEovvrYgvAXRZIfiCciQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rTUAfo9VzdPw0rlGYbuPKQ.png" /></figure><h4>Step 4: SMS OTP Configuration Fields</h4><ul><li><strong>✅ Enable<br></strong>Tick this checkbox to activate SMS OTP functionality for this IdP.</li><li><strong>🔗 SMS URL</strong><br>Use the URL for Twilio’s messaging API, replacing &lt;Your_Account&gt; with your actual <strong>Account SID</strong>.<br> <br>Example:</li></ul><pre>https://api.twilio.com/2010-04-01/Accounts/123/Messages.json</pre><ul><li><strong>📬 HTTP Method</strong><br>Set this to POST, as Twilio’s messaging API requires a POST request.</li><li><strong>🔐 HTTP Headers</strong><br>Twilio requires a Basic Authorization header. Encode your credentials as shown earlier.<br> <br>Format:</li></ul><pre>Authorization: Basic &lt;base64_encoded(Account_SID:Auth_Token)&gt;</pre><ul><li><strong>📦 HTTP Payload</strong><br>Define the request body parameters to pass dynamic values using WSO2’s context variables:</li></ul><pre>Body=$ctx.msg&amp;To=$ctx.num&amp;From=&lt;url_encoded_from_number&gt;</pre><ul><li>Example:</li></ul><pre>Body=$ctx.msg&amp;To=$ctx.num&amp;From=%2B19284152319</pre><blockquote>Note: The phone number in the From field must be URL-encoded (e.g., +19284152319 becomes %2B19284152319).</blockquote><h4>Step 05: Save the Identity Provider</h4><p>Once all the fields are filled out correctly, click Save to complete the integration.</p><h4>🧩 Step 06: Add Mobile Number Claim for the Service Provider</h4><p>Depending on your specific use case, configuring the <strong>mobile number claim</strong> might be essential — especially if you’re implementing SMS OTP authentication.</p><p>In my scenario, I’ve configured <strong>WSO2 Identity Server (IS)</strong> to act as a <strong>Single Sign-On (SSO) provider</strong> for <strong>WSO2 API Manager (APIM)</strong>. To support SMS-based OTP authentication, I needed to make the mobile number (http://wso2.org/claims/mobile) a <strong>mandatory claim</strong> for the associated <strong>Service Provider (SP)</strong> configuration.</p><blockquote><em>💡 </em><strong><em>Note:</em></strong><em> The claim configuration process may vary based on your integration or SP setup. Below, I’m outlining how I configured it specifically for WSO2 APIM SSO integration</em></blockquote><h4>🔧 Configuring the Mobile Claim</h4><ul><li>Navigate to the <strong>Service Providers</strong> section in the WSO2 IS Carbon Console.</li><li>Edit the Service Provider (in my case, the one associated with APIM).</li><li>Go to <strong>Claim Configuration</strong> and set the mobile number claim as <strong>mandatory</strong>.</li></ul><p><em>(Refer to the screenshot below for how this looks in the UI.)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*23x8rxCSZRqxjopw_t9h4A.png" /></figure><h4>⚙️ Advanced Authentication Setup</h4><p>Next, I configured the <strong>Local &amp; Outbound Authentication Configuration</strong> to support the SMS OTP flow.</p><ul><li>Go to the <strong>Local &amp; Outbound Authentication Configuration</strong> section of the SP.</li><li>Choose <strong>Advanced Configuration</strong>.</li><li>Add <strong>smsOTP</strong> as an authentication step, either on its own or in combination with other authenticators (e.g., basic authentication).</li></ul><p>Here’s how my configuration looks in the WSO2 IS interface:</p><p><em>(Include screenshots showing how </em><em>smsOTP is added as an authentication step.)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gB7rE2rrIJc3UsHfDc8oEw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DhyF4D6NkbKgJSVn1EL3dw.png" /></figure><h3>🎉 Done! SMS OTP is Now Enabled</h3><p>Once these steps are complete, your login flow will include SMS OTP as an authentication option. Users will receive an OTP via SMS and use it to complete their login process.</p><p>Once these steps are complete, your login flow will include SMS OTP as an authentication option. Users will receive an OTP via SMS and use it to complete their login process.</p><h3>References:</h3><p>[1] — <a href="https://www.twilio.com/docs/usage/requests-to-twilio#creating-or-updating-resources-with-the-post-method">https://www.twilio.com/docs/usage/requests-to-twilio#creating-or-updating-resources-with-the-post-method</a><br>[2] — <a href="https://is.docs.wso2.com/en/6.1.0/guides/mfa/2fa-sms-otp/">https://is.docs.wso2.com/en/6.1.0/guides/mfa/2fa-sms-otp/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7f14803c084" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Custom XPATH functions in WSO2 MI]]></title>
            <link>https://medium.com/@shavinsenadeera/implementing-custom-xpath-functions-in-wso2-mi-1ab3228ab521?source=rss-2c81d5b33129------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ab3228ab521</guid>
            <dc:creator><![CDATA[Shavindu Senadheera]]></dc:creator>
            <pubDate>Sun, 15 Dec 2024 05:35:30 GMT</pubDate>
            <atom:updated>2025-01-26T14:54:59.753Z</atom:updated>
            <content:encoded><![CDATA[<p>In WSO2 MI, it supports the <a href="https://developer.mozilla.org/en-US/docs/Web/XPath/Functions">standard XPath functions</a> and its variables through the underlying XPath engine. These functions allow developers to access message properties, headers, and other runtime data for complex mediation logic.</p><p>Examples of built-in functions include:</p><ul><li>concat(): Concatenates strings.</li><li>substring(): Extracts substrings from a string.</li><li>boolean(): Evaluates expressions to return a boolean value.</li></ul><p>Please refer to the more examples on <a href="https://ei.docs.wso2.com/en/latest/micro-integrator/references/mediators/property-reference/accessing-properties-with-xpath/#!">official WSO2 MI documentation</a>.</p><p>While WSO2 MI provides a wide range of built-in XPath functions, there are scenarios where you may need custom logic that’s unavailable in the default functions. For such use cases, WSO2 MI allows you to implement custom XPath functions.</p><p>When the built-in functions are insufficient, custom XPath functions come into play.</p><h3><strong>Use Case</strong></h3><p>For this demonstration, we will create a custom XPath function named toCamelCase() that transforms a given text into CamelCase format.</p><h4>Steps to Implement a Custom XPath Function in WSO2 MI 4.3.0</h4><h4>Step 1: Create a Maven Project</h4><p>To get started, create a Maven project for your custom XPath function. Use the following Maven coordinates:</p><pre>&lt;groupId&gt;&lt;group_id&gt;&lt;/groupId&gt;<br>&lt;artifactId&gt;&lt;artifact_id&gt;&lt;/artifactId&gt;<br>&lt;version&gt;&lt;version&gt;&lt;/version&gt;<br>&lt;packaging&gt;bundle&lt;/packaging&gt;</pre><p>The &lt;packaging&gt;bundle&lt;/packaging&gt; tag ensures that the Maven project is packaged as an OSGi bundle. This is necessary because WSO2 MI operates in an OSGi-based runtime environment, and all deployable artifacts must comply with this framework.</p><p>Ensure you include the following dependency for Synapse:</p><pre>&lt;dependency&gt;<br> &lt;groupId&gt;org.apache.synapse&lt;/groupId&gt;<br> &lt;artifactId&gt;synapse-core&lt;/artifactId&gt;<br> &lt;version&gt;4.0.0-wso2v119&lt;/version&gt;<br>&lt;/dependency&gt;</pre><h4>Step 2: Implement the Custom XPath Function</h4><p>Create a Java class that implements the org.jaxen.Function interface. Below is a sample implementation for toCamelCase():</p><pre>package org.example;<br><br>import org.apache.commons.logging.Log;<br>import org.apache.commons.logging.LogFactory;<br>import org.apache.synapse.MessageContext;<br>import org.jaxen.Context;<br>import org.jaxen.Function;<br>import org.jaxen.FunctionCallException;<br>import org.jaxen.function.StringFunction;<br><br>import java.util.List;<br><br>public class CamelCaseFunction implements Function {<br>    private static final Log log = LogFactory.getLog(CamelCaseFunction.class);<br>    private final MessageContext synCtx;<br><br>    public CamelCaseFunction(MessageContext synCtx) {<br>        this.synCtx = synCtx;<br>    }<br><br>    @Override<br>    public Object call(Context context, List args) throws FunctionCallException {<br>        if (args == null || args.isEmpty()) {<br>            log.error(&quot;No input provided for the Camel Case function.&quot;);<br>            throw new FunctionCallException(&quot;Camel Case function requires a single string argument.&quot;);<br>        }<br><br>        // Get the input string<br>        String input = StringFunction.evaluate(args.get(0), context.getNavigator());<br><br>        if (input == null || input.trim().isEmpty()) {<br>            return &quot;&quot;; // Return empty string for null or empty input<br>        }<br><br>        // Convert input to Camel Case<br>        String camelCaseOutput = toCamelCase(input);<br><br>        log.info(&quot;Input: &quot; + input + &quot; | Camel Case Output: &quot; + camelCaseOutput);<br>        return camelCaseOutput;<br>    }<br><br>    private String toCamelCase(String input) {<br>        String[] words = input.split(&quot;\\s+&quot;);<br>        StringBuilder camelCaseBuilder = new StringBuilder();<br><br>        for (int i = 0; i &lt; words.length; i++) {<br>            String word = words[i];<br>            if (word.isEmpty()) continue;<br><br>            if (i == 0) {<br>                // Lowercase the first word<br>                camelCaseBuilder.append(word.toLowerCase());<br>            } else {<br>                // Capitalize the first letter and lowercase the rest<br>                camelCaseBuilder.append(word.substring(0, 1).toUpperCase())<br>                        .append(word.substring(1).toLowerCase());<br>            }<br>        }<br><br>        return camelCaseBuilder.toString();<br>    }<br>}</pre><h4>Step 3: Create the Function Provider</h4><p>In addition to the function class, implement a provider class to register your custom function. Below is a sample implementation:</p><pre>package org.example;<br><br>import org.apache.commons.logging.Log;<br>import org.apache.commons.logging.LogFactory;<br>import org.apache.synapse.MessageContext;<br>import org.apache.synapse.util.xpath.ext.SynapseXpathFunctionContextProvider;<br>import org.jaxen.Function;<br><br>public class CamelCaseFunctionProvider implements SynapseXpathFunctionContextProvider {<br><br>    private Log log = LogFactory.getLog(UppercaseXPathFunctionProvider.class);<br>    private static final String NAME_SPACE_PREFIX = &quot;wso2&quot;;<br>    private static final String CACHE_LOOKUP = &quot;to-camelcase&quot;;<br><br>    public Function getInitializedExtFunction(MessageContext messageContext) {<br>        return new CamelCaseFunction(messageContext);<br>    }<br><br>    public String getResolvingQName() {<br>        return NAME_SPACE_PREFIX + CACHE_LOOKUP;<br>    }<br>}</pre><h4>Step 4: Configure OSGi Bundling</h4><p>Update the pom.xml file to include the Maven Bundle Plugin for OSGi packaging:</p><pre><br>&lt;plugin&gt;<br> &lt;groupId&gt;org.apache.felix&lt;/groupId&gt;<br> &lt;artifactId&gt;maven-bundle-plugin&lt;/artifactId&gt;<br> &lt;extensions&gt;true&lt;/extensions&gt;<br> &lt;version&gt;5.1.9&lt;/version&gt;<br> &lt;configuration&gt;<br> &lt;instructions&gt;<br> &lt;Bundle-SymbolicName&gt;${project.artifactId}&lt;/Bundle-SymbolicName&gt;<br> &lt;Bundle-Name&gt;${project.artifactId}&lt;/Bundle-Name&gt;<br> &lt;Export-Package&gt;<br> org.example.*<br> &lt;/Export-Package&gt;<br> &lt;Import-Package&gt;<br> org.apache.synapse.*<br> &lt;/Import-Package&gt;<br> &lt;DynamicImport-Package&gt;*&lt;/DynamicImport-Package&gt;<br> &lt;/instructions&gt;<br> &lt;/configuration&gt;<br>&lt;/plugin&gt;</pre><p>Build the project using the following command:</p><pre>mvn clean install</pre><p>This will generate a .jar file in the target/ directory in your maven project.</p><h4>Step 5: Deploy the Custom XPath Function</h4><ol><li>Copy the generated .jar file to the lib directory of your WSO2 MI instance:</li></ol><pre>cp target/ToCamelCase-1.0-SNAPSHOT.jar /path/to/wso2mi-4.3.0/lib/</pre><p>2. Add the following property synpase_properties to the deployment.toml file and append the specific custom XPath Function Provider synpase_propertiesorg.example.CamelCaseFunctionProvider along with the default synapse XPath functions:</p><pre>[synapse_properties]<br>&#39;synapse.xpath.func.extensions&#39;=&quot;org.wso2.micro.integrator.mediation.security.vault.xpath.SecureVaultLookupXPathFunctionProvider,org.wso2.micro.integrator.mediation.security.vault.external.hashicorp.HashiCorpVaultLookupXPathFunctionProvider,org.example.CamelCaseFunctionProvider&quot;</pre><p>3. Restart the WSO2 MI server:</p><pre>./wso2mi-4.3.0/bin/micro-integrator.sh</pre><h4>Step 6: Use the Custom XPath Function in a Mediation Flow</h4><p>You can now use the toCamelCase() function in your Synapse configurations. Below is an example of how to invoke the function in an API:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;api context=&quot;/test&quot; name=&quot;EchoAPI&quot; xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;<br>    &lt;resource methods=&quot;GET&quot; uri-template=&quot;/camelcase&quot;&gt;<br>        &lt;inSequence&gt;<br>   &lt;log level=&quot;custom&quot;&gt;<br>    &lt;property name=&quot;TO_CamelCase&quot; expression=&quot;wso2:to-camelcase(&#39;hello world&#39;)&quot; /&gt;<br>   &lt;/log&gt;<br>   &lt;respond/&gt;<br>        &lt;/inSequence&gt;<br>        &lt;faultSequence&gt;<br>        &lt;/faultSequence&gt;<br>    &lt;/resource&gt;<br>&lt;/api&gt;</pre><h4>Step 6: Test the Function</h4><p>1. Deploy the API in the WSO2 MI (&lt;MI_HOME&gt;/repository/deployment/synpase-configs/defult/apis)<br>2. Call the API using a REST client:</p><pre><br>curl -X GET ‘https://localhost:8253/test/camelcase’</pre><p>3. Verify the logs to confirm that the text was successfully transformed into CamelCase.</p><pre><br>[2024–12–15 09:57:37,039] INFO {CamelCaseFunction} — Input: hello world | Camel Case Output: helloWorld<br>[2024–12–15 09:57:37,039] INFO {LogMediator} — {api:EchoAPI} TO_CamelCase = helloWorld</pre><h3>Conclusion</h3><p>With this approach, you can extend the functionality of WSO2 Micro Integrator to meet custom requirements using XPath functions. Whether you need advanced text manipulation, data transformation, or any other logic, custom XPath functions provide a powerful way to tailor your integration solutions.</p><p>Start implementing your own custom XPath functions today and unlock the full potential of WSO2 MI!</p><h3>References</h3><p><a href="https://mi.docs.wso2.com/en/latest/reference/synapse-properties/expressions/#xpath-expressions">https://mi.docs.wso2.com/en/latest/reference/synapse-properties/expressions/#xpath-expressions</a></p><p><a href="https://ei.docs.wso2.com/en/latest/micro-integrator/references/mediators/property-reference/accessing-properties-with-xpath/#!">https://ei.docs.wso2.com/en/latest/micro-integrator/references/mediators/property-reference/accessing-properties-with-xpath/#!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ab3228ab521" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring Azure AD Single Sign-On (SSO) for WSO2 Micro Integrator (MI) Dashboard]]></title>
            <link>https://medium.com/@shavinsenadeera/configuring-azure-ad-single-sign-on-sso-for-wso2-micro-integrator-mi-dashboard-7eb0ae057fbf?source=rss-2c81d5b33129------2</link>
            <guid isPermaLink="false">https://medium.com/p/7eb0ae057fbf</guid>
            <dc:creator><![CDATA[Shavindu Senadheera]]></dc:creator>
            <pubDate>Fri, 28 Jul 2023 17:38:10 GMT</pubDate>
            <atom:updated>2023-08-27T17:08:59.386Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*vFzcYLhLBF5-gwkVqiEN2Q.png" /></figure><h3>Introduction</h3><p>Single Sign-On (SSO) emerges as a crucial solution, streamlining user authentication and bolstering data security. By enabling users to access multiple applications with just one set of login credentials, SSO not only enhances user experience but also simplifies administrative processes for organizations.</p><p>In this comprehensive guide, we will walk you through the step-by-step process of configuring Azure AD Single Sign-On (SSO) for the WSO2 Micro Integrator (MI) Dashboard 4.1.0.</p><p>By following these instructions, you can seamlessly integrate SSO with the MI Dashboard, empowering your users with convenient and secure access while maintaining robust control over resources and data. Join us as we explore the integration of these powerful technologies to elevate your organization’s user experience and bolster its cybersecurity framework.</p><h3>Steps</h3><h4>Azure AD Configurations</h4><p><strong>Explanation</strong></p><p>When we created the Application, we selected the Single-page Application (SPA) as the platform for this application.</p><p>As an explanation for the SPA,</p><ul><li>SPAs are web applications that run entirely in the user’s browser, typically built using JavaScript frameworks like Angular, React, or Vue.js.</li><li>These applications interact with backend APIs and authenticate users using the OAuth 2.0 Implicit Grant Flow or the newer OAuth 2.0 Authorization Code Flow with PKCE (Proof Key for Code Exchange).</li></ul><p>Because of that, we need to select the SPA option when we create the application as a platform.</p><h3>Steps:</h3><ol><li>Go to the “<a href="https://portal.azure.com/">https://portal.azure.com/</a>”.</li><li>Browse to the Azure AD (Active Directory).</li><li>Go to the “App registrations” section.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qBqb-x8Vbc9RBgor" /></figure><p>4. Click “New registration” and fill in the fields below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k0-scPbHxRa3HRim" /></figure><p>5. Go to the “Expose an API” section and click on “Add a scope”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yFFeJEpEHfkrvsHn" /></figure><p>6. Click on “Save and Continue”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fU0Rp80cc47fc1yq" /></figure><p>7. Fill in the fields below and click on “Add scope”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SAO4nnSjVUYZuTvS" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/0*YWHZVpaThI0dMLEP" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KqEhSW5mo95hd-U4" /></figure><p><strong><em>We need this scope (api://&lt;client_id&gt;/access_as_user) to configure the scope property on &lt;MI_DASHBOARD_HOME&gt;/conf/deployment.toml.</em></strong></p><p>8. Go to the “API Permission” section and click on “Add a permission”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8gyoxqEyKD5Ps72l" /></figure><p>9. Select “My APIs”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*336-YBjZMwNoyumo" /></figure><p>10. Click on your application name which you created just before (In my case it is “My_Application”).</p><p>11. Select “Delegated permissions”.</p><p>12. Select the “access_as_user” in the Permission section.</p><p>13. Click on the “Add permission”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/0*5UEQtWW8gR6ZA7Eg" /><figcaption>Add newly created permission to the application</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B9uERX2YruIG7ZVz" /><figcaption>API permissions view</figcaption></figure><p>14. Click on “Grant admin consent for Default Directory” and click on “Yes” on the popup as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*04Ch0Wti4h6eRJum" /><figcaption>Grant admin consent for Default Directory</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gxp-tiML-JQkW9N7" /><figcaption>API permissions view after granting admin consent for Default Directory</figcaption></figure><p>15. Go to the “Certificates &amp; secrets” section and click on “New client secret”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hcnKwOBuzoFLXoCI" /><figcaption>Create new client secret</figcaption></figure><p>16. Add a client secret. Following is the sample screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/0*goAeJ6C9dPneO7lY" /><figcaption>Add client secret</figcaption></figure><p>17. Go to the “Manifest” section and find the “accessTokenAcceptedVersion”.</p><p>18. Change the “accessTokenAcceptedVersion” value to 2.</p><p><strong>This indicates that we will use tokens from the v2.0 endpoint.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dYcWpn6LwAbQBXXv" /><figcaption>Changing value of accessTokenAcceptedVersion to “2” in the Manifest</figcaption></figure><h4>Micro Integrator Dashboard Configurations</h4><p><strong>Explanation</strong></p><p>On the MI Dashboard side, we need to change the value of the property “sendCookiesInRequests” to “false”.</p><p><em>When sendCookiesInRequests is </em><strong><em>false</em></strong><em>:</em></p><p>The “Credentials” property of the fetch request is set to “same-origin” instead of “include”. By setting it to “same-origin”, the client application (MI Dashboard) will send the origin header in the request.</p><p>When the origin header is included in the request, Microsoft Azure responds with the “Access-Control-Allow-Origin” header, allowing access for all domains (*).</p><p>We need to change this property from the config.js.j2 file on MI-4.1.0.</p><p><strong>Steps</strong></p><p>Make the following change in the “&lt;MI_DASHBOARD_HOME&gt;/conf/config-parser/templates/server/www/conf/config.js.j2”.</p><p>Added the following property.</p><pre>sendCookiesInRequests: false</pre><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*q7wPysmYbjEo8NED" /><figcaption>Applying the property “sendCookiesInRequests”</figcaption></figure><p>Adding the SSO configuration as follows.</p><pre>[sso]<br>enable = true<br>client_id = “&lt;client_id&gt;”<br>jwt_issuer = “https://login.microsoftonline.com/&lt;tenant_id&gt;/v2.0&quot;<br>resource_server_URLs = [“https://midashboard.test.com:9743&quot;]<br>sign_in_redirect_URL = “https://midashboard.test.com:9743/sso&quot;<br>well_known_endpoint = “https://login.microsoftonline.com/&lt;tenant_id&gt;/v2.0/.well-known/openid-configuration&quot;<br>scope = [“api://&lt;client_id&gt;/access_as_user”]</pre><h3>Conclusion</h3><p>Configuring Azure AD Single Sign-On (SSO) for the WSO2 Micro Integrator (MI) Dashboard is a significant step toward improving user experience and enhancing security in accessing multiple applications with a single set of login credentials. By following the step-by-step guide provided in this article, organizations can seamlessly integrate SSO with the MI Dashboard, enabling users to authenticate easily and securely. The process involves setting up the necessary Azure AD configurations, creating and granting permissions, and adjusting configurations on both the Azure AD side and the MI Dashboard side. With SSO in place, users can enjoy a smoother authentication process while maintaining robust control over access to resources and data. This integration facilitates a more efficient and user-friendly experience for organizations leveraging WSO2 MI Dashboard, ensuring enhanced productivity and strengthened security measures.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7eb0ae057fbf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Begin with Apache Kafka and CMAK]]></title>
            <link>https://medium.com/@shavinsenadeera/begin-with-apache-kafka-and-cmak-ba9a4399431c?source=rss-2c81d5b33129------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba9a4399431c</guid>
            <dc:creator><![CDATA[Shavindu Senadheera]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 16:41:16 GMT</pubDate>
            <atom:updated>2023-04-26T16:42:16.211Z</atom:updated>
            <content:encoded><![CDATA[<p><em>How to Configure a Kafka Broker with CMAK: A Step-by-Step Guide</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zrWT1xlMrHbdtnCfNjZ-qA.png" /></figure><h3>Introduction</h3><p>Welcome to this chapter where we will delve into the fundamental configuration of the Apache Kafka Cluster, Apache ZooKeeper with Yahoo CMAK. For this guide, we will be using an Ubuntu Server on WSL2.</p><p>As an open-source distributed event streaming platform, Kafka is widely used for real-time data processing. A Kafka cluster consists of one or more Kafka brokers and a ZooKeeper server to manage and coordinate the brokers. This article will focus on configuring and launching a Kafka cluster on a server using Yahoo CMAK (formerly known as Kafka Manager).</p><h3>Prerequesties</h3><p>Before we begin, make sure to have Java on your server.</p><p><strong>-&gt; Install the Java Runtime Environment (JRE)</strong></p><p>To check if Java is already installed, run the following command:</p><pre>java -version</pre><p>If Java is not installed, you’ll get an error message. Install the JRE from OpenJDK 11 by running the following command:</p><pre>sudo apt install default-jre</pre><p>Verify the installation by running the following command:</p><pre>java -version</pre><p>This command should return the version of Java installed on your server.</p><p><strong>-&gt; Install the Java Development Kit (JDK)</strong></p><p>You may need the JDK in addition to the JRE in order to compile and run some specific Java-based software. To install the JDK, execute the following command, which will also install the JRE:</p><pre>sudo apt install default-jdk</pre><p>Verify the installation by checking the version of javac, the Java compiler, using the following command:</p><pre>javac -version</pre><p>This command should return the version of the JDK installed on your server.</p><p>Now you are ready to go.</p><h3><strong>Start to configure a Apache Kafka Brokeer</strong></h3><p>First we need to download the Apache Kafka on our Linux Server.</p><ol><li>Go to the Official Apache Kafka download site [<a href="https://kafka.apache.org/downloads">1</a>].</li><li>Copy the link of the download link by right-clicking on it.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jVIjwyF1-WFcMT0WqqSHEA.png" /></figure><p>3. For download that into our Linux Server, we can use <strong><em>wget </em></strong>command.</p><pre>wget https://downloads.apache.org/kafka/3.4.0/kafka-3.4.0-src.tgz</pre><p>4. Unzip it</p><pre>tar -xvzf kafka-3.4.0-src.tgz</pre><p>5. Configuring the Kafka Cluster The first step is to configure the server.properties file, which contains the Kafka broker configurations. In this file, we need to change the server IP address to allow external clients to connect to the Kafka brokers.</p><p>To change the server IP address, open the server.properties file which is the directory “&lt;KAFKA_HOME&gt;/config/” and add the following line:</p><pre>advertised.listeners=PLAINTEXT://[server-ip-address]:9092</pre><p>Replace the [server-ip-address] with the IP address of your server. In my case I used “localhost”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mP16FdeGVKRyTm3BvOebwg.png" /></figure><p>5. Starting the Kafka Cluster After configuring the server.properties file, we can start the Kafka cluster. To start the Kafka server, run the following command on &lt;KAFKA_HOME&gt; path:</p><pre>JMX_PORT=8004 bin/kafka-server-start.sh config/server.properties</pre><p>This command starts the Kafka server and listens on port 9092 for incoming client connections. The JMX_PORT environment variable specifies the port used for JMX monitoring.</p><h3><strong>Start to configure a Apache ZooKeeper Apach</strong></h3><p>Apache ZooKeeper is a centralized service used to manage and coordinate distributed systems. Kafka uses ZooKeeper to manage its brokers and to maintain cluster metadata.</p><p>To configure ZooKeeper, open the zookeeper.properties file in the directory called &lt;KAFKA_HOME&gt;/config/ and make any necessary changes. The default configuration is suitable for most use cases.</p><p>To start ZooKeeper, run the following command on &lt;KAFKA_HOME&gt; path:</p><pre>bin/zookeeper-server-start.sh config/zookeeper.properties</pre><p>This command starts the ZooKeeper server and listens on port 2181 for incoming client connections.</p><h3><strong>Start to configure a CMAK (Kafka Manager)</strong></h3><p>CMAK (formerly known as Kafka Manager) is an open-source web-based tool for managing Apache Kafka clusters. It provides a user-friendly interface for monitoring and managing Kafka brokers, topics, partitions, and consumers.</p><p>To configure CMAK, follow the instructions in the official documentation at [<a href="https://github.com/yahoo/CMAK">2</a>].</p><ol><li>Go to this git repositoy [<a href="https://github.com/yahoo/CMAK">2</a>] and clone it by following git clone command.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LJRzPL5mCnjVXqmbOaAfqQ.png" /></figure><pre>git clone https://github.com/yahoo/CMAK.git</pre><p>2. Then go inside the cloned CMAK folder and run the following command to build and packagethe CMAK source code into a distributable format.<br>At the end of the process, you can see INFO log with such as “Your package is ready in &lt;CMAK_HOME&gt;/target/universal/cmak-version.zip”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EjNP2La0uviCYwMO1lKJvA.png" /></figure><p>3. Go inside the &lt;CMAK_HOME&gt;/target/universal/ and unzip the cmak-3.0.0.7.zip file.</p><p>4. Open the application.conf file inside the &lt;CMAK_HOME&gt;/target/universal/cmak-3.0.0.7/conf/ directory.</p><p>5. Change the cmak.zkhosts=”kafka-manager-zookeeper:2181&quot; to cmak.zkhosts=”&lt;zookeeper_server_ip_address&gt;:2181&quot;.</p><p>In my case, ZooKeeper is running on the localhost with default port 2181, so my configurations looks like as follows.</p><pre>cmak.zkhosts=”localhost:2181&quot;</pre><p>6. Following the above configuration changes, we can successfully establish a connection between our Kafka Manager and Apache ZooKeeper instance by executing the command provided below.</p><p>It is important to note that while the CMAK (Kafka Manager) is run on port 8081 in this example, you have the flexibility to use any custom port to run the CMAK server, depending on your specific requirements.</p><pre>bin/cmak -Dconfig.file=conf/application.conf -Dhttp.port=8081</pre><p>With the use of the Yahoo CMAK (formerly known as Kafka Manager), we can easily configure our Kafka clusters, topics, etc without having to worry about the .sh files. This user-friendly interface allows us to make any necessary configurations for our clusters with ease, providing a more streamlined approach to managing our Kafka infrastructure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RdLT6Q3Q8P6wU6apuPfwkA.png" /></figure><p>— — — — — — — — — — 👏🙌🎉Cheers!🎉🙌👏 — — — — — — — — — — —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VjZDQdRMfr_PfEOj" /><figcaption>Photo by <a href="https://unsplash.com/@wilstewart3?utm_source=medium&amp;utm_medium=referral">Wil Stewart</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>— — — — — — — — — —👏🙌🎉Cheers!🎉🙌👏 — — — — — — — — — — —</p><h3>References</h3><p>[1] — <a href="https://kafka.apache.org/downloads">https://kafka.apache.org/downloads</a><br>[2] — <a href="https://github.com/yahoo/CMAK">https://github.com/yahoo/CMAK</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba9a4399431c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Siddhi App on WSO2 API Manager 2.6.0]]></title>
            <link>https://medium.com/@shavinsenadeera/create-siddhi-app-in-wso2-api-manager-2-6-0-fdf2f47f9213?source=rss-2c81d5b33129------2</link>
            <guid isPermaLink="false">https://medium.com/p/fdf2f47f9213</guid>
            <dc:creator><![CDATA[Shavindu Senadheera]]></dc:creator>
            <pubDate>Wed, 12 Apr 2023 17:07:24 GMT</pubDate>
            <atom:updated>2023-04-12T17:08:06.083Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YMObC-kVywS8nCrS90oHGg.png" /></figure><h3>Introduction</h3><p>In this blog post, we will walk you through the steps to create a Siddhi App in WSO2 API Manager 2.6.0. A Siddhi App is a collection of Siddhi queries that process streaming data. In this tutorial, we will create a Simple Siddhi Application that will process API request data and store the response code and response time in a MySQL database.</p><h3>What is Siddhi queries?</h3><p>Siddhi queries are the backbone of real-time streaming analytics with WSO2 API Manager. They allow you to define how to process incoming data streams in a flexible and powerful way. With Siddhi, you can create complex queries that filter, aggregate, join, and transform data in real-time. These queries can be combined into a full-fledged Siddhi application that provides valuable insights into your API traffic, allowing you to optimize your APIs and deliver better services to your users. Whether you’re a developer, a data scientist, or a business analyst, Siddhi queries empower you to make informed decisions based on real-time data. With their intuitive syntax and rich set of features, Siddhi queries are a must-have tool for any modern API management solution.<br>You can learn more about the Siddhi query by following this offical documentation <a href="https://siddhi.io/">[1]</a>.</p><h3><strong>Lets start our simple project</strong></h3><p>🔅 <strong>Step 1: Define the Siddhi App</strong></p><p>We will first define the Siddhi app as “APIM_HttpAccessSummaryApp”. In this Siddhi app, we will define the source with the topic “APIM_REQUEST” to get the API request stream. We will then define the table “HttpAccessSummaryTable” to store the response code and response time of each API request. Finally, we will extract the responseCode and responseTime from the “Request” streams and store them in the “HttpAccessSummaryTable” table.</p><p>Here is the Siddhi App code:</p><pre>@App:name(&quot;APIM_HttpAccessSummaryApp&quot;)<br><br>@source(type=&#39;inMemory&#39; , topic=&#39;APIM_REQUEST&#39;)<br>define stream Request (meta_clientType string, applicationConsumerKey string, applicationName string, applicationId string, applicationOwner string, apiContext string,apiName string, apiVersion string, apiResourcePath string, apiResourceTemplate string, apiMethod string, apiCreator string, apiCreatorTenantDomain string, apiTier string, apiHostname string, username string, userTenantDomain string, userIp string, userAgent string, requestTimestamp long, throttledOut bool, responseTime long, serviceTime long, backendTime long, responseCacheHit bool, responseSize long, protocol string, responseCode int, destination string, securityLatency long, throttlingLatency long, requestMedLat long, responseMedLat long, backendLatency long, otherLatency long, gatewayType string, label string);<br><br>@store(type=&quot;rdbms&quot;,<br>       jdbc.url=&quot;jdbc:mysql://localhost:3306/dashboarddb?useSSL=false&quot;,<br>       username=&quot;shavindu&quot;, password=&quot;shavindu&quot;,<br>       jdbc.driver.name=&quot;com.mysql.cj.jdbc.Driver&quot;)<br>define table HttpAccessSummaryTable (responseCode int, responseTime long);<br><br>from Request<br>select responseCode, responseTime<br>insert into HttpAccessSummaryTable;</pre><p>As I explained the above code line by line:</p><ol><li>@App:name(&quot;APIM_HttpAccessSummaryApp&quot;): This is an annotation that gives a name to the Siddhi application. In this case, it is named &quot;APIM_HttpAccessSummaryApp&quot;.</li><li>@source(type=&#39;inMemory&#39; , topic=&#39;APIM_REQUEST&#39;): This is an annotation that defines the source of the data for the Siddhi application. It specifies that the source is an in-memory data store and the data is being sourced from the &quot;APIM_REQUEST&quot; topic.</li><li>define stream Request (meta_clientType string, applicationConsumerKey string, applicationName string, applicationId string, applicationOwner string, apiContext string,apiName string, apiVersion string, apiResourcePath string, apiResourceTemplate string, apiMethod string, apiCreator string, apiCreatorTenantDomain string, apiTier string, apiHostname string, username string, userTenantDomain string, userIp string, userAgent string, requestTimestamp long, throttledOut bool, responseTime long, serviceTime long, backendTime long, responseCacheHit bool, responseSize long, protocol string, responseCode int, destination string, securityLatency long, throttlingLatency long, requestMedLat long, responseMedLat long, backendLatency long, otherLatency long, gatewayType string, label string): This line defines a stream called &quot;Request&quot; with a number of attributes, such as &quot;meta_clientType&quot; and &quot;responseCode&quot;, and their corresponding data types.</li><li>@store(type=&quot;rdbms&quot;, jdbc.url=&quot;jdbc:mysql://localhost:3306/dashboarddb?useSSL=false&quot;, username=&quot;shavindu&quot;, password=&quot;shavindu&quot;, jdbc.driver.name=&quot;com.mysql.cj.jdbc.Driver&quot;): This is an annotation that defines the destination or store of the data for the Siddhi application. In this case, it is a relational database management system (RDBMS) that is being used, with the specific details of the database connection provided, such as the URL, username, and password.</li><li>define table HttpAccessSummaryTable (responseCode int, responseTime long): This line defines a table called &quot;HttpAccessSummaryTable&quot; with two columns, &quot;responseCode&quot; and &quot;responseTime&quot;, and their corresponding data types.</li><li>from Request select responseCode, responseTime insert into HttpAccessSummaryTable;: This line of code is a Siddhi query that selects the &quot;responseCode&quot; and &quot;responseTime&quot; columns from the &quot;Request&quot; stream and inserts them into the &quot;HttpAccessSummaryTable&quot; table.</li></ol><p>Overall, this code defines a Siddhi application that sources data from an in-memory data store, defines a stream with attributes and data types, defines a destination as a relational database, defines a table with columns and data types, and inserts specific data from the stream into the table.</p><p>🔅 <strong>Step 2: Deploy the Siddhi App on APIM Analytics</strong></p><p>Now, we will deploy the Siddhi App on APIM Analytics. Follow the steps below:</p><ol><li>Create the database “dashboarddb” on MySQL.</li><li>Define the database source as follows. (Please Note: In this step, it is necessary to restart the server.)</li><li>Go to the &lt;APIM_ANALYTICS_HOME&gt;/conf/worker/deployment.yaml.</li><li>Define the datasource under the datasources. Please refer to the sample below.</li></ol><p>Here is the deployment.yaml looks like:</p><pre># Datasource Configurations<br>wso2.datasources:<br>  dataSources:<br><br>  ...<br><br>    - name: DASHBOARDDB<br>      description: &quot;The datasource for sample Siddhi App.&quot;<br>      jndiConfig:<br>        name: jdbc/DASHBOARDDB<br>      definition:<br>        type: RDBMS<br>        configuration:<br>          jdbcUrl: jdbc:mysql://localhost:3306/dashboarddb?useSSL=false<br>          username: shavindu<br>          password: shavindu<br>          driverClassName: com.mysql.cj.jdbc.Driver<br>          maxPoolSize: 50<br>          idleTimeout: 60000<br>          connectionTestQuery: SELECT 1<br>          validationTimeout: 30000<br>          isAutoCommit: false</pre><p>3. Please locate any dependencies into the &lt;APIM_ANALYTICS_HOME&gt;/lib folder. In my case, I need to put MySQL driver into this lib folder.<br>(Please Note: In this step, it is necessary to restart the server.)</p><p>4. After creating the Siddhi App make sure to put that into the &lt;APIM_ANALYTICS_HOME&gt;/wso2/worker/deployment/siddhi-files/.<br><em>(Please Note: In this step, it is </em><strong><em>not</em></strong><em> necessary to restart the server.)</em></p><h3>Let’s raise a glass and celebrate! 🍾</h3><p>We’ve completed the configuration and deployment stages, now let’s shift our focus to the exciting testing and observation phase.</p><h3>🔅 <strong>Observations</strong></h3><p>And after the deployment of the Siddhi app, we invoked an API multiple times and observed the following results in the table “HttpAccessSummaryTable”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/0*4oWbYes3IA7Un7a2" /></figure><p>Congratulations! 🥳 👏 🙌</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T4WaTKceb4mn2qwy" /><figcaption>Photo by <a href="https://unsplash.com/@priscilladupreez?utm_source=medium&amp;utm_medium=referral">Priscilla Du Preez</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>References</strong></h3><p>[1] — <a href="https://siddhi.io/">https://siddhi.io/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fdf2f47f9213" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handle a Cookie Path in WSO2 API Manager (APIM)]]></title>
            <link>https://medium.com/@shavinsenadeera/handle-cookie-path-in-wso2-api-manager-apim-a9caaf3b9162?source=rss-2c81d5b33129------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9caaf3b9162</guid>
            <dc:creator><![CDATA[Shavindu Senadheera]]></dc:creator>
            <pubDate>Thu, 25 Aug 2022 05:29:04 GMT</pubDate>
            <atom:updated>2022-08-25T05:33:56.606Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5bgYsBW-x56crsiXf4yfKQ.png" /></figure><p>In this Medium article, I am talking and demonstrating about how to get and handle/manipulate the cookie path in the response flow by using a custom mediation sequence in <a href="https://apim.docs.wso2.com/en/3.2.0/">WSO2 API Manager 3.2.0</a>.</p><p>As for the demonstration purpose I just use desginer.mocky.io [1] to create a sample backend service and use Postman as an HTTP Client for the setup.</p><p><strong><em>Haven’t you heard before “Mocky”? </em>👀</strong></p><p><a href="https://designer.mocky.io/">designer.mocky.io</a> 👆</p><p>We don’t need to wait for the backend to be ready. By using <a href="https://designer.mocky.io/">Mocky</a>, we can generate custom API responses and start working on them right away.</p><p>Okay, let’s get started..✌️</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FQJvwBSGaoc4eI%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fbugs-bunny-running-exercise-QJvwBSGaoc4eI&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdG1ucnE5b3VrNGJ3YXF5OXhybXV1amdwYm81a2FzbGdqMmE5aW92YyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FQJvwBSGaoc4eI%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="313" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd18a7a3f11502698d5784abe077624d/href">https://medium.com/media/bd18a7a3f11502698d5784abe077624d/href</a></iframe><h3>Downloading the WSO2 APIM-3.2.0</h3><p>I’m using the WSO2 APIM-3.2.0 version for this demonstration. You can download the exact product version using this <a href="https://wso2.com/api-management/previous-releases/">link</a> [2].</p><h3>Step 01: Create a sample backend using Mocky.io</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*07fIZhlMmcTWhyJt9aWlLA.png" /><figcaption>Figure 01: Create sample backend in <a href="https://designer.mocky.io/design">Mocky.io</a></figcaption></figure><h3>Step 02: Create the API in WSO2 API Manager</h3><p>You can easily create an API using the Publisher Portal of WSO2 API Manager by adding the Mocky generated URL as an endpoint of your API as follows. For further details you can follow this official <a href="https://apim.docs.wso2.com/en/3.2.0/learn/design-api/create-api/create-a-rest-api/">documentation</a> [3].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qRMOF4L8VXwiDC-5QjClRg.png" /><figcaption>Figure 02: Creating API in Publisher Portal</figcaption></figure><h3>Step 03: Writing the custom mediator</h3><p>Okay! the next step is to write the custom code to create a class mediator by extending the AbstractMediator class. You can follow this <a href="https://apim.docs.wso2.com/en/3.2.0/learn/api-gateway/message-mediation/adding-a-class-mediator/">documentation</a> [4] for further references.</p><p>Please refer to my <a href="https://github.com/shavinsenadheera/WSO2APIM-GetCookiePath/blob/main/src/main/java/org/wso2/custom/mediator/CookieHeaderMediator.java">GitHub link</a> [5] to get the source code.</p><pre>// Get the transportHeaders<br>org.apache.axis2.context.MessageContext msgContext = ((Axis2MessageContext) synCtx).getAxis2MessageContext();<br>Map transportHeaders = (Map) msgContext.getProperty(“TRANSPORT_HEADERS”);</pre><pre>// Get the cookie &quot;set-cookie&quot;<br>String str = transportHeaders.get(“set-cookie”).toString();</pre><pre>// Fetch the cookie path<br>String[] arrOfStr = str.split(&quot;;&quot;, 3);<br>String firstComponent = arrOfStr[0];<br>String pathComponent = arrOfStr[1];<br>String lastComponent = arrOfStr[2];<br>String[] pathArray = pathComponent.split(&quot;=&quot;, 2);<br>String pathName = pathArray[0];<br>String pathValue = pathArray[1];</pre><pre>// Create a new cookie<br>String newCookieValue = firstComponent + &quot;;&quot; + pathName + &quot;=&quot; + &quot;a&quot; + pathValue + &quot;;&quot; + lastComponent;</pre><pre>// Put it into the transportHeaders<br>transportHeaders.put(“set-cookie”, newCookieValue);</pre><pre>// Put transport header into the message context<br>msgContext.setProperty(“TRANSPORT_HEADERS”, transportHeaders);</pre><h3>Step 04: Build the code</h3><p>To build your project you can just run the following maven command.</p><pre>mvn clean install</pre><h3>Step 05: Add the JAR to API Manager Server</h3><p>You can get the build JAR file in the <strong>target </strong>directory of your custom class mediator project and add it to the <strong>&lt;APIM_HOME&gt;/repository/components/lib</strong> directory.</p><p>After adding the JAR file into the <strong>lib </strong>folder we have to <strong>restart the API Manager</strong>.</p><h3>Step 06: Changing the Default Mediation Flow of API Response Flow</h3><p>The, need to add the sequence to the relevant API’s response flow that we need to handle the cookie path by following steps. You can follow this <a href="https://apim.docs.wso2.com/en/3.2.0/learn/api-gateway/message-mediation/changing-the-default-mediation-flow-of-api-requests/">documentation</a> [6] for more details.</p><ol><li>After login into the Publisher Portal, we can select the relevant API and go to “Runtime Configurations”.</li><li>Scroll down the page to the “Response” section.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rQwqyZl8RhwQKR-woeJZ8A.png" /><figcaption>Figure 03: Response Section in Runtime Configurations</figcaption></figure><p>3. Create a sequence as follows to change the default mediation flow in response and save it as a file. (In my case it is response.xml)</p><pre>&lt;?xml version=”1.0&quot; encoding=”UTF-8&quot;?&gt;<br>&lt;sequence xmlns=”http://ws.apache.org/ns/synapse&quot; name=”response”&gt;<br>&lt;class name=”org.wso2.custom.mediator.CookieHeaderMediator” /&gt;<br>&lt;/sequence&gt;</pre><p>4. Then, add the file to the “<strong>Message Mediation</strong>” in “<strong>Response”</strong> by clicking the edit (pencil) icon as follows.</p><figure><img alt="Figure 04: Uploading sequence" src="https://cdn-images-1.medium.com/max/1024/1*yq_81KDaBnE6H4zMXRL9hA.png" /><figcaption>Figure 04: Uploading sequence</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vpZ1JSYh-dst6xOgZKcFIQ.png" /><figcaption>Figure 05: Uploading sequence — Select Custom Policies</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bZAueMM4Yu5WHo_fXC1X7Q.png" /><figcaption>Figure 06: Uploading sequence — Uploading Custom Policies</figcaption></figure><p>Then save the changes.</p><h4>Cheers! 🥂</h4><h4>We have done the configuration part. Let’s focus on the testing part.</h4><h3>Testing the Flow</h3><p>In this demonstration, I just use Postman as an HTTP Client to invoke the created API. If the configuration part is perfectly fine, we can see the cookie path as an “a/TestMe”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YcvNc3uwEk6x6IONkgXcmw.png" /><figcaption>Figure 07: Invoke relevant API using Postman</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mQkifOTwHmVnRLusz03bKg.png" /><figcaption>Figure 07: Checking path of the cookie using Postman</figcaption></figure><p>Congratulations! 🥳 👏 🙌 You’re done! ✅</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fg9582DNuQppxC%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fhero0fwar-karmawhore-rhyming-g9582DNuQppxC&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExbG5iZjRrYnFpMzB4Zm1mY2hzanFpdTR6Y3BiMzNsMzFyM2s1YzV5aCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2Fg9582DNuQppxC%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/72e3aa83d204fa0ae5cae4a54f346d34/href">https://medium.com/media/72e3aa83d204fa0ae5cae4a54f346d34/href</a></iframe><h3>References</h3><p>[1] — <a href="https://designer.mocky.io/">https://designer.mocky.io/</a><br>[2] — <a href="https://wso2.com/api-management/previous-releases/">https://wso2.com/api-management/previous-releases/</a> <br>[3] — <a href="https://apim.docs.wso2.com/en/3.2.0/learn/design-api/create-api/create-a-rest-api/">https://apim.docs.wso2.com/en/3.2.0/learn/design-api/create-api/create-a-rest-api/</a><br>[4] — <a href="https://apim.docs.wso2.com/en/3.2.0/learn/api-gateway/message-mediation/adding-a-class-mediator/">https://apim.docs.wso2.com/en/3.2.0/learn/api-gateway/message-mediation/adding-a-class-mediator/</a><br>[5] — <a href="https://github.com/shavinsenadheera/WSO2APIM-GetCookiePath">https://github.com/shavinsenadheera/WSO2APIM-GetCookiePath</a><br>[6] — <a href="https://apim.docs.wso2.com/en/3.2.0/learn/api-gateway/message-mediation/changing-the-default-mediation-flow-of-api-requests/">https://apim.docs.wso2.com/en/3.2.0/learn/api-gateway/message-mediation/changing-the-default-mediation-flow-of-api-requests/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9caaf3b9162" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate HashiCorp Vault with WSO2 API Manager (APIM)]]></title>
            <link>https://medium.com/@shavinsenadeera/integrate-hashicorp-vault-with-wso2-api-manager-apim-69e1e14604ad?source=rss-2c81d5b33129------2</link>
            <guid isPermaLink="false">https://medium.com/p/69e1e14604ad</guid>
            <dc:creator><![CDATA[Shavindu Senadheera]]></dc:creator>
            <pubDate>Thu, 04 Aug 2022 04:51:37 GMT</pubDate>
            <atom:updated>2022-08-10T14:24:07.027Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c93LK1tejuCuGDhirEVJqg.jpeg" /><figcaption>Image by <a href="https://pixabay.com/users/geralt-9301/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2850276">Gerd Altmann</a> from <a href="https://pixabay.com//?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2850276">Pixabay</a></figcaption></figure><p>First, focus on <strong>HashiCorp Vault…</strong></p><p>HashiCorp Vault is an identity-based secret and encryption management system. Vault provides cryptographic services controlled by authentication and authorization methods. Using Vault’s UI, CLI, or HTTP API, access to confidential and other sensitive data can be securely stored and managed, tightly controlled, and auditable.</p><p>If you want to learn more about the vault, you can refer to HashiCorp’s official blog. They are deeply explaining what, how, why the vaults…</p><p>Okay, let’s get started..✌️</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3ohhwriErowg5DZTSE%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3ohhwriErowg5DZTSE%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3ohhwriErowg5DZTSE%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/aaae661d3d59c8d2e6ca42be43c5aa97/href">https://medium.com/media/aaae661d3d59c8d2e6ca42be43c5aa97/href</a></iframe><h3>Downloading and Installation of HashiCorp</h3><p>Download and install the HashiCorp. You can download HashiCorp using this <a href="https://www.vaultproject.io/downloads">link</a> [1].</p><p>Furthermore, what I am going to do is add the Vault installation directory to the path and make it accessible from anywhere. You can refer to the official install vault documentation <a href="https://learn.hashicorp.com/tutorials/vault/getting-started-install">here</a> [2]. I verified the installation by executing the following vault -version command.</p><pre>s@shavindus~% vault -version<br>Vault v1.11.1 (0f634755745f4adf62ec0723a0b93d6dce5bc33e), built 2022–07–19T20:16:47Z</pre><h3>Downloading the WSO2 APIM-4.0.0</h3><p>You can download the wso2am-4.0.0 using the <a href="https://wso2.com/api-management/previous-releases/">official website</a> [3].</p><h3>Lets start to integration.. 😎</h3><p><strong><em>Step 01: Setting Up the HashiCorp Vault.</em></strong></p><p>You can start the HashiCorp special server which is a special version of a server that works locally called -dev server.</p><p><strong><em>Please Note: </em></strong><em>The “dev” server is a built-in, pre-configured server that is not very secure. Everything in here is stored in-memory and the vault is automatically unsealed. But this is useful for playing with Vault locally. For more information please refer to the official </em><a href="https://learn.hashicorp.com/tutorials/vault/getting-started-dev-server"><em>documentation</em></a><em> [4].</em></p><p><strong><em>Please Note: </em></strong><em>Since everything is stored in the in-memory, we have to ensure that the server keeps running 🏃‍♀️ t</em>hroughout this time.</p><p>Let us start with a special version that works locally.</p><pre>s@shavindus~% vault server -dev <br>==&gt; Vault server configuration:</pre><pre>Api Address: <a href="http://127.0.0.1:8200/">http://127.0.0.1:8200</a><br> Cgo: disabled<br> Cluster Address: <a href="https://127.0.0.1:8201/">https://127.0.0.1:8201</a><br> Go Version: go1.17.12<br> Listener 1: tcp (addr: “127.0.0.1:8200”, cluster address: “127.0.0.1:8201”, max_request_duration: “1m30s”, max_request_size: “33554432”, tls: “disabled”)<br> Log Level: info<br> Mlock: supported: false, enabled: false<br> Recovery Mode: false<br> Storage: inmem<br> Version: Vault v1.11.1, built 2022–07–19T20:16:47Z<br> Version Sha: 0f634755745f4adf62ec0723a0b93d6dce5bc33e<br>==&gt; Vault server started! Log data will stream in below:<br>...<br>WARNING! dev mode is enabled! In this mode, Vault runs entirely in-memory<br>and starts unsealed with a single unseal key. The root token is already<br>authenticated to the CLI, so you can immediately begin using Vault.</pre><pre>You may need to set the following environment variable:</pre><pre>$ export VAULT_ADDR=’<a href="http://127.0.0.1:8200&#39;">http://127.0.0.1:8200&#39;</a></pre><pre>The unseal key and root token are displayed below in case you want to<br>seal/unseal the Vault or re-authenticate.</pre><pre>Unseal Key: pGNWUYScylmBBg6WZJ6Q3hfe/S3cHRWVAp6zN+DTtuY=<br>Root Token: hvs.5z6W1BtvvmOCKEYkjyqVZhjm</pre><pre>Development mode should NOT be used in production installations!</pre><p><strong><em>Step 02: Then, we need to export the VAULT_ADDR and the VAULT_TOKEN as follows,</em></strong></p><p><em>export VAULT_ADDR=</em><a href="http://127.0.0.0:8200/"><em>http://127.0.0.0:8200</em></a><em><br>export VAULT_TOKEN=&lt;Root Token&gt;</em></p><pre>s@shavindus~% export VAULT_ADDR=http://127.0.0.1:8200<br>s@shavindus~% export VAULT_TOKEN=hvs.5z6W1BtvvmOCKEYkjyqVZhjm</pre><p><strong><em>Step 03: Setting up the Key/Value engine.</em></strong></p><p>a. Add the key/value engine.</p><pre>s@shavindus~% vault secrets enable -path=wso2am -version=2 kv</pre><p>b. Add a new secret.</p><pre>s@shavindus~% vault kv put wso2am/keystore_password value=wso2carbon<br>======== Secret Path ========<br>wso2am/data/keystore_password</pre><pre>======= Metadata =======<br>Key                Value<br>---                -----<br>created_time       2022-07-28T05:26:51.538852Z<br>custom_metadata    &lt;nil&gt;<br>deletion_time      n/a<br>destroyed          false<br>version            1</pre><p>c. Check the secret is added.</p><pre>s@shavindus~% vault kv get -field=value wso2am/keystore_password</pre><pre>wso2carbon</pre><p>d. Similarly, add the following secrets also to the vault.</p><pre>s@shavindus~% vault kv put wso2am/admin_password value=wso2carbon<br>======= Secret Path =======<br>wso2am/data/admin_password</pre><pre>======= Metadata =======<br>Key                Value<br>---                -----<br>created_time       2022-07-28T05:30:51.831316Z<br>custom_metadata    &lt;nil&gt;<br>deletion_time      n/a<br>destroyed          false<br>version            1</pre><pre>s@shavindus~% vault kv put wso2am/database_password value=wso2carbon<br>======== Secret Path ========<br>wso2am/data/database_password</pre><pre>======= Metadata =======<br>Key                Value<br>---                -----<br>created_time       2022-07-28T05:30:57.922191Z<br>custom_metadata    &lt;nil&gt;<br>deletion_time      n/a<br>destroyed          false<br>version            1</pre><p><strong><em>Step 04: Add relevant JAR files into APIM Server as follows,</em></strong></p><p>a. Clone the <a href="https://github.com/wso2-extensions/carbon-securevault-hashicorp">GitHub repository</a> [5] and build it. Then, place the jar file (org.wso2.carbon.securevault.hashicorp-1.0.jar) in &lt;APIM_HOME&gt;/repository/components/dropins.</p><p>b. Download the <a href="https://repo1.maven.org/maven2/com/bettercloud/vault-java-driver/5.1.0/">vault-java-driver-5.1.0.jar</a> [6] and placed the jar file in &lt;APIM_HOME&gt;/repository/components/lib.</p><p><strong><em>Step 05: Configure the API Manager.</em></strong></p><p>a. Go to &lt;APIM_HOME&gt;/bin and run the following ./ciphertool.sh -Dconfigure command.</p><p><strong><em>Please Note: </em></strong><em>The default password of the internal keystore is “</em><strong><em>wso2carbon</em></strong><em>”.</em></p><pre>s@shavindus bin % ./ciphertool.sh -Dconfigure<br>Encrypting using Internal KeyStore.<br>{type: JKS, alias: wso2carbon, path: /Users/shavindus/Downloads/WSO2 Setups/wso2am-4.0.0/repository/resources/security/wso2carbon.jks}</pre><pre>[Please Enter Internal KeyStore Password of Carbon Server : ]</pre><pre>Internal KeyStore of Carbon Server is initialized Successfully<br>Secret Configurations are written to the property file successfully</pre><p>b. Add the following configurations into &lt;APIM_HOME&gt;/repository/conf/security/secret-conf.properties.</p><pre>secVault.enabled=true<br>secretRepositories=vault<br>secretRepositories.vault.provider=org.wso2.carbon.securevault.hashicorp.repository.HashiCorpSecretRepositoryProvider<br>secretRepositories.vault.properties.address=<a href="http://127.0.0.1:8200/">http://127.0.0.1:8200</a><br>secretRepositories.vault.properties.namespace=ns1<br>secretRepositories.vault.properties.enginePath=wso2am<br>secretRepositories.vault.properties.engineVersion=2</pre><p>c. Add the following configurations into &lt;APIM_HOME&gt;/repository/conf/log4j2.properties.</p><pre>logger.org-wso2-carbon-securevault-hashicorp.name=org.wso2.carbon.securevault.hashicorp<br>logger.org-wso2-carbon-securevault-hashicorp.level=INFO<br>logger.org-wso2-carbon-securevault-hashicorp.additivity=false<br>logger.org-wso2-carbon-securevault-hashicorp.appenderRef.CARBON_CONSOLE.ref = CARBON_CONSOLE</pre><p>Then add, org-wso2-carbon-securevault-hashicorp to loggers as follows,</p><pre>loggers = org-wso2-carbon-securevault-hashicorp, AUDIT_LOG, trace-messages,...</pre><p>d. Edit the relevant configurations in &lt;APIM_HOME&gt;/repository/conf/deployment.toml as following.</p><p>Add these lines at the end of the file.</p><pre>[secrets]<br>admin_password = &quot;&quot;<br>keystore_password = &quot;&quot;<br>database_password = &quot;&quot;</pre><p>Add the encrypted password alias to the relevant section in the deployment.toml file using the placeholder: $secret{alias}.</p><pre>[super_admin]<br>...<br>password=&quot;$secret{admin_password}&quot;</pre><pre>[database.apim_db]<br>...<br>password = &quot;$secret{database_password}&quot;</pre><pre>[database.shared_db]<br>...<br>password = &quot;$secret{database_password}&quot;</pre><pre>[keystore.tls]<br>...<br>password = &quot;$secret{keystore_password}&quot; <br>key_password = &quot;$secret{keystore_password}&quot;</pre><p><strong><em>Step 06 (Last Step) : Start the API Manager Server.</em></strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FtMPSeKEplOfK0%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FtMPSeKEplOfK0%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FtMPSeKEplOfK0%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/242dce2ce65f9381cf35fb5cfd3dbf19/href">https://medium.com/media/242dce2ce65f9381cf35fb5cfd3dbf19/href</a></iframe><p>Start the APIM server and successfully log in to the server with new password which is defined as “wso2carbon” instead the default password “admin” of the admin user.</p><p><strong><em>Please Note:</em></strong> While the server is starting we need to input the password of the KeyStore and the Root Token as follows.</p><pre>s@shavindus bin % sh api-manager.sh <br>JAVA_HOME environment variable is set to /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home<br>CARBON_HOME environment variable is set to /Users/shavindus/Downloads/WSO2 Setups/wso2am-4.0.0<br>Using Java memory options: -Xms256m -Xmx1024m<br>[2022-07-28 14:31:46,357]  INFO {org.wso2.config.mapper.ConfigParser} - Initializing configurations with deployment configurations<br>andes [org.wso2.andes.wso2.internal.QpidBundleActivator] INFO : Setting BundleContext in PluginManager<br>callhome [org.wso2.carbon.callhome.internal.CallHomeActivator] DEBUG : Activating CallHome agent<br>[Enter KeyStore and Private Key Password :]<br>[2022-07-28 14:32:18,095]  INFO - HashiCorpSecretRepository Initializing HashiCorp Secure Vault<br>[Enter the Root Token: ]</pre><p>Yes! We done it! 🥳</p><p><em>Wait! Wait! </em>😳</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FVeB9ieebylsaN5Jw8p%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FVeB9ieebylsaN5Jw8p%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FVeB9ieebylsaN5Jw8p%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="437" frameborder="0" scrolling="no"><a href="https://medium.com/media/7729f5c80286f568de448b634e57321c/href">https://medium.com/media/7729f5c80286f568de448b634e57321c/href</a></iframe><p>What about the scenario that starts the <strong>APIM server as a background job?</strong></p><p>- Oh...! 😩😩😩</p><p>Just Calm Down! 😎 We can easily do that by following the below steps instead of doing Step 6,</p><p>First, add only the password “wso2carbon” (the primary KeyStore password) to this file password-tmp and placed it in the &lt;APIM_HOME&gt; directory.</p><p>Then, start the server by using the command “sh api-manager.sh start”.</p><p>Now, actually we done it! 😄✌️</p><h3><strong>References</strong></h3><p>[1] -<a href="https://www.vaultproject.io/downloads">https://www.vaultproject.io/downloads</a><br>[2] -<a href="https://learn.hashicorp.com/tutorials/vault/getting-started-install">https://learn.hashicorp.com/tutorials/vault/getting-started-install</a><br>[3] -<a href="https://wso2.com/api-management/previous-releases/">https://wso2.com/api-management/previous-releases/</a><br>[4] -https://learn.hashicorp.com/tutorials/vault/getting-started-dev-server<br>[5] -<a href="https://github.com/wso2-extensions/carbon-securevault-hashicorp">https://github.com/wso2-extensions/carbon-securevault-hashicorp</a><br>[6] -<a href="https://repo1.maven.org/maven2/com/bettercloud/vault-java-driver/5.1.0/">https://repo1.maven.org/maven2/com/bettercloud/vault-java-driver/5.1.0/</a><br>[7] -<a href="https://www.yenlo.com/blogs/hashicorp-vault-with-wso2-identity-server/">https://www.yenlo.com/blogs/hashicorp-vault-with-wso2-identity-server/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69e1e14604ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>