<?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 Wathsara Wishwantha Daluwatta on Medium]]></title>
        <description><![CDATA[Stories by Wathsara Wishwantha Daluwatta on Medium]]></description>
        <link>https://medium.com/@wathsara?source=rss-b211f0baedf8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*of-QkH80huuikhHyZ2pLvw.jpeg</url>
            <title>Stories by Wathsara Wishwantha Daluwatta on Medium</title>
            <link>https://medium.com/@wathsara?source=rss-b211f0baedf8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 05:58:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wathsara/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[User store based conditional authentication with Asgardeo]]></title>
            <link>https://wathsara.medium.com/user-store-based-conditional-authentication-with-asgardeo-8639eb3e2b56?source=rss-b211f0baedf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8639eb3e2b56</guid>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[asgardeo]]></category>
            <category><![CDATA[wso2is]]></category>
            <dc:creator><![CDATA[Wathsara Wishwantha Daluwatta]]></dc:creator>
            <pubDate>Sun, 31 Jul 2022 07:36:20 GMT</pubDate>
            <atom:updated>2022-07-31T07:36:20.447Z</atom:updated>
            <content:encoded><![CDATA[<p>Asgardeo conditional authentication allows you to customize the logic flows by using a script. This allows you to validate multiple factors before granting access to a resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/0*l833DYr7TKPvrfHq" /></figure><p>With this blog I am focusing on how to use conditional authentication based on the user store domain. This will educate you on</p><ol><li>How to grant access to a resource based on the user store domain of a user.</li><li>How to use Adaptive MFA (Multi Factor Authentication) based on the user store domain.</li></ol><p><strong>Prerequisites.</strong></p><p>1. Sign up to Asgardeo.</p><p>2. Connect a remote user store to your Asgardeo Organization.<br>If you haven’t heard about this please go through my article on <a href="https://wathsara.medium.com/lets-connect-your-on-premises-user-store-to-asgardeo-f36b65929f65">Let’s connect your on-premises user store to Asgardeo</a></p><p><strong>Step 1 — Register a Single-Page Application</strong></p><ol><li>Login to<a href="https://console.asgardeo.io/"> Asgardeo Console</a>.</li><li>Go to the <strong>Develop</strong> section and then select <strong>Applications</strong>.</li><li>Click New<strong> </strong>Application.</li><li>Select <strong>Single-Page Application.</strong></li><li>Provide a Name to the application and Click <strong>Add Now </strong>anchor to set Authorized redirect URLs of the sample application.</li><li>Then Click register to create the application.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FbquyI2BqrydwGDE" /></figure><p>Then you’ll be redirected to the Quick-start Section of the Application. There you can select a technology you prefer. Then select a <strong>Try out a sample</strong> and follow the setup guide to run the sample application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P6JQkVHwm4X8MLQj" /></figure><p><strong>Step 2 — Create a customer user in Asgardeo.</strong></p><ol><li>Go to the <strong>Manage</strong> section and then select <strong>Users</strong>.</li><li>Click <strong>New User</strong> and select <strong>Customer.</strong></li><li>Enter the customer Email, First Name, Last Name and select Set a temporary password for the user and enter a password and then click <strong>Finish.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2DQQVDEcKf2lKYwM" /></figure><h3><strong>How to grant access to a resource based on the user store domain of a user.</strong></h3><blockquote>For the application I have configured above I want to allow only the users from my remote user store to access the Application. For the users from other user stores (Default) I want to show an error message saying the user is unauthorized to access the application.</blockquote><p>1. On the Asgardeo console, click <strong>Develop &gt; Applications</strong>.</p><p>2. Select the application for which the conditional login flow should apply.</p><p>3. Go to the <strong>Sign-in Method</strong> tab.</p><p>4. Click <strong>Start with default configuration</strong> to define the login flow starting with username and password.</p><p>5. Turn on <strong>Conditional Authentication</strong> by switching the toggle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BFTTt85hpeOxyNxJ" /></figure><p>6. Then Update the script with the following content.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95448d0facb8b06d87bb22b4be43abdb/href">https://medium.com/media/95448d0facb8b06d87bb22b4be43abdb/href</a></iframe><p>Above script will extract the user store domain from the authenticated subject. Then sending the error message to the error page (In here it’s the default one as I haven’t added an error page) with the relevant parameters.</p><h3><strong>Try it out</strong></h3><p>Access the application URL and try to login using a user from the <strong>MY-REMOTE-USERSTORE</strong>. Users will be able to successfully login to the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YePdzTnSCzVEzrmQ" /></figure><p>Access the application and try to Login to the application from the user we have created previously (Or any other user from Default user store). Those users will get the error message we have passed from our conditional authentication script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lUYl9s0Y49i5GY8l" /></figure><h3><strong>How to use Adaptive MFA (Multi Factor Authentication) based on the user store domain.</strong></h3><blockquote>For the application I have configured above I want to prompt <strong>TOTP</strong> as the second factor authenticator for the users from my remote user store to access the Application. For the users from other user stores (Default) providing the user name and password is enough.</blockquote><p>1. Go to the <strong>Sign-in Method</strong> tab of the application.</p><p>2. Add <strong>TOTP </strong>as the second step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nBsV6NbeDxvySwT2" /></figure><p>3. Then Update the script with the following content.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd47c367e2e2ff31ca7d9cdc981d0c73/href">https://medium.com/media/bd47c367e2e2ff31ca7d9cdc981d0c73/href</a></iframe><p>Above script will extract the user store domain from the authenticated subject. Then only If the user store domain of the user is equals to <strong>‘MY-REMOTE-USERSTORE’</strong>, it will execute the second step.</p><h3>Try it Out</h3><p>Access the application URL and try to login using a user from the <a href="https://gist.github.com/Wathsara/772d4ae11241af5235f18f9443210464"><strong>MY-REMOTE-USERSTORE</strong></a>. Users will have to provide the <strong>TOTP</strong> as well to access the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uwidJZXTn7D-bPNh" /></figure><p>Once you logged in you can see the TOTP in the Decode ID token as well</p><pre>“amr”:<strong>[<br>   </strong>0: “BasicAuthenticator”<br>   1: “totp”<br>]</pre><p>Access the application and try to Login to the application from the user we have created previously (Or any other user from Default user store). Those <strong>users won’t be asked</strong> to provide a TOTP to log in.</p><p>Once you logged in you can only see the <strong>BasicAuthenticator</strong> in the Decode ID token as well</p><pre>“amr”:[<br>   0: “BasicAuthenticator”<br>]</pre><p>Thank you for reading. Have a Good Day!!</p><h3><strong>References</strong></h3><p><a href="https://wso2.com/asgardeo/docs/guides/authentication/conditional-auth/">https://wso2.com/asgardeo/docs/guides/authentication/conditional-auth</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8639eb3e2b56" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s connect your on-premises user store to Asgardeo]]></title>
            <link>https://wathsara.medium.com/lets-connect-your-on-premises-user-store-to-asgardeo-f36b65929f65?source=rss-b211f0baedf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f36b65929f65</guid>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[asgardeo]]></category>
            <category><![CDATA[wso2is]]></category>
            <dc:creator><![CDATA[Wathsara Wishwantha Daluwatta]]></dc:creator>
            <pubDate>Sat, 30 Jul 2022 08:11:40 GMT</pubDate>
            <atom:updated>2022-08-30T05:22:23.788Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://wso2.com/asgardeo">Asgardeo</a> is the latest IDaaS introduced by WSO2 enabling developers with little IAM experience to create seamless login experiences in minutes. Currently Asgardeo is live, which I’m inviting you all to start your journey with next generation IDaaS today for free.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/0*CPk2ZboOX4Lbju-M.png" /><figcaption>Asgardeo Logo</figcaption></figure><p>With this blog I am focusing on how to connect your on premises user store to your Asgardeo organization. With this feature Organization admins get the opportunity to onboard their existing users to Asgardeo by connecting the user store directly to Asgardeo.</p><blockquote>If an organization wants to import the existing users to Asgardeo they can migrate the users to Asgardeo as well. For more information follow, <a href="https://wso2.com/asgardeo/docs/guides/users/migrate-users/">https://wso2.com/asgardeo/docs/guides/users/migrate-users/</a></blockquote><p>Keep in mind that</p><ul><li>Currently Asgardeo allows you to connect the on-premises user stores as the READ ONLY user stores, hence you won’t be able to modify the users and groups using the Asgardeo console.</li><li>Asgardeo currently supports Lightweight Directory Access Protocol (LDAP) &amp; Active Directory (AD) user stores only.</li><li>Communication between your user store and Asgardeo is managed by using a java application called user store agent.</li></ul><h3><strong>How this works.</strong></h3><p>Asgardeo provides an application called user store Agent, which you have to run in your server with the correct configurations to communicate with the user store. The communication between the user store agent and Asgardeo happens via a web socket channel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/0*4LhHieMsBIzdM9VJ" /></figure><p>As an example when a remote user (User inside your on-premise user store) authenticates with Asgardeo, the requests are redirected to the user store agent which validates the user against your AD/LDAP service and then sends the results of the validation back to Asgardeo.</p><h3><strong>Prerequisites.</strong></h3><ul><li>Sign up to<a href="https://wso2.com/asgardeo/signup"> Asgardeo</a>.</li><li>JAVA 8 or JAVA 11 installed locally and JAVA_HOME configured correctly</li></ul><h3><strong>Set up an openLDAP instance to connect to Asgardeo</strong></h3><blockquote>If you are having a LDAP/AD user store already configured in your machine/server, you can skip this part.</blockquote><p>Here we are going to set up an openLDAP instance by using the <a href="https://hub.docker.com/r/bitnami/openldap">bitnami openldap docker image</a>. Then we will add the users to the LDAP Data Interchange Format (LDIF) file.</p><p><strong>Step 1</strong> — Run the openldap instance by using the following command. Here you can change your base dn, admin username and passwords as you prefer.</p><pre>docker run --detach --rm --name openldap \<br>--env LDAP_BASE=dc=exmple,dc=org \<br>--env LDAP_BIND_DN=cn=admin,dc=exmple,dc=org \<br>--env LDAP_BIND_PASSWORD=adminpassword \<br>--env LDAP_ADMIN_USERNAME=admin \<br>--env LDAP_ADMIN_PASSWORD=adminpassword \<br>--env LDAP_USERS=customuser \<br>--env LDAP_PASSWORDS=custompassword \<br>-p 1389:1389 -p 1636:1636 -d bitnami/openldap:latest</pre><p><strong>Step 2</strong> — create a file called <strong>users-and-groups.ldif</strong> file with the following content to create users and groups in your ldap instance. You need to replace <strong>&lt;&lt;PASSWORD&gt;&gt;</strong> with your own password to the users.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67ebd3f012a4d3eaba09faf7d925c280/href">https://medium.com/media/67ebd3f012a4d3eaba09faf7d925c280/href</a></iframe><p><strong>Step 3</strong> — Copy the create the LDIF file to the openldap docker container using</p><pre>docker cp users-and-groups.ldif openldap:/</pre><p><strong>Step 4</strong> — Then execute the following two commands to add the users and groups.</p><pre>docker exec -it openldap bash</pre><pre>ldapadd -a -D “cn=admin,dc=example,dc=org” -w adminpassword -H ldapi:/// -f users-and-groups.ldif</pre><blockquote>You can view the onboard users and groups using the Apache directory Studio — <a href="https://directory.apache.org/studio/">https://directory.apache.org/studio/</a></blockquote><h3><strong>Let’s create a user store in Asgardeo to connect the remote user store.</strong></h3><ul><li>Login to your Asgardeo console.</li><li>Navigate to <strong>Manage &gt; User Stores</strong> and click Connect remote use store.</li><li>Fill the General information of your user store and click next.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VvCHAFZ4CQWlqPHR" /></figure><ul><li>Then Map the username and User ID attributes correctly. This is one of the most important configurations when creating the user store in Asgardeo. These two attributes need to be mapped correctly for proper authentication.</li></ul><blockquote>Username — This is the primary identifier of the user. Which is used to validate users authentication. Asgardeo is recommending you to use an attribute type of email as the username for the best experience. If you had a concern why I have added email for the user identification in my ldap I have created previously, hope you have the answer now.</blockquote><blockquote>User ID — This attribute is used to uniquely identify a user entry. Recommendation is to use some kind of a ID (UUID) to uniquely identify the users. This ID will be the user’s ID which you will be using to retrieve the users information (Even in SCIM).</blockquote><p>In the openldap we have create previously, <strong>Username — cn and user ID — uid</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Shs6galaqkpuZYnj" /></figure><ul><li>Then click finish to create the user store. This will take a few seconds to get created. After registering the user store, you’ll be redirected to the <strong>Setup Guide</strong> of the user store agent.</li></ul><h3>Lets assemble and configure the user store agent bundle to connect the user store to Asgardeo</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s_N-QZpVLVWjcTa9" /></figure><ul><li>Download the user store agent and unzip as the first step.</li><li>Then we need to configure the user store bundle with the relevant configuration to connect the user store to the Agent. These configurations need to be done in the deployment.toml file which can be found at the user store agent home. All the configuration that needs to be configured correctly can be found at <a href="https://wso2.com/asgardeo/docs/references/remote-user-store/remote-user-store-properties/">https://wso2.com/asgardeo/docs/references/remote-user-store/remote-user-store-properties/</a> You need to read these properties carefully when connecting your own user store to Asgardeo.</li><li>Below I have mentioned the configurations for the openldap instance that we have configured.</li></ul><pre>[user_store]<br>type = &quot;ldap&quot;<br>base_dn = &quot;dc=example,dc=org&quot;<br>connection_url = &quot;ldap://localhost:1389&quot;<br>connection_name = &quot;cn=admin,dc=example,dc=org&quot;<br>connection_password = &quot;adminpassword&quot;<br>user_search_base = &quot;ou=users,dc=example,dc=org&quot;<br>user_id_search_filter = &quot;(&amp;amp;(objectClass=inetOrgperson)(uid=?))&quot;<br>user_name_list_filter = &quot;(objectClass=inetOrgperson)&quot;<br>user_id_attribute = &quot;uid&quot;<br>user_name_search_filter = &quot;(&amp;amp;(objectClass=inetOrgperson)(mail=?))&quot;<br>user_name_attribute = &quot;mail&quot;<br>group_search_base = “ou=groups,dc=example,dc=org”<br>group_entry_object_class = &quot;group&quot;</pre><ul><li>After configuring the `deployment.toml` you need to Generate an installation token by clicking the generate token button in the Step 3 of the setup guide.</li><li>This Installation token is required when running the user store agent bundle. This will be used to authorize the web socket connection.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vueDppnZsrPyhO37" /></figure><ul><li>The run the user store agent bundle with commands mentioned<br>Linux/OSx: <strong>sh wso2agent.sh</strong><br>Windows: <strong>wso2agent.bat — run</strong></li></ul><p>When starting the user store agent, it will ask for an <strong>installation</strong> <strong>token</strong> as an input. There you have to provide the token obtained in step 3.</p><ul><li>Then you can validate the connection using the Test Connection button in the bottom of the setup guide page.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UwKzLS28K-DE20mf" /></figure><blockquote>* Copy the installation token and save it in a safe location. You won’t be able to see it again! <br>* This token has no expiry time, but in case you lose or forget it, you can regenerate an installation token.<br>* If you find your token is compromised you can revoke the current token and generate a new token.</blockquote><h3><strong>What’s Next?</strong></h3><p>Next immediate step you have to do is to map the attribute correctly. For that</p><ul><li>You need to navigate to the Attribute Mappings tab in the top of your user store.</li><li>Then update the relevant values for the attribute.</li><li>Please Note — By default Asgardeo filled these attribute values with the most commonly used attribute names in the LDAPs, If those values are correct you can simply click update button to set up the attribute mappings or else you can edit the relevant values click update. If you map the attribute incorrectly, users’ information will not be visible correctly.</li><li>Once you have done that, Navigate to the users section in the console and select the user store name from the drop down. You can see the users you have added to the openldap.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*O2Yyc_p3Lm94RCdn" /></figure><ul><li>Similarly, you can see the groups as well.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wdqVR22znbEurbjJ" /></figure><ul><li>You can try login to My account portal or any or any of your business application using one of the remote user credentials.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RFZckzO7kyHFJ3qQ" /></figure><h3>What else?</h3><p>1. You can navigate to the user store you have created and view the running agents. You get the capability to disconnect and regenerate the tokens of the agents that are running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HwoPFWo252Ufn3Cc" /></figure><p>2. You can run another User store agent using a new installation token if you want High availability. This will help for load balancing as well. For more information refer — <a href="https://wso2.com/asgardeo/docs/guides/users/user-stores/configure-high-availability/#connect-a-second-user-store-agent">https://wso2.com/asgardeo/docs/guides/users/user-stores/configure-high-availability/#connect-a-second-user-store-agent</a></p><p>3. You can disable the user store temporarily if you require it. If you disable the user store, its users will lose access to Asgardeo applications and administrators can no longer view users or groups of that user store in the Asgardeo console.</p><p>Thank you for reading. Have a Good Day!!</p><h3>References</h3><p><a href="https://wso2.com/asgardeo/docs/guides/users/user-stores/configure-a-user-store/#prerequisites">https://wso2.com/asgardeo/docs/guides/users/user-stores/configure-a-user-store/#prerequisites</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f36b65929f65" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secure a FastAPI Server with Asgardeo]]></title>
            <link>https://wathsara.medium.com/secure-a-fastapi-server-with-asgardeo-ca0575e9de2e?source=rss-b211f0baedf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca0575e9de2e</guid>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[asgardeo]]></category>
            <category><![CDATA[fastapi]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[wso2is]]></category>
            <dc:creator><![CDATA[Wathsara Wishwantha Daluwatta]]></dc:creator>
            <pubDate>Mon, 02 May 2022 08:04:59 GMT</pubDate>
            <atom:updated>2022-05-02T08:04:59.080Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jXxpL1FuvLxHNF9UZJ_vpg.png" /></figure><p>FastAPI is a modern, fast, web framework for building APIs with Python 3.6+. FastAPI uses a web server called ASGI (Asynchronous Server Gateway) Interface, it makes faster performance in your applications as it doesn’t have to wait for the other ones to complete before they are processed. You can find out more details from their official documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/0*nelvcOxCMBITN8SU.png" /></figure><p>From this article I’ll be explaining you on how to secure a FastAPI endpoint using a Opaque token of <strong>Asgardeo.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/0*_3VyC9pSshIgr2i-.png" /></figure><h3>Step 1 — Register an OpenID application in Asgardeo.</h3><ol><li>Login to <a href="https://console.asgardeo.io/">Asgardeo Console</a>.</li><li>Go to <strong>Develop</strong> section and then select <strong>Applications</strong>.</li><li>Click New<strong> </strong>Application.</li><li>Choose <strong>Standard-Based Application.</strong></li><li>Provide any application name and Choose <strong>OpenID Connect </strong>click register.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PipU5wAupcTiUkSIhI1_ug.png" /></figure><p>6. Then go to <strong>Protocol</strong> tab and obtain a <strong>Client ID</strong> and <strong>Client Secret.</strong></p><p>7. Then update the allowed grant types by selecting the <strong>Client Credentials</strong> and <strong>Password</strong>. And also make sure Access Token type is selected as <strong>Opaque</strong> as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKffKf8ZKel_lBzm1FzRjA.png" /></figure><h3>Step 2 — Create a customer user in Asgardeo.</h3><ol><li>Go to <strong>Manage</strong> section and then select <strong>Users</strong>.</li><li>Click <strong>New User</strong> and select <strong>Customer.</strong></li><li>Enter the customer Email, First Name, Last Name and select Set a temporary password for user and enter a password and then click <strong>Finish.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7bZO9-C4WY7cMU-W.png" /></figure><h3>Step 3 — Getting started with FastAPI.</h3><p>Now we have the necessary configuration from the Asgardeo side. Lets Start coding.</p><ol><li>First You need to install the FastAPI using the pip.</li></ol><pre>pip install fastapi</pre><p>2. Then we need install uvicorn to work as the server:</p><pre>pip3 install &quot;uvicorn[standard]&quot;</pre><p>3. Lets create the public endpoint first which is accessible without an access token.</p><pre># main.py</pre><pre>from fastapi import FastAPI<br>from fastapi_versioning import VersionedFastAPI, version</pre><pre>app = FastAPI()</pre><pre>@app.get(&quot;/&quot;)<br><a href="http://twitter.com/version">@version</a>(1)<br>def public():</pre><pre>     result = {<br>         &quot;status&quot;: &quot;Success&quot;,<br>         &quot;msg&quot;: (&quot;Hello from a public endpoint.&quot;)<br>      }<br>     return result</pre><pre>app = VersionedFastAPI(app)</pre><p>Start the server using uvicorn main:app --relaod and try out the endpoint using the below command.</p><pre>curl --location --request GET &#39;<a href="http://127.0.0.1:8000/v1_0/api/public&#39;">http://127.0.0.1:8000/v1_0/api/public&#39;</a></pre><h3>Step 4 — Create a secured endpoint with Asgardeo.</h3><blockquote><strong>Opaque</strong>: These types of tokens are plain text tokens. If a resource server wants to know information related to opaque token, it has to query introspection endpoint and get the information related to tokens.</blockquote><p>As we are using the Opaque token, we have to have a method implemented in our code to query the introspection endpoint to validate the access token.</p><pre>import requests<br>import os</pre><pre>org = os.getenv(&quot;ORG&quot;)<br>internal_client_id = os.getenv(&quot;CLIENT_ID&quot;)<br>internal_client_secret = os.getenv(&quot;CLIENT_SECRET&quot;)</pre><pre>def introspect_token(token_string):</pre><pre>   url = &#39;<a href="https://api.asgardeo.io/t/&#39;">https://api.asgardeo.io/t/&#39;</a> + org + &#39;/oauth2/introspect&#39;<br>   data = {&#39;token&#39;: token_string, &#39;token_type_hint&#39;: &#39;access_token&#39;}<br>   auth = (internal_client_id, internal_client_secret)<br>   resp = requests.post(url, data=data, auth=auth)<br>   resp.raise_for_status()<br>   active_status = resp.json().get(&quot;active&quot;)<br>   return active_status</pre><p>When calling the introspect_token method with the access token, It will send the post request to the introspection endpoint of your organization. Then we’ll be using the active key of the response json to validate the token. More information regarding the token validation can be found at the <a href="https://wso2.com/asgardeo/docs/guides/authentication/oidc/token-validation-resource-server">Asgardeo docs</a>.</p><p>Lets create the private endpoint just like the public endpoint. Here we’ll be using the <strong>FastAPIs</strong> HTTPBearer schema to get the authorization header. This is available under the <strong>fastapi.security.</strong></p><pre>from fastapi.security import HTTPBearer</pre><pre># Scheme for the Authorization header                             token_auth_scheme = HTTPBearer()</pre><pre><a href="http://twitter.com/app">@app</a>.get(&quot;/api/private&quot;)<br>def private(response: Response, token: str = Depends(token_auth_scheme)): <br>   <br>   &quot;&quot;&quot;A valid access token is required to access this route&quot;&quot;&quot;</pre><pre>   authorized = introspect_token(token.credentials)<br>   result = {<br>      &quot;status&quot;: &quot;Success&quot;,<br>      &quot;msg&quot;: (&quot;Hello from a private endpoint protected with Asgardeo opaque token.&quot;)<br>   }<br>   if authorized == True:<br>      return result<br>   else:<br>      return unauthorizedResponse()</pre><pre>def unauthorizedResponse():</pre><pre>   result = {<br>      &quot;status&quot;: &quot;Unauthorized&quot;,<br>      &quot;msg&quot;: &quot;Token is invalid or expired.&quot;<br>   }<br>   return JSONResponse(status_code=status.HTTP_401_UNAUTHORIZED, content=result)</pre><p><strong>Great…!!</strong></p><p>Here we have created our first endpoint secured with the Asgardeo Opaque token.</p><p>Let try out the endpoint with a valid Opaque token. Use the following command to get a valid access token for the user you have created in the Step 2.</p><pre>curl --location --request POST &#39;<a href="https://dev.api.asgardeo.io/t/wathsarad/oauth2/token?grant_type=password&amp;username=jmeter_11@wso2.com&amp;password=Ucsc@123&#39;">https://api.asgardeo.io/t/&lt;ORG&gt;/oauth2/token?grant_type=password&amp;username=&lt;USERNAME&gt;&amp;password=&lt;PASSWORD&gt;&#39;</a> \<br>--header &#39;Content-Type: application/json&#39; \<br>--header &#39;accept: application/json&#39; \<br>--header &#39;Authorization: Basic BASE46_ENCODING&lt;client_id:client_secret&gt;&#39;</pre><p>Then try out the endpoint with the token obtained from the above.</p><pre>curl --location --request GET &#39;<a href="http://127.0.0.1:8000/v1_0/api/private&#39;">http://127.0.0.1:8000/v1_0/api/private&#39;</a> \<br>--header &#39;Authorization: Bearer &lt;OPAQUE_TOKEN&gt;&#39;</pre><p>If the token you have entered is valid, you will get the below response</p><pre>{<br>    &quot;status&quot;: &quot;Success&quot;,<br>    &quot;msg&quot;: &quot;Hello from a private endpoint protected with Asgardeo opaque token.&quot;<br>}</pre><p>You can find the full code from below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a5431528cf4de91fb573b1f51fddad2/href">https://medium.com/media/1a5431528cf4de91fb573b1f51fddad2/href</a></iframe><p>If you want to tryout the sample please use the following command.</p><pre>docker run -p 8000:80 -e ORG=&quot;&lt;ORG&gt;&quot; -e CLIENT_ID=&quot;&lt;CLIENT_ID&gt;&quot; -e CLIENT_SECRET=&quot;&lt;CLIENT_SECRET&gt;&quot; wathsara/asgardeo-fastapi-sample:1.0.0</pre><p><strong>References</strong></p><ul><li><a href="https://wso2.com/asgardeo/docs/">Home</a></li><li><a href="https://fastapi.tiangolo.com/">FastAPI - FastAPI</a></li></ul><p>Thank you for reading my article. Have a Good Day!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca0575e9de2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hello Rancher Desktop!!]]></title>
            <link>https://wathsara.medium.com/hello-rancher-desktop-35db030822bf?source=rss-b211f0baedf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/35db030822bf</guid>
            <category><![CDATA[docker-desktop]]></category>
            <category><![CDATA[rds]]></category>
            <category><![CDATA[rancher-desktop]]></category>
            <dc:creator><![CDATA[Wathsara Wishwantha Daluwatta]]></dc:creator>
            <pubDate>Sun, 30 Jan 2022 18:32:21 GMT</pubDate>
            <atom:updated>2022-01-31T06:05:43.390Z</atom:updated>
            <content:encoded><![CDATA[<p>Docker Desktop is an application which is available for Mac and Windows environments to build and share containerized applications. I have been using it for sometime mostly to use docker on my Mac.</p><blockquote>I never had any reason to look for an alternative for docker desktop until I saw that <strong>Docker Desktop is no longer free for enterprise users.</strong></blockquote><p>I have figured out <a href="https://minikube.sigs.k8s.io/docs/start/"><strong>minikube</strong></a> and Rancher desktop as the two best alternatives for the Docker desktop. I have tried minikube which I felt was a really good docker desktop alternative. <strong>Minikube</strong> has been in the system for quite some time now, the community is quite good and the product is more stable. Even though that, I wanted to try the Rancher Desktop as Its something that I haven’t heard of previously.</p><blockquote>This post is focused on Mac only.</blockquote><h3>Rancher Desktop</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*AB23v4S6ZolzaWxh.png" /></figure><p>Rancher Desktop (<strong>RD</strong>) is an open-source application to run Kubernetes and container management. It provides capability to manage containers either by using containerd or dockerd(Moby) as the container runtime. It is available for Mac (both on Intel and Apple Silicon), Windows, and Linux. Visit <a href="https://rancherdesktop.io/">https://rancherdesktop.io</a> find out more details.</p><p>Although my experience with Rancher Desktop is very little, I think it’s a really good alternative for docker desktop. But there were few issues I have faced while I’m working with docker on the Rancher Desktop.</p><h3><strong>1. Run a docker container on ports 80 and 443.</strong></h3><p>The first thing I did after installing the RD was to run the docker ps command. It has listed several running containers but It was not a problem for me at that point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Di_bATzK_4L7SAgoJ47lPQ.png" /><figcaption>docker ps output</figcaption></figure><p>Then after I ran a nginx container to verify whether everything is working fine. (docker run — name nginx -p 80:80 nginx). Then I opened my browser and tried to reach the 127.0.0.1 and It says 404 not found but I was expecting the <strong>Welcome to nginx!. </strong>After doing an initial research I have found that It’s causing due a ingress controller which is included in the K3s. Since I want to run the container only, I was able to fix this by disabling the Kubernetes manually by deleting the node.</p><pre>kubectl config use-context rancher-desktop &amp;&amp; kubectl delete node lima-rancher-desktop</pre><h3>2. host.docker.internal</h3><p>host.docker,internal which is a special DNS name to resolve to the internal IP address used by the host. This has been used to communicate with the services running in the host machine.</p><p>By default this host mapping has been added by the RD to the VM (<a href="https://github.com/rancher-sandbox/rancher-desktop/pull/1000">https://github.com/rancher-sandbox/rancher-desktop/pull/1000</a>). So whenever you are running a container on a host network you will get the host.docker.internal inside your container. If you want to verify run a nginx container in the host network using docker run — name nginx-2 — network host -it nginx bash and then execute cat /etc/hosts to see the host mapping available for the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*LnecUib0P9W1twqeHpd1cQ.png" /><figcaption>Output of cat /etc/hosts</figcaption></figure><p>You will see 192.168.5.2 has been mapped to host.docker.internal. Now you can do the same thing if you want the host.docker,internal inside your container and not wanting to run it on the host network by using docker run — name nginx-2 — add-host host.docker.internal:192.168.5.2 nginx</p><blockquote>192.168.5.2 — There is no official place where it is mentioned that this IP is static or not. As I think, this has to be the Lima/QEMU gateway IP so it has to be static with RD.</blockquote><h3>3. Is the docker daemon running?</h3><p>I had an issue getting <strong>Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?</strong> after executing an automated script I have written to set up few applications. After this issue I have to Quit and Launch the RD to work with docker commands again.</p><p>I have faced a similar kind of issue with docker desktop where it gets crashed if we kill processes running on a port where a container is running. Which actually helped me a lot to identify what the issue is.</p><p>In RD, if we kill processes running using kill -9 $(lsof -ti:&lt;port&gt;) or npx kill-port &lt;port&gt; using any other way, it will end up with <strong>Cannot connect to the Docker daemon</strong>. So make sure to be aware of that.</p><h3>Conclusion</h3><p>Although the rancher desktop is young, it has become one of the most favorite alternatives for the docker desktop. Even though I have been using it for a few days, I’m so impressed with how it works. Biggest drawback I’m seeing at the moment is the community support. Finally I would love to mention to you that RD is a superb alternative to docker desktop.</p><p>Thank you for reading my article. Have a Good Day!!</p><h3>References</h3><ul><li><a href="https://rancherdesktop.io/">Rancher Desktop by SUSE</a></li><li><a href="https://github.com/rancher-sandbox/rancher-desktop/issues/1194#issuecomment-1013155085">Unable to run a container which is reachable on ports 80 or 443 · Issue #1194 · rancher-sandbox/rancher-desktop</a></li><li><a href="https://www.docker.com/products/docker-desktop">Docker Desktop</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35db030822bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asgardeo authentication with Golang and Goth]]></title>
            <link>https://wathsara.medium.com/asgardeo-authentication-with-golang-and-goth-2be8eea7dbe7?source=rss-b211f0baedf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2be8eea7dbe7</guid>
            <category><![CDATA[asgardeo]]></category>
            <category><![CDATA[goth]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[authentication]]></category>
            <dc:creator><![CDATA[Wathsara Wishwantha Daluwatta]]></dc:creator>
            <pubDate>Sat, 22 Jan 2022 13:14:49 GMT</pubDate>
            <atom:updated>2022-01-22T13:22:36.118Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sLjfOCxmeDbP0qH6BDKKBA.png" /></figure><p>With this blog I will focus on implementing authentication via Asgardeo in a Go web application. For this you need to have the basic knowledge on GO, HTML and CSS. As Asgardeo has not yet released an official Golang SDK yet, I will be using the<a href="https://github.com/markbates/goth"> Goth</a> which is an open source Multi-Provider Authentication package for Golang.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/0*_Cqp-sg32A9GcMkp.png" /></figure><h3>Step 1 — Register an OpenID application in Asgardeo.</h3><ol><li>Login to <a href="https://console.asgardeo.io/">Asgardeo Console</a>.</li><li>Go to <strong>Develop</strong> section and then select <strong>Applications</strong>.</li><li>Click New<strong> </strong>Application.</li><li>Choose <strong>Traditional Web Application</strong> and Choose <strong>OpenID Connect</strong>.</li><li>Provide any application name and configure <a href="http://localhost:8000/auth/openid-connect/callback">http://localhost:8000/auth/openid-connect/callback</a> and <a href="http://localhost:8000/logout/openid-connect">http://localhost:8000/logout/openid-connect</a> as the<strong> Authorized redirect URLs </strong>(If you are planning to run on a different port, update the callback URLs with your port) and<strong> </strong>click<strong> Register.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*34D7m1QyyVs96JX3OxEdhQ.png" /></figure><p>6. Then go to <strong>Protocol</strong> tab and obtain a <strong>Client ID</strong> and <strong>Client Secret.</strong></p><p>7. Then add <a href="http://localhost:8000/">http://localhost:8000</a> in the allowed origins field and update the application.</p><h3>Step 2 —Create a customer user in Asgardeo.</h3><ol><li>Go to <strong>Manage</strong> section and then select <strong>Users</strong>.</li><li>Click <strong>New User</strong> and select <strong>Customer.</strong></li><li>Enter the customer Email, First Name, Last Name and select Set a temporary password for user and enter a password and then click <strong>Finish.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mep_E7Ts-LT3Kv2o7_7fBA.png" /></figure><h3>Step 3 — Initialize a Go project.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*niyjw1R8VYbrt3sh.png" /></figure><p>Go to a new directory and execute the following command. It will create a new go.mod which will help us to manage the dependencies easily.</p><pre>go mod init asgardeo</pre><p>If your are new to Golang please follow <a href="https://go.dev/doc/code">this article</a> to create your first project.</p><h3>Step 4 — Implement the Golang server.</h3><p>Following are the main packages that we’ll be using for the implementation.</p><ul><li><strong>html/template:</strong> Go package to parse html files.</li><li><strong>gorilla/pat:</strong> A request router and dispatcher.</li><li><strong>gorilla/sessions:</strong> To save information from asgardeo in session.</li><li><strong>markbates/goth/providers/openidConnect:</strong> OpenID connect provider provider by Goth.</li></ul><p>First we need to initialize a session store called NewCookieStore() provided by the <strong>gorilla/sessions</strong> and pass a secret key used to authenticate the session. Inside the handler, we call store.Get() to retrieve an existing session or create a new one. Then we set some session values in session.Values, which is a map[interface{}]interface{}. And finally we call session.Save() to save the session in the response. Then we can set this as the gothic store to manage the session. We can do it by adding the following code to main.go.</p><pre>var key = “_auth_session” // Note: Don&#39;t store your key in your source code.<br>var store = sessions.NewCookieStore([]byte(key))<br>var sessionName = “auth”</pre><pre>func main() {</pre><pre>    store.MaxAge(3600)<br>    store.Options.Path = “/&quot;<br>    store.Options.HttpOnly = true<br>    gothic.Store = store<br>}</pre><p>Then we need to set up the Openid connect configuration by adding the following code in the main function of the <strong>main.go</strong></p><pre>// Export these to enviroment varibles with your valus.<br>OPENID_CONNECT_KEY := os.Getenv(“OPENID_CONNECT_KEY”)<br>OPENID_CONNECT_SECRET := os.Getenv(“OPENID_CONNECT_SECRET”)<br>ASGARDEO_ORG_NAME = os.Getenv(“ASGARDEO_ORG_NAME”)</pre><pre>CALLBACK_URL := “http://localhost:8000/auth/openid-connect/callback&quot;</pre><pre>OPENID_CONNECT_DISCOVERY_URL := fmt.Sprintf(“https://api.asgardeo.io/t/%s/oauth2/token/.well-known/openid-configuration&quot;, ASGARDEO_ORG_NAME)</pre><pre>openidConnect, _ := openidConnect.New(OPENID_CONNECT_KEY, OPENID_CONNECT_SECRET, CALLBACK_URL, OPENID_CONNECT_DISCOVERY_URL)</pre><pre>if openidConnect != nil {<br>   goth.UseProviders(openidConnect)<br>}</pre><p>Then we will create the Go server with the following routes. We will be using the <strong>gorilla/pat </strong>for routing. Include the following code in the main method as well.</p><pre>router := pat.New()<br>router.Get(“/auth/{provider}/callback”, callback)<br>router.Get(“/auth/{provider}”, auth)<br>router.Get(“/logout/{provider}”, logout)<br>router.Get(“/home”, home)<br>router.Get(“/”, indexHandler)<br>http.Handle(“/”, router)</pre><pre>log.Print(“Listening on port 8000…”)<br>log.Fatal(http.ListenAndServe(“:8000”, nil))</pre><p>Create a separate directory named ui to include the HTML files that are needed for our web application.</p><p>Add the following code to a file named <strong>index.html</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/264d1e880c48b2a8798bdee3cf5b984b/href">https://medium.com/media/264d1e880c48b2a8798bdee3cf5b984b/href</a></iframe><p>Create another file in the ui directory with name <strong>home.html</strong> and include the following code into the file. This will show the decorded ID token after successful authentication.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a8bb9ced163ea09fd3c829dd8d8518f/href">https://medium.com/media/6a8bb9ced163ea09fd3c829dd8d8518f/href</a></iframe><p>Let’s start to implement the rest of the functions.</p><ul><li><strong>“/”:</strong> The root route will render the index.html page. This page will include the SignIn button.</li></ul><pre>func indexHandler(wr http.ResponseWriter, req *http.Request){<br>   <br>   wr.WriteHeader(http.StatusOK)<br>   t, _ := template.ParseFiles(“ui/index.html”)<br>   t.Execute(wr, false)<br>}</pre><ul><li><strong>/auth/{provider}:</strong> When you click on SignIn button it will hit this route and gothic.BeginAuthHandler will redirect you to the Asgardeo for the authentication.</li></ul><pre>func auth(wr http.ResponseWriter, req *http.Request) {</pre><pre>    gothic.BeginAuthHandler(wr, req)<br>}</pre><ul><li>/auth/{provider}/callback: Once you have authenticated, gothic.CompleteUserAuth will capture the relevant information from the callback. This is why we initially configured the callback URL with<a href="http://localhost:8000/auth/openid-connect/callback"> http://localhost:8000/auth/openid-connect/callback</a>. Then goth will save the information in session to use when the web application wants.</li></ul><pre>func callback(wr http.ResponseWriter, req *http.Request) {</pre><pre>     user, err := gothic.CompleteUserAuth(wr, req)<br>     if err != nil {<br>         wr.WriteHeader(http.StatusInternalServerError)<br>         log.Print(err)<br>         return<br>     }<br>     addUserToSession(wr, req, user)<br>     http.Redirect(wr, req, &quot;/home&quot;, http.StatusFound)</pre><pre>}</pre><ul><li><strong>“/home”:</strong> The route will render the home.html page. This page will include the information of the jwt token.</li></ul><pre>func home(wr http.ResponseWriter, req *http.Request) {</pre><pre>   session, _ := store.Get(req, sessionName)<br>   user := session.Values[&quot;user&quot;].(goth.User)<br>   if user.IDToken == &quot;&quot; {<br>       wr.Header().Set(&quot;Location&quot;, &quot;/&quot;)<br>       wr.WriteHeader(http.StatusTemporaryRedirect)<br>       return<br>   }</pre><pre>   t, _ := template.ParseFiles(&quot;ui/home.html&quot;)<br>   t.Execute(wr, struct {<br>       Org     string<br>        IDToken string<br>   }{ASGARDEO_ORG_NAME, user.IDToken})<br>}</pre><ul><li><strong>/logout/{provider}:</strong> This route will be use to remove the session. Users will be redirected to this route from the post logout redirect url from the asgardeo. That’s why we configured the call back URL with<a href="http://localhost:8000/logout/openid-connect"> http://localhost:8000/logout/openid-connect</a>.</li></ul><pre>func logout(wr http.ResponseWriter, req *http.Request) {<br>  <br>    err := gothic.Logout(wr, req)</pre><pre>    if err != nil {<br>       log.Print(&quot;Logout fail&quot;, err)<br>    }</pre><pre>    removeUserFromSession(wr, req)<br>    wr.Header().Set(&quot;Location&quot;, &quot;/&quot;)<br>    wr.WriteHeader(http.StatusTemporaryRedirect)<br>}</pre><h3>It’s time for the demonstration.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*rLbZcx5r-PFxUSABFIe1dA.gif" /></figure><p><strong>Great…!!</strong></p><p>Here you have implemented Asgardeo authentication with Golang. Now you could follow <a href="https://wso2.com/asgardeo/docs/">https://wso2.com/asgardeo/docs</a> and customize the logins as you wish within minutes.</p><p>If you want to tryout the sample please use the following command.</p><pre>docker run -e OPENID_CONNECT_KEY=&lt;YOUR_APP_KEY&gt; \<br>-e OPENID_CONNECT_SECRET=&lt;YOUR_APP_SECRET&gt; \<br>-e ASGARDEO_ORG_NAME=&lt;YOUR_ORG_NAME&gt; \<br>-p 8000:8000 wathsara/asgardeo-go-sample-app:1.0.0</pre><p>You can find the sample application with full code base from below GitHub repository.</p><p><a href="https://github.com/Wathsara/asgardeo-go-sample-app">GitHub - Wathsara/asgardeo-go-sample-app: Sample Go lang web application with Asgardeo</a></p><p>Thank you for reading my article. Have a Good Day!!</p><p><strong>References</strong></p><p><a href="https://wso2.com/asgardeo/docs/">https://wso2.com/asgardeo/docs</a></p><p><a href="https://github.com/markbates/goth">GitHub - markbates/goth: Package goth provides a simple, clean, and idiomatic way to write authentication packages for Go web applications.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2be8eea7dbe7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configure Asgardeo as JupyterHub authenticator]]></title>
            <link>https://wathsara.medium.com/configure-asgardeo-as-jupyterhub-authenticator-79dc71f794de?source=rss-b211f0baedf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/79dc71f794de</guid>
            <category><![CDATA[idaas]]></category>
            <category><![CDATA[asgardeo]]></category>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[ami]]></category>
            <dc:creator><![CDATA[Wathsara Wishwantha Daluwatta]]></dc:creator>
            <pubDate>Sun, 31 Oct 2021 08:01:03 GMT</pubDate>
            <atom:updated>2021-10-31T08:01:03.935Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Asgardeo?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*NAsh7VWHmIyLt2zcoPpeXw.png" /></figure><p><a href="https://wso2.com/asgardeo">Asgardeo</a> is latest IDaaS introduced by WSO2 enabling developers with little IAM experience to create seamless login experiences in minutes. Currently Asgardeo is live for Early Adoption which I’m inviting you all to start your journey with next generation IDaaS today for free. With this blog I will focus on to configuring Asgardeo as JupyterHub authenticator.</p><h3>What is JupyterHub?</h3><p>You all might have heard about <strong><em>Jupyter Notebook</em></strong> which is a server-client application that allows editing and running notebook documents via a web browser. JupyterHub is an extended version which brings the power of notebooks to groups of users.</p><p><strong>Prerequisites</strong></p><ol><li>Sign up to <a href="https://wso2.com/asgardeo/signup">Asgardeo</a>.</li><li><a href="https://jupyterhub.readthedocs.io/en/stable/quickstart.html#installation">Install JupyterHub</a></li></ol><h3>First you need to register an <strong>OpenID</strong> application in Asgardeo.</h3><ol><li>Login to <a href="https://console.asgardeo.io/">Asgardeo Console</a>.</li><li>Go to <strong>Develop</strong> section and then select <strong>Applications</strong>.</li><li>Click New<strong> </strong>Application.</li><li>Choose <strong>Traditional Web Application</strong> and Choose <strong>OpenID Connect</strong>.</li><li>Provide any application name and configure <a href="http://localhost:8000/hub/oauth_callback">http://localhost:8000/hub/oauth_callback</a> as the<strong> Authorized redirect URLs </strong>and<strong> </strong>click<strong> Register</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*er5IahfQAGyUiiIWj1-zqQ.png" /></figure><p>6. Then go to the <strong>User Attribute tab &gt; First Name </strong>and update the application. Then <strong>OpenID Connect Scopes &gt; OpenID &gt; New Attribute </strong>and<strong> add First Name.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U5jA8kXz65A__V0Zu0JXww.gif" /></figure><p>7. Then go to <strong>Protocol</strong> tab and obtain a <strong>Client ID</strong> and <strong>Client Secret.</strong></p><p>8. As the Final step, go to info tab to obtain all the sever endpoints which we will be using in next steps.</p><h3>Now you need to create a customer user in Asgardeo.</h3><ol><li>Go to <strong>Manage</strong> section and then select <strong>Users</strong>.</li><li>Click <strong>New User</strong> and select <strong>Customer.</strong></li><li>Enter the customer Email, First Name, Last Name and select Set a temporary password for user and enter a password and then click <strong>Finish.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mep_E7Ts-LT3Kv2o7_7fBA.png" /></figure><h3>Now it’s time to start configure JupyterHub.</h3><ol><li>JupyterHub will look by default for a configuration file, in the current working directory by default. Therefor to generate the run jupyterhub — generate-config</li><li>Install the oauthenticator package using the pip install oauthenticator</li><li>Then Inset the following python to the generated jupyter_notebook_config.py by replacing the values you obtained from the Asgardeo.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd52000b798c496596a98a9eeff33104/href">https://medium.com/media/dd52000b798c496596a98a9eeff33104/href</a></iframe><p>4. Now start the JupyterHub pointing out the configuration file we just created by using jupyterhub -f /path/to/jupyterhub_config.py command.</p><blockquote>5 . This step is only for the users that are not having a Linux OS as their OS. What you need to do is create a user by giving the same <strong>first name you have used to create the customer user in Asgardeo</strong>.</blockquote><blockquote>Mac — <a href="https://support.apple.com/en-lk/guide/mac-help/mtusr001/mac">https://support.apple.com/en-lk/guide/mac-help/mtusr001/mac</a><br>Windows — <a href="https://www.windows-commandline.com/add-user-from-command-line/">https://www.windows-commandline.com/add-user-from-command-line/</a></blockquote><h3>It’s time for the demonstration.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jcOa5w9NRCUbVhb_mbH0LA.gif" /></figure><p><strong>Great…!!</strong></p><p>Here you have configure the Asgardeo as the authenticator of JupyterHub. Now you could follow <a href="https://wso2.com/asgardeo/docs/">https://wso2.com/asgardeo/docs</a> and customize the logins as you wish within minutes.</p><p>And also you can follow <a href="https://github.com/jupyterhub/oauthenticator">https://github.com/jupyterhub/oauthenticator</a> and bring your authorization to the JupyterHub. Hopefully I will come up with an separate article on how to do it using the Asgardeo.</p><h3>Reference</h3><p><a href="https://github.com/jupyterhub/oauthenticator">GitHub - jupyterhub/oauthenticator: OAuth + JupyterHub Authenticator = OAuthenticator</a></p><p><a href="https://wso2.com/asgardeo/docs/">https://wso2.com/asgardeo/docs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79dc71f794de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I have added my Medium articles to GitHub profile page.]]></title>
            <link>https://wathsara.medium.com/how-i-have-added-my-medium-articles-to-github-profile-page-300f4733899e?source=rss-b211f0baedf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/300f4733899e</guid>
            <category><![CDATA[profile-page]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[médium]]></category>
            <category><![CDATA[workflow]]></category>
            <dc:creator><![CDATA[Wathsara Wishwantha Daluwatta]]></dc:creator>
            <pubDate>Thu, 10 Sep 2020 07:37:19 GMT</pubDate>
            <atom:updated>2020-09-10T07:50:41.923Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello Guys!!.. Recently I tried lots of workflows in the GitHub to make my profile page a really attractive one. Before Moving into rest let me show you my profile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*Py4yvBF6VlN1zrk7caSKZA.png" /><figcaption>Profile Page</figcaption></figure><p>What is actually a profile repository is? Let me explain. If you add a README file to the root of a public repository with the same name as your username, that README will automatically appear on your profile page. You can edit your profile README with GitHub Flavored Markdown to create a personalized section on your profile. What I am referring to as a profile repository is a repository created with the GitHub username.</p><p>I needed to add my Medium articles as a list to my profile page in GitHub. But I never wanted to update the list manually whenever I wrote an article. So I thought to create a GitHub workflow to do the job for me. Then I Implemented a really small python script and now I scheduled the job using the GitHub workflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iDTTAt9ZVEtLQOujVkHzQQ.png" /><figcaption>Medium Articles</figcaption></figure><p>I am not going to explain how I did implement that using the python as it is really easy to understand. Anyone can see the implementation from the below link. (PRs are welcome as well)</p><p><a href="https://github.com/Wathsara/medium-blogs-readme">Wathsara/medium-blogs-readme</a></p><p><strong>Steps to run</strong></p><p>1 . Add the following comments to your README</p><pre>&lt;!--START_SECTION:medium--&gt;<br>&lt;!--END_SECTION:medium--&gt;</pre><p>2. Create a workflow.</p><pre>on:<br>  schedule:<br>      # Runs at every 2 days. Schedule it as you want.<br>      - cron: &#39;0 0 */2 * *&#39;<br>jobs:  <br>  update-readme:<br>    name: Update this repo&#39;s README<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: wathsara/medium-blogs-readme@master<br>        with:<br>          MEDIUM_HANDLER: &#39;@wathsara&#39; //Your Medium Handler<br>          GH_TOKEN: ${{ secrets.GH_TOKEN }}<br>          REPOSITORY: &lt;username&gt;/&lt;repo-name&gt;<br>          DAYS: 30 // Show blogs wrote in last 30 days</pre><p>Now its all done and the list will be updated every 2 days (Depends on how you schedule the job) on your profile page. All you have to do is keep writing. Check out my repository for more details.</p><p>Hope to see you guys with my next article. Have a Good Day and Stay safe!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=300f4733899e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Node OAuth applications with WSO2 Identity Server.]]></title>
            <link>https://wathsara.medium.com/setting-up-node-oauth-applications-with-wso2-identity-server-1d13cb1650f0?source=rss-b211f0baedf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d13cb1650f0</guid>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[wso2is]]></category>
            <category><![CDATA[wso2]]></category>
            <dc:creator><![CDATA[Wathsara Wishwantha Daluwatta]]></dc:creator>
            <pubDate>Mon, 25 Nov 2019 04:39:20 GMT</pubDate>
            <atom:updated>2022-03-09T13:58:23.971Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello… Today I’m going to do some interesting things. I’m going to show you guys how to config a node application with the WSO2 Identity Server. No need to talk a lot lets move to the configurations.</p><h4><strong>Prerequisites</strong></h4><ol><li>Download the product.</li></ol><ul><li>In your Web browser, go to <a href="http://wso2.com/products/identity-server">http://wso2.com/products/identity-server</a>.</li><li>Click the <strong>Download</strong> button in the upper right-hand corner of the page to download the <strong>latest</strong> version. To download an older version, click the <strong>Previous Releases</strong> link and then select the version that you want.</li><li>Enter the required details in the form, and click <strong>Download</strong>.</li></ul><p>2. Clone the samples repository from <a href="https://github.com/Wathsara/OAuth-Node-WSO2-IS">https://github.com/Wathsara/OAuth-Node-WSO2-IS</a>.</p><p><strong>To start the server </strong><a href="https://is.docs.wso2.com/en/5.9.0/setup/installation-prerequisites/#running-the-product"><strong>click here</strong></a><strong> and follow the steps correctly.</strong></p><h4><strong>Configurations.</strong></h4><p>Open the management console <a href="https://localhost:9443/carbon">https://localhost:9443/carbon</a> and login with admin user credentials. (username — admin, password — admin).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ROvJCKfzSeVyM8hgObTc2w.png" /><figcaption>Login page of Management console</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*f9yaYL3lPao2UnLlwIFXmQ.png" /><figcaption>Menu</figcaption></figure><p>After you successfully login to the Management Console, you can find out the menu bar on the right-hand side of the window.</p><p>Click the add button under service providers.</p><p>Then you will be redirected to the add new service provider page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*DYZ6JZGgNz5mCykRivW_LA.png" /><figcaption>Add New Service Provider Page</figcaption></figure><p>Enter an unique name for service provider.</p><p>I added oAuth as my service provider name.</p><p>Description field is optional and just ignore it for now and click the Register button.</p><p>Then You will redirect to the configure service provider page, where you can find many options to configure your service provider.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*sNcm81u35Hvs0smBgT1bUw.png" /><figcaption>configure service provider page</figcaption></figure><p>For now, go to the <br><strong>Inbound Authentication Configuration → OAuth/OpenID Connect Configuration → Configure.</strong></p><p>Then You will redirect to the Register new application settings page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*wE252yUOBH8mHWIyfOrPIw.png" /><figcaption>Register New Application page</figcaption></figure><p>Put the call-back URL of the application.</p><p>You can add your own redirect URL as well. But for now, add the URL given below which will ease the inauguration of the node application.</p><p><a href="http://localhost:8010/oauth">http://localhost:8010/oauth</a></p><p>Then click the Add button.</p><p>After that You’ll redirect back and you’ll be able to find out you client key and client Secret.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*zn9u8b6NesNneJVxcc_HPw.png" /><figcaption>Client key and client secret</figcaption></figure><p>Now you successfully configured your service provider inside the WSO2 identity server.</p><h4><strong>Config the Node application</strong></h4><p>Open the cloned project and run <strong>npm i </strong>command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*Ehwj7GzB2DbzdtvN02sO2g.png" /><figcaption>index.js</figcaption></figure><p>Then open the <strong>index.js</strong> file and <strong>replace the clientID with your client key and and clientSecret with your client secret.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*zRJytTf4HrzyyaPcP7bhsA.png" /><figcaption>index.html</figcaption></figure><p>Open the <strong>public → index.html</strong> file and replace the client_id with your client key.</p><p>Configurations are all done. Run <strong>node index,js </strong>command.</p><p>Then go to <a href="http://localhost:8010/">http://localhost:8010/</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ug0Eu8HM5ydpfOMpzEqN1A.png" /><figcaption>Opening page.</figcaption></figure><p>Then Click the <strong>Login with wso2 Identity Server </strong>link. Then you will redirect to the login page of the wso2 is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yu8BhSsuxl-PRtJrLpGzBQ.png" /><figcaption>Login page</figcaption></figure><p>Then enter the admin credentials (username — admin, password — admin).</p><p>Then click Approve once and press continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nEos1MNAHo3mN6g462W1kw.png" /><figcaption>Authorize page</figcaption></figure><p>Then you will redirect to the <strong>welcome.html</strong> page and you will get the access token as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VUMTUbw-gB-8mKkc4gUXTA.png" /><figcaption>welcome.html</figcaption></figure><p>That’s It. You have your own OAuth application with WSO2 Identity server.</p><p>If you gained something from this article let me know with a comment or claps.And I’m looking forward to see you again soon with my next article. Have a Good Day!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d13cb1650f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authentications vs Authorization]]></title>
            <link>https://wathsara.medium.com/authentications-vs-authorization-f7560d24e0f6?source=rss-b211f0baedf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7560d24e0f6</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[authorization]]></category>
            <dc:creator><![CDATA[Wathsara Wishwantha Daluwatta]]></dc:creator>
            <pubDate>Tue, 19 Nov 2019 05:11:07 GMT</pubDate>
            <atom:updated>2019-11-19T05:23:05.922Z</atom:updated>
            <content:encoded><![CDATA[<h3>Authentication vs Authorization</h3><p>Today I’m going to discuss something people confuse on. Authentication and Authorization, Feels like the same but different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*yc1XFXH1M6i7aYTIF5oO7A.png" /></figure><h3><strong>Authentication</strong></h3><p>Authentication is the process of verifying the identity of a user by obtaining some sort of credentials like User Name and password and using those credentials to verify the user’s identity. If the credentials are valid, the authorization process starts. Authentication process always proceeds to Authorization process. Authentication is usually done by a username and password, based on the security level authentication factor can vary. As examples</p><ul><li><strong>Single-Factor</strong> <strong>Authentication</strong> — It’s the simplest authentication method which commonly relies on a simple username and password to grant user access to a particular system.</li><li><strong>Two-Factor Authentication </strong>— Two-factor authentication (2FA), sometimes referred to as two-step verification or dual factor authentication, is a security process in which the user provides two different authentication factors to verify themselves to better protect both the user’s credentials and the resources the user can access.</li><li><strong>Multi-Factor Authentication </strong>— It is a security system that verifies a user’s identity by requiring multiple credentials. Rather than just asking for a username and password (We called this what you know), MFA requires some other additional credential normally from something you have or some thing you are.</li></ul><h3><strong>Authorization</strong></h3><p>Authorization is the process of allowing an authenticated users to access the resources by checking whether the user has access rights to the system. Authorization helps you to control access rights by granting or denying specific permissions to an authenticated user.</p><p>Systems and processes may also need to authorize their automated actions within a network. Online backup services, patching and updating systems and remote monitoring systems, such as those used in smart grid technologies, all need to securely authenticate before they can verify that it is the authorized system involved in any interaction and not a hacker.</p><p><strong>Real-world example</strong></p><p>When you go through security in an airport, you show your ID to authenticate your identity. Then, when you arrive at the gate, you present your boarding pass to the flight attendant, so they can authorize you to board your flight and allow access to the plane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*kSQKm-yhXuD5yG1r9yGjdw.png" /><figcaption>Source from [<a href="http://www.differencebetween.net/technology/difference-between-authentication-and-authorization/">http://www.differencebetween.net/technology/difference-between-authentication-and-authorization/</a>]</figcaption></figure><p>The authentication and authorization are the security measures taken in order to protect the data in the information system. Authentication is the process of verifying the person’s identity approaching the system. On the other hand, Authorization is the process of checking the privileges or access list for which the person is authorized.</p><p>I am looking forward to see you again soon with my next article. Have a Good Day!!</p><p>Reference — <a href="http://www.differencebetween.net/technology/difference-between-authentication-and-authorization/">http://www.differencebetween.net/technology/difference-between-authentication-and-authorization/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7560d24e0f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Adaptive Adaptive Authentication]]></title>
            <link>https://wathsara.medium.com/introduction-to-adaptive-adaptive-authentication-572874c8a6c3?source=rss-b211f0baedf8------2</link>
            <guid isPermaLink="false">https://medium.com/p/572874c8a6c3</guid>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[wso2is]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[adaptive-authentication]]></category>
            <dc:creator><![CDATA[Wathsara Wishwantha Daluwatta]]></dc:creator>
            <pubDate>Sat, 09 Nov 2019 12:52:42 GMT</pubDate>
            <atom:updated>2019-11-09T12:58:50.746Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction to Adaptive Authentication</h3><p>It is not a good idea to use a username and a static password as the authentication method for logins since it dramatically increases the risk of unauthorized access to services and information against the number of growing cyber-attacks. The next step is having <a href="https://medium.com/@wvd.51461/mfa-with-wso2-identity-server-f9ee3b7fef9e">MFA</a>. <a href="https://medium.com/@wvd.51461/mfa-with-wso2-identity-server-f9ee3b7fef9e">MFA</a> means <strong>M</strong>ulti<strong>-F</strong>actor <strong>A</strong>uthentication. It is a security system that verifies a user’s identity by requiring multiple credentials. Rather than just asking for a username and password.</p><p>Although Multi-factor authentication (MFA) can help to reduce the risk, does MFA affect usability? I think it affects, security and ease of use are often directly in conflict with each other. People do not like to enter OTPs or answer security questions whenever they try to login to a system. In this case, Adaptive authentication coming to play their role.</p><p>Adaptive MFA improves the user experience while also improving security. Users are only asked to provide an additional authentication factor when necessary. The reason is adaptive authentication users authenticate with a first factor, which is usually username and password. Then the authentication process checks contextual information such as IP, tenant, user role, etc. If the context doesn’t match the predefined policy, then only the system requests a second authentication method. Therefor adaptive authentication is a secure and flexible form of authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jzvoyW8IL0iuiYtu3okG0Q.png" /><figcaption>Example used by the WSO2 Identity Server</figcaption></figure><p>The WSO2 Identity Server (IS) management console provides an authentication script editor that allows you to define authentication scripts using JavaScript. The script editor provides a set of predefined templates that you can use to easily set up adaptive authentication for some of the most common authentication scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KQO2q1J09ggsDuqPTupAOg.png" /><figcaption>The authentication script editor of the WSO2 Identity Server Management Console</figcaption></figure><blockquote>Some of predefined templates of adaptive scripts in WSO2 Identity Server.<br> 1.Role-Based Adaptive Authentication<br> 2.Tenant-Based Adaptive Authentication<br> 3.New-Device-Based Adaptive Authentication<br> 4.IP-Based Adaptive Authentication</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*PMfr0lRnO4hJusG64xlIIA.png" /><figcaption>WSO2 Identity Server</figcaption></figure><p>As we discussed adaptive authentication enables ensuring security without impacting usability at the time of authentication thereby providing an enhanced user experience. If you are looking to add adaptive authentication to your system, use the WSO2 Identity server for a better and secure experience.</p><p>Have a Good Day!!</p><p>Reference — <a href="https://docs.wso2.com/display/IS570/Adaptive+Authentication">WSO2 Documentation</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=572874c8a6c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>