<?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 Pasindu Yeshan Abeysinghe on Medium]]></title>
        <description><![CDATA[Stories by Pasindu Yeshan Abeysinghe on Medium]]></description>
        <link>https://medium.com/@pasinduyeshan?source=rss-9d51bbef07d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*D9ymCA1E9pQTGJr0K2im5w.jpeg</url>
            <title>Stories by Pasindu Yeshan Abeysinghe on Medium</title>
            <link>https://medium.com/@pasinduyeshan?source=rss-9d51bbef07d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:12:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pasinduyeshan/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[Securely Running WSO2 Identity Server Behind Reverse Proxy with Docker]]></title>
            <link>https://pasinduyeshan.medium.com/securely-running-wso2-identity-server-behind-reverse-proxy-with-docker-0bf843229418?source=rss-9d51bbef07d------2</link>
            <guid isPermaLink="false">https://medium.com/p/0bf843229418</guid>
            <dc:creator><![CDATA[Pasindu Yeshan Abeysinghe]]></dc:creator>
            <pubDate>Mon, 28 Jul 2025 17:44:22 GMT</pubDate>
            <atom:updated>2025-07-28T17:44:22.642Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mGorIrPGm2tdR9ZAj5kD2A.png" /></figure><h3>What is a Reverse Proxy?</h3><p>A <strong>reverse proxy</strong> is a server that sits in front of your backend service and acts as an intermediary for client requests. It intercepts traffic from the public, forwards it to the right internal server, and sends the response back to the client.</p><p>Why bother with one?</p><ul><li>🔐 <strong>SSL Termination</strong>: It handles HTTPS decryption so your backend service doesn’t have to.</li><li>🛡 <strong>Centralized Security</strong>: You can apply firewalls, rate limits, or authentication rules at the gateway.</li><li>🔒 <strong>Backend Protection</strong>: Your app remains hidden behind the proxy — clients never talk to it directly.</li><li>⚖️ <strong>Load Balancing</strong>: Easily distribute traffic across multiple backend instances if you need to scale.</li></ul><h3>Why Use One With WSO2 Identity Server?</h3><p>Let’s use a metaphor:</p><p>Imagine <strong>WSO2 Identity Server</strong> (WSO2 IS) is your backstage manager at a concert — checking passes, managing schedules, and keeping the event running. Would you also make them stand at the door dealing with loud crowds?</p><p>Nope — you’d hire a <strong>bouncer</strong>. That’s your <strong>reverse proxy</strong>.</p><p>In our case:</p><ol><li><strong>NGINX Reverse Proxy (The Bouncer)</strong><br> The front-facing gatekeeper. It accepts public HTTPS traffic on proxy.wso2is.com and forwards valid requests to WSO2 IS securely.</li><li><strong>WSO2 Identity Server (The Backstage Manager)</strong><br> The brains of the operation. It manages user identities, SSO, OAuth2, user sessions, etc.</li><li><strong>Docker (The Venue)</strong><br>Spins up both services in isolated containers, links them over an internal Docker network, and keeps your local machine clean.</li></ol><h3>Quick Start Guide</h3><p>📝 <em>Note: This is intended for </em><strong><em>local development only</em></strong><em> — not production use. It’s a learning tool to help you understand how WSO2 Identity Server, NGINX, and Docker can work together seamlessly.</em></p><p>👉 GitHub Repo: <a href="https://github.com/PasinduYeshan/wso2-is-reverse-proxy/tree/deployment/docker">link</a></p><p>Here’s how to launch this setup on your local machine in a few simple steps.</p><h4>1. Update Your Hosts File</h4><p>Tell your system where proxy.wso2is.com should resolve to:</p><pre>127.0.0.1    proxy.wso2is.com</pre><ul><li>On macOS/Linux: /etc/hosts</li><li>On Windows: C:\Windows\System32\drivers\etc\hosts</li></ul><h4>2. Clone the Repository</h4><pre>git clone https://github.com/PasinduYeshan/wso2-is-reverse-proxy -b deployment/docker<br>cd wso2-is-reverse-proxy</pre><h4>3. Add SSL Certificates</h4><p>To enable HTTPS for NGINX:</p><ul><li>Place proxy.crt (certificate) and proxy.key (private key) into the nginx/ssl/ directory.</li></ul><p>Generate self-signed certs for local testing like this:</p><pre>openssl req -x509 -newkey rsa:4096 -nodes -keyout proxy.key -out proxy.crt -days 365</pre><h4>4. Launch with Docker Compose</h4><pre>docker-compose up -d</pre><p>This starts both NGINX and WSO2 IS containers. It might take a minute or two.</p><h4>5. Access the Identity Server</h4><p>Visit 👉 <a href="https://proxy.wso2is.com/console">https://proxy.wso2is.com/console</a></p><p>Login with:</p><ul><li><strong>Username:</strong> admin</li><li><strong>Password:</strong> admin</li></ul><p>You’re now securely accessing WSO2 Identity Server via NGINX!</p><h3>What’s Happening Under the Hood?</h3><h4><strong>NGINX Config (</strong><strong>nginx/nginx.conf)</strong></h4><pre>http {<br>    upstream ssl.is.dev.wso2.com {<br>        server internal.wso2is.com:9443;<br>        # Add more WSO2 IS instances here for load balancing<br>        # server internal.wso2is-2.com:9443;<br>        ip_hash;  # Ensures sticky sessions based on client IP<br>    }<br><br>    server {<br>        listen 443 ssl;<br>        server_name proxy.wso2is.com;<br>        ssl_certificate /etc/nginx/ssl/proxy.crt;<br>        ssl_certificate_key /etc/nginx/ssl/proxy.key;<br><br>        location / {<br>            proxy_set_header X-Forwarded-Host $host;<br>            proxy_set_header X-Forwarded-Server $host;<br>            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>            proxy_set_header Host $http_host;<br>            proxy_read_timeout 5m;<br>            proxy_send_timeout 5m;<br>            <br>            proxy_pass https://ssl.is.dev.wso2.com/;<br>        }<br>    }<br>}</pre><ul><li><strong>listen 443 ssl</strong>: NGINX accepts HTTPS traffic on port 443.</li><li><strong>SSL Certificates</strong>: Handles HTTPS termination using your self-signed or trusted certs.</li><li><strong>upstream block</strong>: Defines a group of backend servers. Here, it&#39;s just one instance (internal.wso2is.com:9443), but you can add more for <strong>load balancing</strong>.</li><li><strong>ip_hash</strong>: Ensures the same client IP consistently hits the same WSO2 IS instance—useful for sticky sessions.</li><li><strong>Headers</strong>: Pass important request headers so WSO2 IS can properly interpret the original request source.</li><li><strong>proxy_pass</strong>: Forwards the request to the internal WSO2 IS service over HTTPS.</li></ul><h4>WSO2 IS (wso2-config/deployment.toml)</h4><pre>[server]<br>hostname = &quot;proxy.wso2is.com&quot;<br><br>[transport.https.properties]<br>proxyPort = 443</pre><p>Why this matters:</p><ul><li>hostname ensures WSO2 IS generates URLs that match the proxy domain</li><li>proxyPort ensures redirect URLs don’t point to the internal port (9443)</li></ul><p>Without these tweaks, callbacks and redirects will break because the browser sees mismatched domains or ports.</p><blockquote>Want to use <strong>Podman</strong> instead of Docker? Check the main branch for Podman-compatible instructions.</blockquote><h3>Wrapping Up</h3><p>This setup gives you a clean, isolated environment to explore:</p><ul><li>How NGINX acts as a secure gateway</li><li>How WSO2 IS works in reverse-proxy environments</li><li>How Docker Compose simplifies orchestration</li></ul><p>For production deployments, refer to the official WSO2 documentation for proper configurations and hardening strategies:</p><p>🔗 <a href="https://is.docs.wso2.com/en/latest/deploy/deployment-guide/">WSO2 IS Deployment Guide</a></p><p>Hopefully, this guide gave you a strong foundation to build on. It was crafted with the help of ChatGPT ✨</p><p>Now go ahead — spin up WSO2 Identity Server and see it in action.<br>You might just love what it can do. 💡</p><p>👉 GitHub Repo: <a href="https://github.com/PasinduYeshan/wso2-is-reverse-proxy/tree/deployment/docker">link</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0bf843229418" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Passwordless Login with Passkeys in WSO2 Asgardeo]]></title>
            <link>https://pasinduyeshan.medium.com/passwordless-login-with-passkeys-in-wso2-asgardeo-1d239e17af31?source=rss-9d51bbef07d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d239e17af31</guid>
            <category><![CDATA[passkey]]></category>
            <category><![CDATA[secure-login]]></category>
            <category><![CDATA[identity]]></category>
            <category><![CDATA[asgardeo]]></category>
            <category><![CDATA[wso2]]></category>
            <dc:creator><![CDATA[Pasindu Yeshan Abeysinghe]]></dc:creator>
            <pubDate>Sat, 07 Jun 2025 20:53:47 GMT</pubDate>
            <atom:updated>2025-06-07T20:53:47.157Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s be honest, passwords are a pain. We all have dozens of them. We’re told to make them long, complex, and unique, which means we either forget them or, let’s face it, reuse them. We’ve spent years applying band-aid solutions — password managers, multi-factor authentication, frequent resets — but these are just workarounds. What if we could eliminate passwords entirely?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*239sVKSRa6-2sUAqXGN6-g.png" /></figure><p>That’s where <strong>Passkeys</strong> come in.</p><p>Created by the FIDO Alliance, passkeys represent a major shift from traditional “what you know” authentication (passwords) to “what you have” (your device). They’re designed to be both more secure and more user-friendly.</p><p>In this article, First, I’ll demystify what passkeys are in simple terms very briefly. Then, I’ll show you just how easy it is to add them to your application using the WSO2 Asgardeo. Let’s dive in. 👇</p><h3>What Is a Passkey?</h3><p>Forget the jargon — think of a passkey as a digital, unbreakable key that lives securely on your device and works only for a specific website or app. When you register on a site, your device (your phone or laptop) generates a unique pair of cryptographic keys:</p><ul><li><strong>🔓 Public Key (The Lock):</strong> This gets sent to the server (Relying Party). It’s like a lock designed just for your device — safe to share because it can’t be used on its own.</li><li><strong>🔐 Private Key (The VIP Key):</strong> This stays securely on your device, protected by secure hardware like a Secure Enclave or TPM. It never leaves your device and is accessed using biometrics (like a fingerprint or face scan) or your device PIN.</li></ul><h3>How Passkey Login Works (Simplified Flow)</h3><ol><li>You click “Sign in” on the website.</li><li>The server sends a one-time challenge to your device.</li><li>You verify yourself with biometrics or PIN.</li><li>Your device signs the challenge using your private key.</li><li>The server checks the signature using your public key.</li><li>You’re securely logged in — no passwords involved.</li></ol><blockquote><em>Your private key never leaves your device and is never shared — so it can’t be phished, reused, or stolen in a breach.</em></blockquote><h3>Why Are Passkeys a Game-Changer?</h3><ul><li><strong>🛡️ They are Phishing-Proof:</strong> A passkey is tied to the website it was created for. A hacker can’t trick you into using your Google passkey on their fake site <em>go0ogle-login.scam</em>. The browser knows the difference, and the key simply won’t work.</li><li><strong>⚡ Fast &amp; Frictionless:</strong> What’s easier: typing P@ssw0rdStr0ng!# or just glancing at your phone for Face ID? It turns the login process from a chore into a seamless, one-second action.</li><li><strong>🔐 No More Passwords to Steal:</strong> If your application’s server is ever breached, there are no passwords for hackers to steal. All they get are the public “locks,” which are useless without the private “keys” stored safely on your users’ devices.</li><li><strong>🔄 They Sync Across Your Devices:</strong> Thanks to providers like Google Password Manager and Apple iCloud Keychain, when a user creates a passkey on their iPhone, it’s automatically available on their MacBook and iPad. They don’t have to worry about losing a single device.</li></ul><p>The benefits are clear. But now you’re probably thinking about the implementation — handling WebAuthn APIs, managing cryptographic challenges, and securing key pairs. Doing this from scratch is complex and risky.</p><h4>That’s Where WSO2 Asgardeo Comes In 🚀</h4><p>Asgardeo acts as your out-of-the-box <strong>Relying Party</strong>, handling the entire passkey flow securely and reliably. It abstracts away the protocol details, server logic, and validation steps — so you can focus on building your app, not reinventing authentication infrastructure.</p><h3>Let’s Get Started: A Step-by-Step Guide</h3><h4>Prerequisites</h4><p>Before we start, make sure you have the following:</p><ol><li><strong>An Asgardeo Account:</strong> If you’re new to Asgardeo, you can follow the <a href="https://wso2.com/asgardeo/docs/get-started/create-asgardeo-account/">official guide to create an account</a>.</li><li><strong>A Registered Application:</strong> You need an application registered in Asgardeo. You can register your own or use one of the official <a href="https://wso2.com/asgardeo/docs/get-started/try-samples/">sample applications</a>. For this guide, I’ll use the React sample app.</li><li><strong>A Test User:</strong> Create a test user in your organization so you can test the login flow.</li></ol><blockquote>Right now, if you run the sample app, you’ll see a simple login page asking for a username and password. Let’s add passkeys to the mix.</blockquote><h4>Step 1: Add Passkey as a Login Option</h4><p>First, we need to update our application’s login flow to include passkeys.</p><ol><li>On the Asgardeo Console, navigate to <strong>Applications</strong>.</li><li>Select your application from the list.</li><li>Go to the <strong>Login Flow</strong> tab and select <strong>Add Passkey login</strong> from the list.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kUC2ctww1WxOgQDX.png" /></figure><ol><li>Click <strong>Update</strong> to save the changes.</li></ol><blockquote>You’ll now see an info banner that says, <em>“Passkey progressive enrollment is disabled.”</em> Let’s take a closer look at what that means.</blockquote><h4>Step 2: Enable Progressive Enrollment</h4><p>Progressive enrollment allows users to register a passkey during the login flow, rather than manually setting it up in their profile.</p><ol><li>Navigate to <strong>Connections</strong> from the side panel.</li><li>Find <strong>Passkey</strong> in the list and click the <strong>Set up</strong> button. (or use the banner link from Step 1).</li><li>Check the box for <strong>“Allow passkey progressive enrollment”</strong>.</li><li>Click <strong>Update</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AGZDF8DqMck9Ksmx.png" /></figure><blockquote>For now, we’ll leave “Usernameless authentication” unchecked; — we’ll explore that later.</blockquote><h4>Step 3: Add the Conditional Authentication Script</h4><p>Now that progressive enrollment is enabled, we need to define how Asgardeo should handle cases where a user <strong>tries to sign in with a passkey but doesn’t have one yet</strong>. This is where <strong>Conditional Authentication</strong> comes into play.</p><ol><li>Go back to your application’s <strong>Login Flow</strong> tab.</li><li>Scroll to the bottom and enable the <strong>Conditional Authentication</strong> toggle. This opens up the script editor.</li><li>In the <strong>Templates</strong> section on the right, find <strong>Passkey Enrollment</strong> and click the <strong>+</strong> icon next to the <strong>Passkey Progressive Enrollment</strong> template.</li><li>Click <strong>Confirm</strong> to add the script to the editor.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I8vbJbXA9W2oR0Ez.png" /></figure><blockquote>For even greater security, you could customize this script to require an additional factor, like an email or SMS OTP, before enrollment.</blockquote><h4>Putting It All Together: The Final User Experience</h4><p>Now that everything is configured, let’s walk through the end-to-end experience for a new user:</p><ol><li><strong>First Login Attempt:</strong> A new user lands on your application’s login page and clicks <strong>“Sign in with a passkey.”</strong></li><li><strong>The Fallback:</strong> Since they haven’t registered a passkey yet, adaptive script prompts them to sign in using their trusted username and password to verify their identity.</li><li><strong>The Enrollment Invitation:</strong> After they successfully enter their password, a new screen appears inviting them to <strong>“Create your passkey”</strong> for faster logins next time.</li><li><strong>Creating the Passkey:</strong> The user agrees and uses their device’s biometrics (Face ID, fingerprint) or PIN to approve and save the new passkey.</li><li><strong>The Next Seamless Login:</strong> The next time the user visits your site, they can click “Sign in with a passkey,” confirm their identity using biometrics, and be logged in instantly. No password needed.</li></ol><h4>A Quick Word on “Usernameless Authentication”</h4><p>You might remember that in Step 2, we left a checkbox unticked: <strong>“Enable usernameless authentication.”</strong> So, what is it?</p><p>By default, our current flow still requires the user to enter their username first. When you enable usernameless authentication, you activate what are known as <strong>“discoverable credentials,”</strong> where the passkey itself remembers the user’s identity.</p><p>The user experience becomes even smoother:</p><ul><li>A user arrives at your login page and clicks <strong>“Sign in with Passkey.”</strong></li><li>The browser opens a prompt showing a list of their saved accounts for your site (e.g., “Sign in as alice@email.com”).</li><li>They simply select their account, use their biometrics, and they’re in. No typing is required at all.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*vS7zoub-xk7LTC2I.gif" /></figure><p>That’s a wrap! I hope this guide helped you understand how passkeys work — and how easy it is to implement passwordless login with WSO2 Asgardeo.</p><p>Thanks for reading — here’s to safer, smoother authentication. 🔐</p><p><strong>References</strong></p><ul><li><a href="https://wso2.com/asgardeo/docs/guides/authentication/passwordless-login/add-passwordless-login-with-passkey/">https://wso2.com/asgardeo/docs/guides/authentication/passwordless-login/add-passwordless-login-with-passkey/</a></li><li><a href="https://wso2.com/asgardeo/docs/guides/authentication/conditional-auth/passkey-progressive-enrollment-based-template/">https://wso2.com/asgardeo/docs/guides/authentication/conditional-auth/passkey-progressive-enrollment-based-template/</a></li><li><a href="https://specopssoft.com/blog/passkeys-benefits-limitations-passwords/">https://specopssoft.com/blog/passkeys-benefits-limitations-passwords/</a></li><li><a href="https://developers.google.com/identity/passkeys">https://developers.google.com/identity/passkeys</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d239e17af31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplify Password Security with WSO2 Asgardeo: Rule-Based Password Expiration & More ]]></title>
            <link>https://systemweakness.com/simplify-password-security-with-wso2-asgardeo-rule-based-password-expiration-more-8331e90c6675?source=rss-9d51bbef07d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8331e90c6675</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[password-security]]></category>
            <category><![CDATA[identity-management]]></category>
            <category><![CDATA[asgardeo]]></category>
            <category><![CDATA[wso2]]></category>
            <dc:creator><![CDATA[Pasindu Yeshan Abeysinghe]]></dc:creator>
            <pubDate>Mon, 07 Oct 2024 19:08:06 GMT</pubDate>
            <atom:updated>2024-10-15T14:51:42.042Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*nOL_zDbN-7ZLndr2.jpg" /></figure><p>In today’s digital age, password security isn’t just a priority — it’s a fundamental necessity. 🔐 Weak or outdated passwords are like open invitations for cyber threats, leaving your systems vulnerable. On the other hand, frequent password changes can be frustrating for users, especially when they have to repeatedly come up with complex, unique passwords. Fortunately, tools like <strong>WSO2 Asgardeo</strong> empower organizations to strike a balance between strong security and user convenience. In this article, we’ll explore how Asgardeo’s powerful password validation features, can help bolster your organization’s security without overwhelming users. Let’s dive in! 🌊</p><h3>Why Password Validation Matters 🤔</h3><p>Let’s be honest — remembering strong passwords can be a hassle. It can be frustrating to be repeatedly asked to change your password, but the cost of using weak or outdated passwords can be far worse, exposing your systems to a host of cyberattacks. Password validation helps ensure that users create complex passwords that are tough to crack, reducing the risk of breaches. By updating passwords regularly, organizations minimize these risks and align with industry security standards and regulations. Meeting these regulations is not just about improving security — it’s also crucial for maintaining legal compliance and protecting both users and the business from potential penalties or breaches. It’s a win-win for compliance, protection, and peace of mind. 🏆</p><h3>What Is WSO2 Asgardeo?</h3><p><strong>WSO2 Asgardeo</strong> is a cloud-based <strong>Identity as a Service (IDaaS)</strong> platform. Simply put, it helps you manage user identities and access in a secure and efficient way. With features like <strong>Single Sign-On (SSO)</strong>, <strong>Multi-Factor Authentication (MFA)</strong>, and <strong>user provisioning</strong>, Asgardeo is your one-stop shop for identity management.</p><h3>Password Validation in Asgardeo</h3><p>Asgardeo offers a powerful suite of password validation tools to boost security, including:</p><ol><li><strong>Rule-Based Password Expiration</strong> ⏳</li><li><strong>Password History Count</strong> 🔄</li><li><strong>Password Input Validation</strong> 📝</li></ol><p>Let’s dive into each of these features in detail!</p><p>To get started with Asgardeo’s Password Validation:</p><ul><li>Log in to the <strong>Asgardeo Console</strong> and navigate to <strong>“Login and Registration”</strong>.</li><li>Under <strong>Login Security</strong>, choose <strong>Password Validation</strong>.</li></ul><h3>1. Rule-Based Password Expiration</h3><h4>What Is It?</h4><p>Rule-based password expiration allows you to set custom password expiration rules based on user attributes such as roles or groups. Unlike a one-size-fits-all policy, this feature helps you tailor expiration rules that match each user group’s unique security needs.</p><h4>Why Is It Useful?</h4><ul><li><strong>Customized Security:</strong> Different users need different levels of security. Admins, for instance, might need to change passwords more frequently compared to regular users.</li><li><strong>Flexibility:</strong> You can skip password expiration for certain service accounts or apply stricter policies for high-risk roles.</li><li><strong>Prioritization:</strong> Set rule precedence to ensure the correct policy applies when users belong to multiple groups or roles.</li></ul><p>Imagine you’re managing a company called <strong>TechNova Corp</strong> with diverse teams and roles:</p><p><strong>Roles:</strong></p><ul><li><strong>Administrators Role:</strong> Users with critical system access need maximum security, so their passwords expire every <strong>30 days</strong>.</li><li><strong>Platform Engineers Role:</strong> For example, platform engineers who need shared access to manage system-level configurations might require <strong>no expiration</strong>. This ensures uninterrupted access to critical infrastructure without the risk of unexpected password expiry.</li></ul><p><strong>Groups:</strong></p><ul><li><strong>Developers Group:</strong> Members working on code repositories need a balance between security and productivity, so their passwords expire every <strong>60 days</strong>.</li><li><strong>Support Staff Group (Contractors):</strong> Contractors handling customer queries require frequent updates, with their passwords expiring every <strong>15 days</strong> to limit exposure given their temporary access.</li></ul><p>Here’s how you could set up rule-based password expiration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JWNSKfDbGej9bw3wkPbW4w.png" /></figure><p>Rules are evaluated in priority order, from top to bottom. For instance, if a user is both in the <strong>Developers Group</strong> and has the <strong>Administrators Role</strong>, the password expiry of <strong>60 days</strong> will apply, as the Developers Group rule is above the Administrators Role rule.</p><p>If no specific rule is applied to a user, the default password expiry will be used. This default setting is configurable, allowing you to adjust the expiration period to suit your organization’s needs.</p><h3>2. Password History Count</h3><h4>What Is It?</h4><p>Password history count prevents users from reusing their previous passwords, requiring new and unique passwords every time they update.</p><h4>Why Is It Useful?</h4><ul><li><strong>Increased Security:</strong> Discourages users from recycling old passwords that may be compromised.</li><li><strong>Compliance:</strong> Ensures compliance with standards that demand unique password histories.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*m5U8M6RiThCA-ykOJ_7IuQ.png" /></figure><p>Let’s take <strong>Alex</strong>, a member of the finance team at TechNova Corp. The company policy is set so that users cannot reuse any of their last <strong>5 passwords</strong>. This means:</p><ul><li>When Alex changes his password, he must come up with something entirely new.</li><li>He can’t rotate between “Finance#1”, “Finance#2”, and “Finance#3”.</li><li>This reduces the risk of someone guessing his password based on previous ones.</li></ul><p>By enforcing a password history count, you encourage users like Alex to create fresh, unique passwords every time. 🌟</p><h3>3. Password Input Validation</h3><h4>What Is It?</h4><p>Password input validation enforces complexity requirements for passwords, ensuring that they meet specific security standards. This includes setting rules for minimum and maximum lengths, requiring a mix of character types (such as uppercase letters, lowercase letters, numbers, and special symbols), and preventing repeated or sequential characters.</p><h4>Why Is It Useful?</h4><ul><li><strong>Stronger Passwords:</strong> Complexity requirements make passwords more resilient against attacks, making them harder to guess or crack.</li><li><strong>User Guidance:</strong> By guiding users to create complex passwords, you help maintain high security standards, reducing the risk of unauthorized access.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*X2vxUmRrMRnd7pD5x9NXpQ.png" /></figure><p>By implementing password input validation, you ensure that users create strong, secure passwords that better protect their accounts and your organization’s sensitive data. 💪</p><h3>Tips and Best Practices</h3><ul><li><strong>Balance Security &amp; Usability:</strong> Strong passwords are crucial, but overly complex requirements can frustrate users. Find a balance!</li><li><strong>Implement Multi-Factor Authentication (MFA):</strong> Adding MFA alongside strong passwords provides an extra layer of security, making it much harder for unauthorized users to gain access. 🔒</li><li><strong>Educate Your Users:</strong> Host a fun training session or share tips on good password habits — like avoiding common phrases or using password managers.</li></ul><h3>Wrapping Up</h3><p>Enhancing password security doesn’t have to be complicated. With WSO2 Asgardeo, you can easily implement features like rule-based password expiration, password history enforcement, and password complexity validation to strengthen your security practices.</p><p>For more details on configuring password validation, check out the <a href="https://wso2.com/asgardeo/docs/guides/user-accounts/account-security/password-validation/"><strong>official WSO2 Asgardeo documentation</strong></a>.</p><p>Thanks for reading! If you have any questions or insights, drop a comment below. Together, let’s make the digital world a safer place. 🌐🔒</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8331e90c6675" width="1" height="1" alt=""><hr><p><a href="https://systemweakness.com/simplify-password-security-with-wso2-asgardeo-rule-based-password-expiration-more-8331e90c6675">Simplify Password Security with WSO2 Asgardeo: Rule-Based Password Expiration &amp; More 🚀</a> was originally published in <a href="https://systemweakness.com/">System Weakness</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Device Attribute-Based Authentication with WSO2 IS and Entgra]]></title>
            <link>https://pasinduyeshan.medium.com/device-attribute-based-authentication-with-wso2-is-and-entgra-9b5f70b8c235?source=rss-9d51bbef07d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b5f70b8c235</guid>
            <category><![CDATA[identity-and-access]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[entgra]]></category>
            <category><![CDATA[adaptive-authentication]]></category>
            <category><![CDATA[wso2-identity-server]]></category>
            <dc:creator><![CDATA[Pasindu Yeshan Abeysinghe]]></dc:creator>
            <pubDate>Sat, 28 Sep 2024 11:26:18 GMT</pubDate>
            <atom:updated>2024-09-28T11:26:18.790Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*emW6YPo6q8csxMMxhbxtiw.png" /></figure><p>In today’s digital landscape, the sensitivity of the data your application handles often dictates the level of security measures you need to implement. For high-stakes applications like banking, healthcare, or government services, it’s not just about protecting data — it’s about balancing that protection with a seamless user experience. However, as security demands escalate, adding more authentication layers can create unnecessary friction, frustrating users 😞 and hindering access to critical information.</p><p>So, how do you maintain airtight security without making your login process cumbersome? Device attribute-based authentication offers a solution. Instead of merely increasing the number of authentication steps, this method restricts login access to approved devices, ensuring that only trusted devices can access your application. By delving deeper and evaluating specific device attributes, you can fine-tune your authentication process for an even higher level of security — without impeding the user experience.</p><h3>Enhancing Security While Keeping It User-Friendly</h3><p>By integrating WSO2 Identity Server with Entgra, you can elevate your application’s security through device attribute-based adaptive authentication. This approach provides a smarter, more efficient way to control not only who gains access to your app but also from which devices. Rather than relying solely on passwords or user credentials, this method ensures that only approved devices with specific, secure configurations can log in.</p><p>Here are the key objectives you can achieve using device attribute-based adaptive authentication::</p><ul><li><strong>Restrict Login to Registered Devices</strong>: Allow users to log in only from devices that have been enrolled and registered. This prevents unauthorized devices from accessing sensitive information, even if user credentials are compromised.</li><li><strong>Control Access Based on Device Attributes</strong>: Enhance security further by permitting login only from devices that meet specific conditions, such as not being rooted, not in developer mode, or meeting a certain encryption level. This ensures that even registered devices must maintain a secure state to access the application.</li></ul><p>By integrating device attributes directly into the authentication flow, your app benefits from an adaptive security model that responds to the context of login attempts. Rather than burdening users with multiple authentication steps, you rely on the security of the devices themselves — making the process both frictionless and highly secure.</p><h3>How It Works</h3><p>Suppose you’re building a mobile app and want to ensure that only safe, compliant devices can log in while maintaining a smooth experience for legitimate users. Here’s how you can achieve this using WSO2 Identity Server and Entgra:</p><h4>Device Enrolment Flow</h4><p>Before a user can access your application, they must enroll their device using Entgra’s device management API. The flow works as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*91S-58vQRSLfoDyKEhZSOg.png" /></figure><ol><li><strong>Enrollment Initiation:</strong> When the user opens the app for the first time, they are prompted to enroll their device. This action triggers the Entgra SDK to send a request to Entgra’s server.</li><li><strong>User Authentication:</strong> Entgra requests authorization from WSO2 Identity Server (WSO2 IS), which authenticates the user and returns their details to Entgra for provisioning, if not already provisioned.</li><li><strong>Device Registration Token Generation:</strong> Entgra processes the response and provisions the user. It generates a token that allows for device enrollment.</li><li><strong>Device Enrollment Completion:</strong> Using this token, the device is registered, and its identifier is stored by Entgra.</li></ol><p>This enrollment process ensures that only devices recognized and registered by Entgra can attempt to authenticate with your application.</p><h3>Login Flow: Authenticating Users Based on Device Attributes</h3><p>Once the device is enrolled, the login process leverages device attributes to make authentication decisions in real time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*PpZN83nswwFQMCYI2NusZg.png" /></figure><ol><li><strong>Authorization Request:</strong> A login request is sent to WSO2 IS, including the device identifier registered during enrollment.</li><li><strong>Credential Verification:</strong> The user provides their credentials, which are validated by WSO2 IS.</li><li><strong>Attribute Fetching:</strong> WSO2 IS requests a <strong>device attributes report</strong> from Entgra. Entgra synchronizes with the device in real time to fetch critical data such as rooting status, developer mode status, and USB debugging (ADB) settings.</li><li><strong>Risk-Based Decision:</strong> Based on the retrieved device attributes, WSO2 IS determines the next steps:</li></ol><ul><li><strong>Frictionless Login:</strong> If the device is secure (e.g., not rooted, developer mode off), the user proceeds with a seamless login experience.</li><li><strong>Additional Authentication Steps:</strong> If moderate risks are detected (e.g., developer mode enabled), the system may require additional authentication steps like Multi-Factor Authentication (MFA) to ensure security.</li><li><strong>Access Denial:</strong> If the device is compromised (e.g., rooted) or if the device is not registered, the login attempt is denied entirely to protect sensitive data.</li></ul><p>5. <strong>Final Response:</strong> The authentication response is sent back to the mobile app, either logging the user in or requiring further actions based on the risk assessment.</p><p>By implementing this login flow, you’re not just adding a security layer — you’re creating a dynamic authentication process that adapts to the security posture of the user’s device in real-time. This approach minimizes user friction while maximizing protection against unauthorized access.</p><h3>Benefits of Device Attribute-Based Authentication</h3><p>Integrating device attributes into your authentication flow offers several advantages:</p><ul><li><strong>Enhanced Security:</strong> By ensuring that only compliant and registered devices can access your application, you significantly reduce the risk of data breaches due to compromised devices.</li><li><strong>User Experience Optimization:</strong> Users enjoy a seamless login experience when their devices meet security criteria, reducing frustration and increasing satisfaction.</li><li><strong>Adaptive Risk Management:</strong> The system can adapt authentication requirements based on the real-time assessment of device risk factors, providing flexibility without compromising security.</li><li><strong>Regulatory Compliance:</strong> For industries with strict compliance requirements, this method helps meet regulatory standards by enforcing device-level security policies.</li></ul><h3>Bringing It All Together</h3><p>In today’s world, where cyber threats are more sophisticated than ever, relying solely on traditional authentication methods just isn’t enough for high-stakes applications. Device attribute-based authentication with WSO2 Identity Server and Entgra offers a robust solution that boosts security without compromising user experience. By focusing on both the user’s identity and the security posture of their device, you create an environment that’s both secure and user-friendly.</p><p>Whether you’re a small business securing a few devices or a large enterprise managing thousands of endpoints across multiple locations, <strong>WSO2 Identity Server</strong> and <strong>Entgra</strong> provide a highly scalable solution that grows with your organization’s needs. These powerful tools work together to deliver comprehensive identity and access management, coupled with advanced device management capabilities.</p><p><strong>Discover more about these innovative products:</strong></p><ul><li><a href="https://wso2.com/identity-and-access-management/">WSO2 Identity and Access Management Solutions</a></li><li><a href="https://entgra.io/entgra-cloud/">Entgra Device Management</a></li></ul><p>By integrating these solutions into your security infrastructure, you can confidently protect your applications and data while providing a seamless experience for your users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b5f70b8c235" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Effortlessly Run WSO2 Identity Server with Different Databases Using This Handy Script]]></title>
            <link>https://pasinduyeshan.medium.com/effortlessly-switch-databases-in-wso2-identity-server-with-our-handy-script-2b78ecbe239f?source=rss-9d51bbef07d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b78ecbe239f</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[wso2is]]></category>
            <category><![CDATA[script]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Pasindu Yeshan Abeysinghe]]></dc:creator>
            <pubDate>Thu, 30 Nov 2023 15:45:07 GMT</pubDate>
            <atom:updated>2024-05-16T14:23:50.988Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello, developers! 🌟 Do you find yourself frequently switching databases for WSO2 Identity Server (IS) during testing or development phases and feeling it’s a bit repetitive? It seems easy at first, but doing it over and over? That’s when it starts to feel like a chore.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*oliied6VZ4Sr0nVkM8RbkQ.jpeg" /></figure><h3>Getting Started: Cloning and Setting Up the Script</h3><p>First, let’s get the script onto your system. Here’s how to start your journey with our script:</p><h4>Step 1: Clone the Repository</h4><p>Grab the script from GitHub with this simple command in your terminal:</p><pre>git clone https://github.com/PasinduYeshan/wso2-scripts.git</pre><h4>Step 2: Navigate to the Script’s Directory</h4><p>Once you’ve cloned the repository, move into the directory where the script resides:</p><pre>cd wso2-scripts/deploy/identity_server</pre><h4>Step 3: Open and Configure the config.ini File</h4><p>In the deploy/identity_server directory, you&#39;ll find the config.ini file. This is where you&#39;ll specify your database choice and paths for the WSO2 IS ZIP file and its extraction. Open it in a text editor and adjust the settings for MySQL, like so:</p><p><strong>1. Specifying the IS and Unzip Paths:</strong></p><p>Here’s where you provide the path to your WSO2 IS ZIP file and where you want it unzipped. For example:</p><pre>[files]<br>zip_file_path=/path/to/wso2is.zip<br>unzip_dir_path=/path/for/unzipping</pre><p><strong>2. Choosing Your Database Flavor:</strong></p><p>This part is exciting! You can choose which SQL database to use. Just set the <strong>type</strong> under the <strong>[database]</strong> section. Let&#39;s say you&#39;re going for MySQL:</p><pre>[database]<br>type=mysql</pre><p><strong>3. Running the IS:</strong></p><p>You can even decide whether to run the IS after configuration and whether to enable debug mode right here in the config:</p><pre>[server]<br>run_is=true<br>run_in_debug=false</pre><h4>Step 4: Execute the Script</h4><p>Everything’s set up now! In your terminal, within the script’s directory, run the script:</p><pre>./configure_is_with_sql_db.sh</pre><h4>Step 5: Observing the Magic Unfold:</h4><p>Watch as the script efficiently unzips the WSO2 IS, sets up the MySQL Docker container, and configures the databases, readying everything for an optimal run.</p><h4>Step 6: Dive into the Log File:</h4><p>Don’t forget to peek into the process_info.log for an in-depth look at the setup details.</p><pre>Database Configuration:<br>Database Type:            mysql<br>Container Name:           mysql_db_is_200<br>Database Port:            3306<br>Database Username:        root<br>Database Password:        myStrongPaas42!emc2<br>Identity DB Name:         WSO2_IDENTITY_DB<br>Shared DB Name:           WSO2_SHARED_DB<br><br>IS Configuration:<br>Unzipped IS Directory:    /Users/pasindu/project/is/mysql/wso2is-7.0.0-rc1-SNAPSHOT</pre><p>By following these steps, you’ll see just how seamlessly you can set up and deploy WSO2 IS with MySQL. This hands-on experience showcases the script’s ability to transform what used to be a repetitive chore into an efficient and smooth operation. 🚀✨</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*BNWhh_OnuIm8Mq3-Qb869g.jpeg" /></figure><h3>Peeking Under the Hood: How the Magic Happens</h3><p>So you’ve edited the <strong>config.ini</strong> and initiated the script. Now, let&#39;s take a sneak peek at what&#39;s happening behind the scenes. It&#39;s like watching a magician prepare their tricks backstage. 🎩✨</p><h4>The Script’s Workflow</h4><p>When you run the script, it embarks on a carefully orchestrated journey:</p><ol><li><strong>Unzipping the WSO2 IS:</strong> The script starts by unzipping the WSO2 IS ZIP file to your specified location.</li><li><strong>Setting Up the Docker Container:</strong> Based on your chosen database type, the script conjures up a Docker container. This container is your database server, be it MySQL, MSSQL, or PostgreSQL.</li><li><strong>Configuring Databases:</strong> The script then proceeds to set up databases within the container. It creates the necessary databases and ensures they’re ready for WSO2 IS.</li><li><strong>Applying Patches and Drivers:</strong> If you have any patches or specific JDBC drivers, the script applies them, ensuring your WSO2 IS is up-to-date and compatible with your database.</li><li><strong>Final Touches:</strong> Finally, the script updates the WSO2 IS configurations, pointing it to the newly set-up databases.</li></ol><h4>Script Anatomy: Bash, Python, and a Dash of Node.js</h4><p>The script is a medley of Bash, Python, and, for those on ARM64 architecture using MSSQL, a dash of Node.js. Here’s how these components play their parts:</p><ul><li><strong>Bash Scripts:</strong> They orchestrate the overall process, managing Docker containers, and invoking other scripts as needed.</li><li><strong>Python Scripts:</strong> These come into play for updating the WSO2 IS configurations. They’re like the precise tools in our toolbox, tweaking the configurations with accuracy.</li></ul><h3>Exploring Advanced Options: Tailoring the Script to Your Needs</h3><p>While the basic setup already offers a lot of conveniences, our script also comes with advanced options for those who need extra control. Let’s dive into these features:</p><h4>Configuring Pool Options: Customize to Your Needs</h4><p>If you need to tailor your database connections with pooling options, our script includes configurations for MySQL, PostgreSQL, and MSSQL. Enabling pooling is straightforward — simply turn on the <strong>enable_pooling</strong> option in the <strong>[database]</strong> section of your <strong>config.ini</strong> file:</p><pre>[database]<br>...<br>enable_pooling=true</pre><h4>Diving into Python Script Customization</h4><p>Our script’s flexibility shines through in the <strong>python_scripts/db_config_template.py</strong> file. Here, you can find and customize the default settings for connection pooling. We&#39;ve aligned these with standard documentation, but they&#39;re fully adjustable to suit your specific requirements. Check out a snippet of the configurations:</p><pre># MySQL Configs<br>mysql_advanced_config = f&quot;&quot;&quot;<br>[database.identity_db.pool_options]<br>maxActive = &quot;80&quot;<br>maxWait = &quot;360000&quot;<br>... (additional configurations)<br>&quot;&quot;&quot;<br><br># PostgreSQL Configs<br>postgresql_advanced_config = f&quot;&quot;&quot;<br>... (specific configurations for PostgreSQL)<br>&quot;&quot;&quot;<br><br># MSSQL Configs<br>mssql_advanced_config = f&quot;&quot;&quot;<br>... (settings for MSSQL)<br>&quot;&quot;&quot;</pre><p>For further customization of the <strong>deployment.toml</strong> in WSO2 IS, simply modify the <strong>python_scripts/update_deployment_toml.py</strong>. This script is designed for easy editing, offering you the flexibility to change configurations as needed.</p><h4>Force Recreate Containers:</h4><p>Sometimes, you might want to start afresh with your Docker containers. Our script lets you forcibly recreate containers to ensure a clean setup. This is particularly useful when you’re troubleshooting or need to reset your environment. Enable this by setting <strong>force_container_recreation</strong> to <strong>true</strong>.</p><pre>[database]<br>...<br>force_container_recreation=true</pre><h4>Node.js Integration for MSSQL on ARM64</h4><p>For our friends using ARM64 architecture and working with MSSQL, here’s where things get interesting. The usual MSSQL image for ARM64 lacks certain tools, so we had to think outside the box. Inspired by a colleague’s work, I turned to Node.js and the <strong>tedious</strong> module to establish database connections and execute SQL scripts. This ensures smooth operations even in these specific scenarios.</p><h3>Wrapping Up: Enhancing Your WSO2 IS Deployment Experience</h3><p>As you’ve seen, this script is all about making the process of switching databases in WSO2 IS a lot more manageable and less time-consuming. From setting up Docker containers to customizing connection pooling options and even managing MSSQL on ARM64 architecture, it’s all been designed with ease and simplicity in mind.</p><p>Feel free to take it for a spin, and see for yourself how it streamlines WSO2 IS deployments. 🌟🛠️</p><p>In bringing this project to life, I also want to extend a special thank you to ChatGPT, an AI developed by OpenAI. ChatGPT played a significant role in both the development of the script and the crafting of this article 😚.</p><h3>A Call for Collaboration and Improvement</h3><p>Developing software is an ever-evolving journey, and there’s always room for enhancement and innovation. If you, as a user of this script, identify areas for improvement or have ideas to expand its capabilities, I encourage you to dive in and contribute. Your insights, feedback, and contributions are not just welcome, they’re invaluable. Together, we can refine and evolve this tool, making it even more beneficial for everyone who uses it. Let’s collaborate and push the envelope of what this script can achieve! 🚀🤝</p><p>🔗 <strong>Find the Script on GitHub:</strong> <a href="https://github.com/PasinduYeshan/wso2-scripts/tree/main/deploy/identity_server">WSO2 Identity Server Database Configuration Script</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b78ecbe239f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS Native Module on React Native]]></title>
            <link>https://pasinduyeshan.medium.com/ios-native-module-on-react-native-fa9429703ca9?source=rss-9d51bbef07d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa9429703ca9</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[native-modules]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Pasindu Yeshan Abeysinghe]]></dc:creator>
            <pubDate>Tue, 22 Mar 2022 17:36:41 GMT</pubDate>
            <atom:updated>2025-06-13T19:04:44.349Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*pHwCiD0ImV6ndsif.png" /></figure><p>If you are not familiar with React Native, React Native is a JavaScript framework for writing mobile applications which eventually rendered natively. React Native runs on React, a popular open-source library for building user interfaces with JavaScript, So if you know React it will be really easy to develop user interfaces in React Native mobile applications. That is one reason React native is so popular.</p><h4>Native Module</h4><p>The NativeModule system exposes instances of native classes to JavaScript as JavaScript objects. When you run npx react-native run-android it runs your react native mobile application on Android OS and all the native modules you have written in the Android folder will be accessible in react native. You can read my previous <a href="https://medium.com/@pasinduyeshann/native-module-for-react-native-using-kotlin-1f169372b6d3"><strong><em>article</em></strong></a><strong><em> </em></strong><em>to learn how to write Android Native Module using Kotlin. </em>In this article, I will talk about how you can do that in iOS using … mmm. Let’s see what we’re gonna use.</p><h4><strong>Swift or Objective-C</strong></h4><p>You can develop an iOS native module using both Swift and Objective-C. If we compare Swift and Objective-C even though both of them are native languages for iOS, Swift is a much more modern language and it’s more human-friendly and easy to learn. Moreover, applications written in Swift are said to have only 30% of lines of code compared to one written in Objective-C. According to Apple Swift is 2.6 times faster than Objective-C 😎. But, the layout engine (Yoga) used in React Native stays in Objective-C, therefore, using Objective-C in native development is very straightforward but that doesn’t mean you can not use Swift. If you are familiar with Swift or kind of don’t like the syntax of Objective-C 😢 you can still write the native module with Swift easily and you will need an additional bridging file, known as a bridging header, to expose the Objective-C files to Swift. I will be focusing on writing the native module in Objective-C here.</p><h4>Getting Started</h4><p>First of all, we should have a React Native project 😃 So, if you don’t have a react native project click <a href="https://reactnative.dev/docs/environment-setup">here</a> and follow the instructions given under the React Native CLI Quickstart. The reason I’m telling you to use React Native CLI instead of Expo CLI which is way easier to use than React Native CLI is, integrating native modules in Expo is a nightmare. You can read more about this matter from <a href="https://medium.com/nerd-for-tech/expo-v-s-react-native-cli-what-to-choose-and-what-to-stay-away-from-85afc81597bc">here</a>.</p><p>Okay, now we can jump into iOS native module development, for that, I recommend using Xcode for writing native modules since it will help you resolve simple errors like syntax errors easily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*XX6l-6APX06nJZByzMUSzQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*M_RvsIkvn0NZwLKBDul3OQ.png" /></figure><p>First, open the ios folder from Xcode and create a New Group option, this won’t create a new folder though, if you want your native module in a separate folder select the option “New group with Folder”.</p><h4>Native Module Header File</h4><p>The next step is to create a header file containing the interface of your native module. Create your header file inside the group you have created earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ydMG-usWLiQ_qYVwIGAGXw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p2oEVhNaEm0kwa2qTZKYxQ.png" /></figure><p>When you open EntgraServiceModule.h file you will see autogenerated code like below. Don’t worry I will explain it. 😃</p><blockquote><em>When the code is compiled, the preprocessor checks whether </em><em>EntgraSeerviceModule_h has been previously defined. If not, the compiler defines </em><em>EntgraSeerviceModule_h and includes the contents of the file. If the header is included again into the same file, </em><em>EntgraSeerviceModule_h will already have been defined from the first time that the contents of the header were included; the </em><em>ifndef guard will then ensure that the contents of the header will be ignored.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*sBnwQ4dfbXNFefENEkzZ5A.png" /></figure><p>Okay, now you what this auto-generated code means, now let’s define our Native Module interface here. First, you need to import React/RCTBridgeModule.j. The class definition starts with the keyword @interface followed by the class name and type. A class should implement RCTBridgeModule to register as a native module in Objective-C</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R__yfPuEJ2GU5PiW9QlnNw.png" /></figure><blockquote><em>If you get an error like </em><em>React/ReactBridgeModule.h file not found don’t worry I got you covered 😃. Follow these steps.</em></blockquote><blockquote>rm -r node_modules/<br>rm -r ios/Pods<br>npm install<br>cd ios &amp;&amp; pod install<br><em>Open XCode, hit </em><em>CMD + Shift + K to clean and build</em></blockquote><p>Now we are done with the header file. Easy right 😆.</p><h4>Native Module Implementation</h4><p>Now let’s implement our native module. For that, you should create an Objective-C file as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Q1dpOcWOExAdAGdMsVo4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*puOOxTMe9FwAyDM1Rh7I2Q.png" /></figure><p>Then import your header file into the Objective-C file.</p><pre>#import “EntgraServiceModule.h”</pre><p>You can start implementing your native module after the keyword @implementation and native module name. RCT_EXPORT_MODULE() export and register native module class with React Native. You can pass any name to this method as a parameter and your native module class will be registered to React Native by that name.</p><pre>#import &lt;Foundation/Foundation.h&gt;<br>#import “EntgraServiceModule.h”</pre><pre><strong>@implementation</strong> EntgraServiceModule</pre><pre>// Export EntgraServiceModule<br>RCT_EXPORT_MODULE(EntgraServiceManager);</pre><pre>@end</pre><blockquote>This argument is not a string literal. So don’t pass name as RCT_EXPORT_MODULE(&quot;EntgraServiceManager&quot;).</blockquote><blockquote>If you read my previous <a href="https://medium.com/@pasinduyeshann/native-module-for-react-native-using-kotlin-1f169372b6d3">article</a> you may have noticed, I named my Android native module as EntgraServiceManager. So that’s why I use the same name in iOS as well. In fact, you need to use the same name and same method formats inside these native modules. Otherwise, you will have to check the OS and then invoke each method according to the OS which is additional work.</blockquote><h4>Export Native Method to React Native</h4><p>Now we have registered our native module to React Native. Unfortunately, like in Android, in iOS React Native will not expose any methods in a native module to JavaScript unless explicitly told to. But it’s not that hard, you can use RCT_EXPORT_METHOD() to export your native method to React Native.</p><blockquote>Methods written in the RCT_EXPORT_METHOD macro are asynchronous and the return type is therefore always void. Therefore, we can’t just return values. You can use callback functions to overcome this issue and return any value from the native module to React native. Here I pass two callback functions as parameters for each method which will be invoked in success and error.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/128a0c3bd45eca3db74081c5d96fc060/href">https://medium.com/media/128a0c3bd45eca3db74081c5d96fc060/href</a></iframe><blockquote>For iOS, callbacks are implemented using the type RCTResponseSenderBlock and it only accepts one argument which is an array of parameters to pass to the JavaScript callback.</blockquote><p>One more thing before we test our native module. It’s always good to declare your native methods in the header file inside the interface. (OOP concepts 😜) As a result, you will get a warning when you haven’t implemented any defined function in your implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e5xhtUp7o-basnqlbMjMkg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*04yL05C3LoTEe6NWT64RAg.png" /></figure><p>Woo-hoo we are done with the native module. 😎 Now let’s see how this can be accessed in React Native.</p><h4>Testing Native Module</h4><p>You can build a wrapper for the native module instead of using it directly each time you access your native module. If you are using typescript you can make your code type-safe by adding type annotation to your native module as follows. It will make your code cleaner and easier to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I56grcbIUuXIUMYeE9qANQ.png" /></figure><p>Then you can use this native module anywhere as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*TD61bg_fbvpHAplNqBujvg.png" /></figure><p>Ok, you are all set to go. First, you will need to start the Metro, the Javascript bundler by running npx react-native start inside your project folder. Then open another terminal and run npx react-native run-ios to start your application. Make sure to run npx react-native run-ios each time you update your native module.</p><p>Thank you for reading and hope you got some insight on developing iOS native modules for React Native 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa9429703ca9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Native module for React Native using Kotlin]]></title>
            <link>https://pasinduyeshan.medium.com/native-module-for-react-native-using-kotlin-1f169372b6d3?source=rss-9d51bbef07d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f169372b6d3</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[native-modules]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Pasindu Yeshan Abeysinghe]]></dc:creator>
            <pubDate>Thu, 24 Feb 2022 13:57:22 GMT</pubDate>
            <atom:updated>2022-07-05T13:55:18.817Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6biTxRAHbXVwBnPkKyPtCQ.png" /></figure><h3>About React Native</h3><p>React Native is a JavaScript framework for writing mobile applications which eventually rendered natively. React Native runs on React, a popular open-source library for building user interfaces with JavaScript, So if you know React it will be really easy to develop user interfaces in React Native mobile applications. That is one reason React native is so popular.</p><h3>About Kotlin</h3><p>Kotlin is a cross-platform, statically typed, general-purpose programming language. Kotlin is designed to interoperate fully with Java and Java Class Library. Therefore it is straightforward to use Kotlin with React Native.</p><h3>About Native Module</h3><p>The NativeModule system exposes instances of native classes to JavaScript as JavaScript objects. Which allows us to execute native code from JavaScript. There are two ways to write a native module for React Native application</p><ul><li>Directly withing React Native application’s project</li><li>As an NPM package that can be installed as a dependency by other React Native Application</li></ul><p>In this article, I will explain how to implement a native module directly within React Native application</p><h3>Getting Started</h3><p>First of all, we should have a React Native project 😃 So, if you don&#39;t have a react native project click <a href="https://reactnative.dev/docs/environment-setup">here</a> and follow the instructions given under the React Native CLI Quickstart. You can start the React Native project with Expo CLI as well which is easier than the React Native CLI but I used React Native CLI to create my React Native Project and I hope that you all have a React Native project which looks like this,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/1*EqorjkO86Yv9_lxZb3y-eQ.png" /><figcaption>Folder structure</figcaption></figure><h3>Setting up Gradle</h3><p>Gradle is an open-source general-purpose build automation tool before we start writing Kotlin, there are a few changes to be made in Gradle files.</p><p>First, open the project-level build.gradle file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*MSkQyNA5wT9vBBdqK4hI0g.png" /></figure><p>Include Kotlin Version</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*1O-Bv31U_GyAhs4pmLvH5A.png" /></figure><p>Add google() in the buildscript.repositories and allprojectsin the same build.gralde file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*zKxW-1Y5fYnCMqPYa__sRQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*XGKq4zX3PpZ5464HnHKCTQ.png" /></figure><p>Add the following classpath in the dependencies to include the Kotlin Gradle plugin.</p><pre>classpath &quot;org.jetbrains.kotlin:kotlin-gradle-plugin:${project.ext.kotlinVersion}&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*YR8T3yIKhPafxbhqC3lNQg.png" /></figure><p>After you finish with project-level build.gralde file open up the build.grdle file inside the app folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*9dsx9Kwk8CkjFsRCw40jXQ.png" /></figure><p>Add the following code at the top of the file</p><pre>apply plugin: &quot;kotlin-android&quot;</pre><p>In the dependencies section add the following dependency</p><pre>implementation &quot;org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.0&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*6uLQdXRBPXhCGMa6vqAFmg.png" /></figure><p>Now you are done with adding Kotlin to your project. You can go to your project root folder and run react-native run-android in the terminal to test everything is working without a problem. This might take a while since the Android project will sync Gradle and download all the missing packages and dependencies to your project.</p><h3>Bridge Kotlin in React Native</h3><p>First, let’s create a separate folder inside the project package to code our Kotlin module. In my case, isentgra is my main package name and entgraServices is the folder I have created inside the package folder. As you can see inside the entgraServices folder I have created two Koltin files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*DillMCCCuAWjFbbDixmIGA.png" /></figure><ul><li>EntgraServiceManager — This class implements the necessary functionalities to run the native module and implements getName() function which registers the native Kotlin module with the React Native bridge.</li><li>EntgraServicePackage — This class registers native module with React native.</li></ul><h3>Native Module</h3><p>— EntgraServiceManager.kt</p><p>First, add the following content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PabFjECPHGDulbsXrlC4lQ.png" /></figure><p>For Android, Java native modules are written as classes that extend ReactContextBaseJavaModule and implement the functionality required by JavaScript. Since Kotlin is designed to interoperate fully with Java and Java Class Library we can extend ReactContextBaseJavaModule class as follows.</p><p>getName() — All native modules in Android need to implement getName() method and this name will be used to access the native module in JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T_yQoy0Ej6BXygAUPcCREA.png" /></figure><h4>Export a Native Method to JavaScript</h4><p>Next, we should annotate methods that we plan to invoke from JavaScript with @ReactMethod . You can pass callback methods as parameters (optional) to the native method from JavaScript to run on success and failure as above.</p><h3>ReactPackage</h3><p>— EntgraServicePackage.kt</p><p>After writing the native module we need to register that module with React Native. For that, the native module should be added to the ReactPackage and register ReactPackage with React Native. During initialization, React Native will loop over all the packages and, for each ReactPackage, register each native module within.</p><p>createNativeModules()- Return a list of native modules to register with React Native</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N_Vww5J302nziXYoQ3FF8w.png" /></figure><h4>Add the package to MainApplication</h4><p>To register our native module we must add our EntgraServicePackage to the list of packages returned in ReactNativeHost’s getPackages() method.</p><p>Open the MainApplication.java file which can be found in android/app/src/main/java/com/&lt;package-name&gt;/MainApplication.java . Import your package and add the package into the packages list as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PEvlGyMELpWiJs1PCxE2Ig.png" /></figure><p>Now you can test the native module you have built.</p><h3>Test Native Module in JavaScript</h3><p>First import NativeModules from ReactNative. Then you can access your native module from NativeModulesas follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jo_qrlBRI-WL0gfvgTALxg.png" /></figure><p>Finally, you can rebuild the React Native application with the latest native code with your new native modules by running the following code in the project root folder.</p><pre>npx react-native run-android</pre><p>Thank you for reading and hope you got some insight on developing native modules for React Native with Kotlin 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f169372b6d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>