<?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 Dinuwan Kalubowila on Medium]]></title>
        <description><![CDATA[Stories by Dinuwan Kalubowila on Medium]]></description>
        <link>https://medium.com/@dckalubowila25132?source=rss-e56247d71f09------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*iQsqUzNoyx4wlU2R.jpg</url>
            <title>Stories by Dinuwan Kalubowila on Medium</title>
            <link>https://medium.com/@dckalubowila25132?source=rss-e56247d71f09------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 11:41:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dckalubowila25132/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[Transformation of the Network Trust patterns to Service Mesh in Micro services Governance]]></title>
            <link>https://medium.com/@dckalubowila25132/transformation-of-the-network-trust-patterns-to-service-mesh-in-micro-services-governance-15315989fb4d?source=rss-e56247d71f09------2</link>
            <guid isPermaLink="false">https://medium.com/p/15315989fb4d</guid>
            <category><![CDATA[service-mesh]]></category>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[istio-service-mesh]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[microservices-security]]></category>
            <dc:creator><![CDATA[Dinuwan Kalubowila]]></dc:creator>
            <pubDate>Fri, 19 Aug 2022 08:30:50 GMT</pubDate>
            <atom:updated>2022-08-19T10:21:32.303Z</atom:updated>
            <content:encoded><![CDATA[<h4>A periodical growth of Inter-Service communication on Microservices.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*Sk_EtPqQGgD5L9ECs2f-Rg.png" /></figure><h4><strong>Prerequisites</strong></h4><ul><li>Architectural changes from Monolith to Microservice.</li><li><a href="https://medium.facilelogin.com/challenges-of-securing-microservices-68b55877d154">Securing microservice applications</a>.</li></ul><h4><strong>Let me give you a brief intro on Microservices and how it was getting concurred</strong></h4><p>The concept “microservices” was originally introduced in 2011 to describe a specific implementation of Service-Oriented Architecture (SOA), which is a typical architectural technique for breaking down complex systems into tiny, loosely coupled services. With the innovation of microservices architecture, organizations such as Amazon, Netflix, Facebook and Uber have embraced DevOps and cloud computing best practices to build robust applications.</p><p>In a nutshell, the microservice architectural style is a methodology for building a single application as a collection of tiny services, each of which runs in its own process and communicates through lightweight methods, most often an HTTP resource API. These services are centered on business capabilities and are deployable independently through fully automated deployment machinery.</p><p>There is a bare minimum of central administration for these services, which may be built in a variety of programming languages and use a variety of data storage methods. Due to the fact that microservices use a range of technologies and platforms, traditional approaches of centralized controlling is ineffective. The microservices community prefers decentralized governance because its developers seek to create usable solutions which could be used by others to address similar issues. Microservice design, like decentralized governance, promotes decentralized data management. Generally, each service in a microservice application maintains its own database.</p><p>Microservice architectures will make use of libraries, their methodology of componentizing their own software is via service decomposition. Libraries are defined as components that are linked into a system and invoked from in function calls, while services are defined as out-of-process components that communicate via a method such as a RESTful web service request or remote procedure call. gRPC is the most widely used remote procedure call in microservices communication. When dividing a large scale software system into components, management often concentrates on the technology layer, resulting in the formation of UX/UI developers, backend developers, QA Engineers and database administration. Microservices use a new approach to division, segmenting into services structured around business capabilities. These services include the whole lifecycle of software development for that business sector, including the user interface, persistent storage, and any external collaborations.</p><p>I am not going to carry the story forward with Docker and Kubernetes much, even though those are the heart of modern microservices. Lets have a look into the architectural changes over securing microservices.</p><p><strong>Securing microservice can be divided into 02 phases.</strong></p><ol><li>Edge level security</li><li>Service to service security</li></ol><p>Edge-level security is enforced by the API gateway. It has done only for the inbound request towards the microservice deployment from the external party. (Outside from the cluster.) As an example let ‘s assume the end user sends a request to an e-commerce application. That E-commerce application has developed based on microservices architecture and it has services like <strong>Cart, Wishlist, Checkout, Orders </strong>and<strong> Inventory</strong> etc.</p><p>Once end user context is received the API gateway is going to check whether it is a valid user context or not. If it is valid then only the API gateway would dispatch the request to the upstream. From here onward the Edge Level Security has completed.</p><p>But did you know in microservices there is plenty of service-to-service communication? Order service calls Inventory, Inventory calls to either cart or wishlist etc.</p><p>But within this blog I am primarily focused on how the engineers secure above service to service communication from then to now are what are the improvements involved during the architectural changes in microservices governance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6kQPxw-yqQRFkojl" /><figcaption>Abstract Architecture of a Micro services Application</figcaption></figure><p>As a summary the API gateway could enforce coarse-grained access-control policies to the request while inter-service communication, every request needs to have many fine-grained access control policies.To do fine-grained policy enforcement at the service level, there are several policy decision patterns available.</p><ol><li>Network Trust Pattern with TLS</li><li>Network Trust Pattern with MTLS</li><li>Zero Trust Pattern — MTLS + Static JWT</li><li>Zero Trust Pattern — MTLS + Dynamic JWT</li></ol><p>Let me go with one by one.</p><h4><strong>Network Trust Pattern with TLS</strong></h4><p>When the API Gateway receives the request, it terminates the request along with all client connections at the edge level. The request is dispatched to the corresponding upstream microservices if it is validated at the API gateway level. The client context carries out the information about the client application. Also at the edge level the <strong><em>API gateway enables the Transport Layer Security (TLS) to secure the communication channels between the gateway and corresponding microservices</em></strong>. In this pattern, the network grants trust to all upstream microservices. After it dispatches from the API gateway stage, network trust patterns never consider how each service to service request call would validate.</p><p>However, in today’s world, network dynamics based on zero trust are becoming more prevalent. Zero trusts, as the name implies, ensures that <strong><em>microservices never trust the network</em></strong>.</p><h4><strong>Network Trust Pattern with MTLS</strong></h4><p>When compared to the previous pattern, this one is marginally better. Here the request would use MTLS (Mutual TLS) to authenticate the workloads and API gateway. Even if this pattern is superior to the previous pattern, it still has the same problem. Because the HTTP header is used by the API gateway to transfer the end-user context to the upstream microservice. The above header’s i<strong><em>ntegrity is not secured when service to service communication happens</em></strong>.</p><p>Let me take the same E commerce example for here as well. Order microservice is used to transfer the user context from the header at API gateway. Then the order service processes the same header to inventory/cart/wishlist services. Hence there’s no way to guarantee that order microservices don’t change the header, and also there’s no way to check headers when they move from service to service.</p><h4><strong>Zero Trust Pattern — MTLS + Static/Shared JWT</strong></h4><p>When compared to the previous pattern, this one is also a better option. The main difference is that a JSON Web Token (JWT) now includes the user/client context. JWT is a cryptographic method of transferring data between applications. Instead of passing user context in the request header, the API gateway embeds the user context in a JWT of its own. However, Mutual TLS is used to authenticate request workload at both the gateway and service levels. No one can alter the specifics of a JWT after it has been embedded with user context. As a result, the integrity issue is no longer a susceptible concern.</p><p>However, there is a problem with this pattern as well. Both upstream microservices use the same embedded token. To put it another way, the client context would not shift from one service to the next. Therefore JWT ‘s audience is not going to change. Even in service-to-service the required scopes are also different. In this approach the initial JWT token should have to be created with the superior scopes that are consumed by all the services.</p><p>But the services which do not require superior scopes, at the service level the scopes are getting over-provisioned. Because the corresponding microservice is having a set of permissions rather than what it is supposed to have. Also the token Audience is the set of legitimate recipients of microservices of one particular token. Since the same audience is shared across the microservices, a single audience value is accepted by all the microservices in deployment.</p><p>As a summary each microservice inherits the same set of rights since the token is shared. In this policy decision pattern, there is no way to change such rights.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*o43LPyE34OU0OM1P" /></figure><h4><strong>Zero Trust Pattern — MTLS + Shared / Dynamic JWT</strong></h4><p>MTLS + Exchangeable JWT was the most suited approach for service to service. Communication in microservices. As shown in the figure the API gateway sends the request along with the JWT token to the upstream microservice. In this pattern, corresponding microservices never transfer the same JWT as the API gateway, instead calling the JWT token issuer (STS — Security Token Service) and exchanging it for a new JWT with a different audience value. The audience, rights, scopes, payload and functions of the newly generated JWT token can differ from one to the next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/0*uvVygDecsA20qeL5" /></figure><p><strong>This was the initial foundation for the Service Mesh pattern.</strong></p><h4><strong>Service Mesh Architecture</strong></h4><p>Even if Kubernetes API Gateways solved many of the issues in deployments, There was a highlighted gap in the operational logic and managing inter-service communication. As a result, the service mesh architecture was introduced for a fine-grained security control over each micro service. A service mesh is a technique for controlling how various components of an application exchange data. It provides security enforcement, fault injection, health checks, traffic management, routing, as well as circuit breaking and fail-over policies, thus removing the complexity associated with a microservice architecture. In contrast to traditional methods of handling service to service communication, a service mesh integrates a dedicated infrastructure layer straight into a service.</p><p>At the beginning I have mentioned that there were 02 phases of securing microservices, namely edge security and service-to-service security. Service Mesh can be used to secure service to service communication (east-west traffic) while API Gateway is for edge level security (north-south traffic)</p><p><strong>Service Mesh architecture has major 02 approaches.</strong></p><ol><li>In Process Service Mesh Pattern</li><li>Out of Process Service Mesh Pattern</li></ol><h4><strong>In Process Service Mesh Pattern</strong></h4><p>In-process service mesh is a proxy based approach, which is running concurrently with the microservice’s business logic itself . Developers could apply security policies to an associated microservice without having any dedicated security code or layer in the upstream microservice.It behaves as an authorization interceptor attached to the business service.</p><p>However, the primary drawback of this pattern is that once a vulnerability is detected in the proxy code embedded in the application code, it is required to redeploy the whole microservice. The reason for this is that the relevant microservice and proxy are tightly coupled. Therefore both the proxy and the service must be written in the same programming language. To overcome above tight coupling between the proxy and the service, the Out of Process Service Mesh has been discovered by engineers.</p><h4><strong>Out of Process Service Mesh Pattern</strong></h4><p>As an abstract definition, in an Out-of process service mesh pattern, it has decoupled the operation between proxy and business microservice. The proxy works outside the business application’s process. This is the architecture followed by modern service mesh solutions including <a href="https://istio.io/"><strong>Istio</strong></a>, <a href="https://linkerd.io/"><strong>Linkerd</strong></a> and <a href="https://www.consul.io/"><strong>HashiCorp Consul</strong></a>.</p><p>When sending requests to the microservice, the service mesh enforce MTLS validation. The purpose of creating such Out-of service mesh architecture is to accelerate inter-service communication in microservices through API calls and gRCP calls.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*ZQq5NXDuM8jcy1aT" /><figcaption>Examples for modern services meshes</figcaption></figure><p>Above all 03 service mesh solutions use a “sidecar” architecture for the data plane, with a proxy operating in a separate container inside each pod. This sidecar container gets data from the application and delivers it to it. Additionally, it does the heavy work associated with transferring or converting data across pods or to points outside the cluster. Both Istio, Linkerd and Consul provide adequate support for certificate rotation and external root certificates.</p><p>In today’s world the <strong><em>most widely used Service Mesh in Kubernetes is Istio</em></strong>, since it leads the pack in terms of security features.</p><p>In the upcoming chapters will discuss, what is this Istio service mesh, its components and how to install Istio into a namespace in a Kubernetes cluster and how its going to secure service-to-service communcation.</p><p><strong>Reffereces :</strong></p><p><a href="https://www.manning.com/books/microservices-security-in-action">Micorservices Security In Action</a> — by Prabath Siriwardhene <br><a href="https://medium.facilelogin.com/challenges-of-securing-microservices-68b55877d154">Challenges of Securing Microservices</a></p><p>S. Cimpan and V. Couturier, “Can Styles Improve Architectural<br>Pattern Reuse ?,” Seventh Working IEEE/IFIP Conference on Software<br>Architecture (WICSA 2008), 2008, pp. 263–266, doi:<br>10.1109/WICSA.2008.38.</p><p>R. Biswas, X. Lu and D. K. Panda, “Accelerating TensorFlow with<br>Adaptive RDMA-Based gRPC,” 2018 IEEE 25th International Conference on<br>High Performance Computing (HiPC), 2018, pp. 2–11, doi:<br>10.1109/HiPC.2018.00010.</p><p>P. Urien, “A New IoT Trust Model Based on TLS-SE and TLS-IM<br>Secure Elements: A Blockchain Use Case,” 2021 IEEE 18th Annual<br>Consumer Communications &amp; Networking Conference (CCNC), 2021, pp. 1-<br>2, doi: 10.1109/CCNC49032.2021.9369485.</p><p>R. Melton, “Securing a Cloud-Native C2 Architecture Using SSO and<br>JWT,” 2021 IEEE Aerospace Conference (50100), 2021, pp. 1–8, doi:<br>10.1109/AERO50100.2021.9438218.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15315989fb4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create your own federated authenticator for WSO2 Identity Server]]></title>
            <link>https://medium.com/@dckalubowila25132/create-your-own-federated-authenticator-for-wso2-identity-server-698e47eed353?source=rss-e56247d71f09------2</link>
            <guid isPermaLink="false">https://medium.com/p/698e47eed353</guid>
            <category><![CDATA[federated-identity]]></category>
            <category><![CDATA[wso2is]]></category>
            <category><![CDATA[federated-authentication]]></category>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[identity-management]]></category>
            <dc:creator><![CDATA[Dinuwan Kalubowila]]></dc:creator>
            <pubDate>Mon, 08 Aug 2022 08:43:09 GMT</pubDate>
            <atom:updated>2022-08-09T13:37:44.257Z</atom:updated>
            <content:encoded><![CDATA[<h4>An implementation and functional explanation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*E_Vm_DAyWmzt9tPeYdYW6Q.png" /></figure><h4>Pre - Requisites</h4><ul><li><a href="https://is.docs.wso2.com/en/latest/learn/identity-federation/">Basic about Identity federation</a>.</li><li><a href="https://is.docs.wso2.com/en/latest/develop/writing-a-custom-federated-authenticator/">Writing a Custom Federated Authenticator to WSO2 IS.</a></li><li>Hands-ON experience with <a href="https://wso2.com/identity-server/">WSO2 Identity Server</a>.</li></ul><p>Federated authentication is a process of presenting user’s identity with user attributes stored across distinct Identity Providers. Also its kind of an arrangement between two or more trust domains that enables access to apps and services using the same digital identity.</p><p>As an example <a href="https://wso2.com/identity-server/">WSO2 Identty Server</a> allows authenticating client applications with Azure AD. The login user should be Azure AD. Client application registered as a SP in WSO2 Identity Server. Here the user base is from Azure AD and the Service Provider/Client Application is registered in the WSO2 Identity Server.</p><p>Through out of this blog post, I will be assisting you to create a custom OIDC based federated authenticator with WSO2 Identity Server. In future blogs I hope to discuss writing unit test cases, integrating sonar cube with these custom written components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/0*XvOJFHl8vR-AFiMv" /></figure><p>According to the above diagram IS1-SP is going to act as a client application for a IS1-IDP. Then IS1-IDP will act as a client application to IS2-SP.</p><p>Once we create an OAuth2/OIDC SP in WSO2 Idenity Server, the IS will provide consumer key and consumer secret. Also we have to provide a callback URL for SP as well. Then we can add same information even in the side client applicationl. It’s like a property file in the client app. In Google, the Google IdP will provide a JSON file onece we register clent application. As same the IS1-IDP will act as a property file to IS2-SP. But it has more capabilities just than a property file.</p><ul><li>Browser based request redirection.</li><li>Interception of the request as a middleman. (delegate process)</li><li>Claim mappings.</li><li>Id token decoding.</li></ul><p>In generally federated based login flow and logout flow would function as follows:</p><h4><strong><em>Login flow</em></strong></h4><p><em>IS/oauth2/authorize &gt; fidp/oauth2/authorize &gt; IS/commonauth &gt; client app callback</em></p><h4><strong>Logout flow</strong></h4><p><em>IS/oidc/logout &gt; fidp/odic/logout &gt; IS/commonauth &gt; client app callback</em></p><p>Lets discuss above capabilities in depth as follows:</p><h3><strong>Browser based request redirection</strong></h3><p><strong>Authorization Request</strong></p><p>The first redirection will be performed by the authorize request which is supposed to send to the external identity provider. However before sending the the authorize request from this authenticator, the corresponding SP should perform an authorize request through Identity Server’s inbound protocol. It could be either SAML or OIDC.</p><ul><li>If there is a SAML SP configured in IS, inbound authentication should be SAML.</li><li>If there is OAuth2/OIDC SP, inbound authentication should be OAuth2.</li></ul><p>According to the diagram, once the authorize request gets successful from inbound, then inbound protocol allow the control to the IS outbound protocol. Inbound will handle the all the requests getting into the IS while outbound is capable in handling all the request which are flooding out from the IS. You can find the WSO2 documentation which includes the configuration of federated authentication. In this blog my target object is to explain the code level functionality behind such federated authenticator component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/0*_n9ZZY9FApZNvqRs" /></figure><p>As I mentioned before the authorized request will be handled by the federated authenticator, once it receives to the outbound section. initiateAuthenticationRequest method will initiate the authorize request. The implementation of the method as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84da12f4db639eec90834b58006c21c5/href">https://medium.com/media/84da12f4db639eec90834b58006c21c5/href</a></iframe><p>In authorization code grant, the first objective is to obtain an authorization code from an Identity Provider. Here the Identity Provider for the federated authenticator is your External IdP (Google, Yahoo, Facebook, Azure AD etc.)</p><p>As you can sea in the method, first it will load all the property values from the UI. According to the OAuth2 spec, the required parameters for the authorize request is scope, response type and callback URI along with the authorize endpoint.</p><pre>https://&lt;host&gt;:&lt;port&gt;/oauth2/authorize?response_type=code&amp;client_id=&lt;client-ID&gt;&amp;redirect_uri=&lt;callback-url&gt;&amp;scope=&lt;scope&gt;</pre><p>But within the implementation you could sea there is having an additional parameter called state. The state parameter is responsible to corelate the relationship between inbound request and outbound request. In other words once authenticator receives this authorize request, the particular authenticator should have to have a capability to understand where it received.</p><p>Then finally using the Java builder design patent, authenticator will creates the authorize request. And this is a redirection. If you open up your HAR file (browser trace) you could be abel sea the 302 as the request status code. If the authorize request proceeds successfully, then something upto the External IdP. Simply it will load its login page to enter user credentials.</p><p>This is kind of a similar process would happen even in WSO2 Identity Server Inbound authentication section as a local authenticator. If you sends a correct authorize request to the IS from the SP, then IS prompts a login screen to you. But here according to the 1st Figure, the authenticator will act as a SP (IS1-IdP) to the External IdP what ever you are using. Once the user submits user credentials to the External IdP, it will validate those and generate an authorization code. According to the callback URL / Redirect URI configured in External IdP’s SP and authenticator IS will received the authorization code. (In WSO2 Identity Server the callback URI is commonauth endpoint. ) This redirect URI of authenticator and the callback URI of external IdP should exact same. That’s why I have mentioned the authenticator can be act as a property file to the External IdP’s SP.</p><p>As of now the authorization code has been received to the commonauth endpoint as a query parameter. Then again the job is back to the authenticator.</p><p>Now the flow will continue with processAuthenticationResponse method. Lets look at what will happen inside there. Remember this is back-channel process. Because this is time the authenticator is going to get an access token. Since access token is containing someone authority to protected resource it should not be handled via a HAR file. So ths process is not visible in the HAR.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c4dc176f15db7a65f93e68f23c5f887/href">https://medium.com/media/2c4dc176f15db7a65f93e68f23c5f887/href</a></iframe><p><strong>Token Request</strong></p><p>As the very first step, the method will obtain the authorize response from the previous request. If it is a valid the processAuthenticationResponse delegate the controller to the getAccessTokenRequest method. Before diving with getAccessTokenRequest method, it will finish processAuthenticationResponse. As of now getAccessTokenRequest returns a complete authentication request which is suited to send to the token endpoint of external IdP.</p><pre>curl -k --user &quot;$CLIENTID:$CLIENTSECRET&quot; -d &quot;code=$CODE&amp;grant_type=authorization_code&amp;client_id=$CLIENTID&amp;redirect_uri=$REDIRECTURI&quot;https://&lt;host&gt;:&lt;port&gt;/oauth2/token</pre><p>If the authentication request get succeed, the authenticator would receive an access token. If you have passed openid as a scope during the authorize request, you may receive an id token as well. As of now user has authenticated from the external IdP. Next is claim mapping. Even though the method calls are residing in the processAuthenticationResponse method, the implementation of the methods need to done separately. Lets discuss more about claim mapping in the following sections.</p><p>Now will have a look on getAccessTokenRequest According to the token request, the required parameters are authorization code, grant type, client id and redirect URI. Then is should be authorized with client id and client secret of the external IdP’s SP. That is why we should provide client id,client secret of the SP and token endpoint of the external IdP, to the federated authenticator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05ec7dcbe9574eba493f10a7f3066945/href">https://medium.com/media/05ec7dcbe9574eba493f10a7f3066945/href</a></iframe><p>As same in initiateAuthenticationRequest, here also storing the data from properties and creates a request using builder pattern.</p><p><strong>Logout Request</strong></p><p>Once the Identity Server initiated the logout request from the client application side, the inbound section of IS will pass the control to outbound section. That outbound initiated request will be handled by federated authenticator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8348006d4cbd8f70d56579943080a17/href">https://medium.com/media/c8348006d4cbd8f70d56579943080a17/href</a></iframe><p>There are few parameters required here.</p><ul><li>state</li><li>Id_token_hint</li><li>post_logout_redirect_uri</li></ul><p>Why <strong><em>state</em></strong> parameter is necessary? Because it contains the session id of the valid session from federated IdP. Using this state parameter IS can correlated the logout flow. In other words it’s include where this particular request belongs to. (Which service provider, which tenant domain etc.)</p><p>According to the OIDC specification<strong><em> </em></strong><strong><em>id_token_hint</em></strong> is being used to check the validations.</p><p>The <strong><em>id_token_hint </em></strong>contains the user’s authenticated session from external IdP. Within this id_token_hint it contains the client id and callback URL. If the client id of the id_token_hint allow to redirect back to the mentioned callback, then only the user will redirected.</p><p>In WSO2 Identity Server the <strong><em>post_logout_redirect_uri</em></strong> for federated authenticator is always should be the IS commonauth endpoint.</p><p>Basically in this method, the federated authenticator used above parameters through a HashMap and put in to the logout request. Then finally the created logout request will execute in the browser. Once t get succeeded, the browser redirected the IS to the commonauth endpoint with the same state parameter which has used to create the logout request on initiateLogoutRequest method. If the commnauth has that exact same state parameter value, then only IS could understand where the request was originated from and where it should belongs to. Hope you may get clear on that point.</p><p>However let’s discuss how these flow are geting triggered exactly with a explanation of a HAR file and sequence diagram in the next article. Because the primitive objective of this article is to get an understadng about the code base.</p><h4><strong>Retrieving user data from either id token or user info endpoint</strong></h4><p>According to the code snippets as you could sea it is going to execute 02 distinct flows get user attributes, based on either id token or access token. jsonClaimMap is the responsible variable to store those user data. Remember as I mentioned before this logic is completely inside in the processAuthenticationResponse function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76859ae1c0a30fee77690e1d46d94c3a/href">https://medium.com/media/76859ae1c0a30fee77690e1d46d94c3a/href</a></iframe><p>Now let’s look at what is actually happens within getUserInfoUserAttributes and getIdTokenClaims methods.</p><p><strong>getIdTokenClaims</strong></p><p>Simply this is the method which decodes the id token and fetch it’s clams into a JSON literal object. Since the Authentication context is getting passed there, this method can simply split and and select the id token’s payload.</p><p><strong>getUserInfoAttributes</strong></p><p>This method is defined to send a GET API request to user info endpoint of the external Identity Provider. Within this method it will call the sendUserInfoRequest function while passing the authentication context and the access token as a string. As same as idTokenClaims method, this method will also call the buildJSON. As method to retrieve the user attributes as a Java Map object.</p><h4><strong>Claim Mappings</strong></h4><p>Let me start just from a simple question. Why claim mapping is a vital role in a federated flow ? As of the answer, there might be different claims from the external IdP side rather than WSO2 Identity Server. In federated authentication always the user authenticated from an External Identity Provider. When authenticating the user these claims should exactly be mapped with Identity Server’s claims wherever relevant. As a standard, according to the OIDC specification OIDC authenticator always pointed to the OIDC claim dialect for the claim mapping. Therefore from the Identity Server’s side if you have introduced a new local claim there, same time you have to add that claim into OIDC claim dialect as well. That is why even this implementation also includes a constant variable to store OIDC claim dialect is there.</p><p>From where we have stopped at last explanation, the jsonClaimMap have attribute. Now there is having 02 methods called getAuthenticatedUserId and getMultiAttributeSeparator</p><p>Now lets have a look at on those 02 methods.</p><p><strong>getAutenticatedUserId</strong></p><p>According to the OIDC specification, the <strong>sub</strong> claim is referred as a unique identifier. Even here also from the JSON literal object the method itself fetch the user’s unique identifier using this <strong>sub</strong> claim.</p><pre>authenticatedUserId = (String) userClaims.get(CustomAuthenticatorConstants.<em>SUB</em>);</pre><p><strong>getMultiAttributeSeperator</strong></p><p>Using this method, it allows the authenticator to separate json attributes from suitable character.</p><p>Finally the processAuthenticationResponse ended after adding the authenticated user object into active authentication context. In addition to above methods there are couple of common methods to get authenticators unique name,display name,load property fields etc. All of these requests will be checked by the canHandle method and itself evaluates weather the authenticator has an ability to handle particular request or not.</p><p>Get the source code from <a href="https://github.com/DInuwan97/wso2-is-custom-components/tree/master/components/federated-authenticator-oidc">GitHub</a></p><p>Let’s get a quick pause, and see you soon in the next chapter !!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*LPNd8R9TUZ8YEIxxhhwkig.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=698e47eed353" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proof Key for Code Exchange (PKCE) in OAuth2 Authorization Code Grant]]></title>
            <link>https://medium.com/@dckalubowila25132/proof-key-for-code-exchange-pkce-in-oauth2-authorization-code-grant-8b36d7e11d61?source=rss-e56247d71f09------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b36d7e11d61</guid>
            <category><![CDATA[oauth]]></category>
            <category><![CDATA[wso2is]]></category>
            <category><![CDATA[pkce]]></category>
            <category><![CDATA[identity]]></category>
            <category><![CDATA[authorization-code]]></category>
            <dc:creator><![CDATA[Dinuwan Kalubowila]]></dc:creator>
            <pubDate>Tue, 12 Apr 2022 13:55:42 GMT</pubDate>
            <atom:updated>2022-04-12T14:03:16.190Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*SGQcB1Nsc9f08p4lwoQo8w.png" /></figure><h4><strong>This article was intended to provide an overview of PKCE, how it integrates with OAuth, the importance of PKCE, and a simple demo of PKCE using WSO2 Identity Server.</strong></h4><h4><strong>Pre Requisites:</strong></h4><p>Basic understanding on OAuth principles and OAuth grant types</p><p><strong>First of all, I would like to mention that PKCE is available only for the Authorization Code Grant.</strong></p><p>PKCE is an acronym for Proof Key for Code Exchange. It is a technique that was created specifically to increase the security of the OAuth 2.0 Authorization Code grant in exceptional cases. The next thing pops up into your mind is: What are those exceptional cases?</p><p>Whenever the Authorization code grant is used, the client application should have to store client ID and the client secret of Service Providers. Either property file or at least as a JSON object it should have to save within your client application. So is it a trustworthy appraoch? It’s OK since your client app is a web application. BUt what happens if your client application is a mobile application? Can you trust mobile applications 100%? But in the mobile world, those client id and client secrets are open to any application running in the same mobile phone. If you owned the mobile phone and if you have root access then you can do anything.That’s why mobile applications are always known as untrusted clients. Therefore PKCE is most targeted on mobile native apps, which are called untrusted clients. Also SPA can be considered as untrusted as well. If want to get more information about OAuth clients, follow <a href="https://is.docs.wso2.com/en/latest/learn/oauth-2.0-clients/">here</a>.</p><h4><strong>How does PKCE work?</strong></h4><p>As an example, just think if you want to integrate Google/Microsoft login within your mobile app, then you need to spin up the system browser using your mobile app.Simply once you click the option called sign in with google, then the mobile browser enabled web view may open. Neither Google nor Azure AD prompt login page naively designed for mobile apps.</p><ul><li><em>After a successful authentication, the browser sends an authorization code to the callback URL.</em></li><li><em>Once the authorization code is received, the mobile operating system knows how to pass that code to the native mobile application from the browser view.</em></li><li><em>To do this the native application should register an URL scheme with mobile OS against the application.</em></li><li><em>Once the authorization code is received, the mobile OS checks the browser’s URL scheme with the registered scheme in the OS.</em></li><li><em>Once matched, then the OS will pass it into the corresponding native application.</em></li></ul><p><strong>But the problem is more than one application can be registered with the same URL scheme. If there is a malicious application in your mobile phone, then it may also receive that code.</strong></p><p>Even Though malicious app gets the authorization code, you may think a malicious app needs to have a client and a secret. Other-vice it couldn’t get the access token. As I said before, those Client ID s and client secrets can be shared across multiple applications running on your mobile. <strong>But in PKCE the above case would not happen.</strong></p><p>The basic idea behind PKCE is proof of possession. The client app should give proof to the authorization server that the authz code belongs to the client app in order for the authorization server to issue an access token for the client app.</p><p>Therefore PKCE had to introduce some additional parameters like <strong>code_verifier, code_challenge, code_challenge_method</strong>to the authorization code flow.</p><h4><strong>code_verifier</strong></h4><p>The <strong>code_verifier </strong>should be a cryptographically generated random string. Its limitations are as follows.</p><ul><li>Minimum length : 43 characters</li><li>Maximum length : 128 characters</li><li>Allowed alphanumeric characters : <strong>A-Z,a-z,0-9</strong></li><li>Allowed other characters<strong> : </strong><strong>tilde(~),hyphen(-),period(.),underscore(_)</strong></li></ul><h4><strong>code_challange</strong></h4><p>base64 URL encoded string of the <strong>code_verifier </strong>using <strong>S256</strong> algorithm.Not just base64.</p><p>If you’re having an integrated client application, in the sense you can use this method whatever is suited with any programming language.</p><pre><strong>Base64UrlEncode(SHA256Hash(code_verifier))</strong></pre><p>If you are just testing this PKCE and if there is no way to get back such base64 URL encoded string programmatic ally, then use online encoding tools.But there are no base64 URI encoders. But there are base64 encoders. Therefore you need to adjust the following changes from base64 to base64URLencoded.</p><ul><li><strong><em>+</em></strong><em> to </em><strong><em>-</em></strong></li><li><em>Ignore and remove </em><em>&#39;=&#39;</em></li><li><em>Replace </em><em>&#39;</em><strong><em>/</em></strong><em>’ with </em><em>&#39;</em><strong><em>_</em></strong><em>&#39;</em></li></ul><h4><strong>code_challange_method</strong></h4><p>This is an optional parameter. The available values are S256“ and “plain”. By default it is set to &quot;<strong>plain</strong>”. If you are using plain, then <strong>code_challenge </strong>is exactly the same value as <strong>code_verifier</strong>.</p><h4><strong>The flow of PKCE</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vgron8UvFkTmfOXO" /></figure><h4><strong>According to the above diagram the steps as follows:</strong></h4><ol><li>The legitimate application will initiate the request and at the same time legitimate application may create code verifier and the code challenge.(Let’s discuss further about this Code challenge and code verifier in the following sections)</li><li>Then authorization requests will be sent to the authorization server along with the above created code challenge.</li><li>The authorization server will return the Authorization code to the browser’s callback URL.</li><li>Now authorization code will go to the both Legitimate and Malicious apps. (because of same URL scheme is having for both apps)</li><li>In order to get the access token the client application should pass the code verifier along with the received authorization code (authorization code grant). <strong>But malicious apps don’t have that verifier.</strong></li></ol><h4><strong>How to use PKCE in WSO2 Identity Server?</strong></h4><p>In order to follow this section you need to have some hands on experience with WSO2 Identity Server. Because I am not going to explain the entire flow of creating a Service Provider (SP) in WSO2 IS, hence its not much relevant to the final objective of this article. However you can find a lot more information on WSO2 IS from the <strong>O</strong><a href="https://is.docs.wso2.com/en/latest/"><strong>fficial documentation of WSO2 Identity Server</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KVspTP8P1S3IyK9G" /></figure><p>In the OAuth2 SP configuration there are 02 selection options related to PKCE. If you enable <strong>PKCE Mandatory</strong>, then the corresponding SP should definitely obtain the access token via PKCE enable flow. Even Though the <strong>code_challange_method</strong> parameter is opttional(According to the PKCE specification) in <strong>Support PKCE ‘Plain’ Transform Algorithm, </strong>in<strong> </strong>WSO2 IS, by default, enables code_challange_method as <strong>‘plain’</strong>.</p><p>However in Azure AD B2C performs this PKCE flow by default. Wherever it uses the Authorization Grant, then it will use the PKCE flow itself.</p><h4><strong>Steps to follow:</strong></h4><p>First you have to create<strong> code_verifier</strong> and convert it using base64 URL format and save encoded one as <strong>code_challange</strong> as I mentioned in above instructions.</p><p>Now you need to export your OAuth SP’s client ID,client secret,redirect URL,user account credentials, authorize and token endpoints of the WSO2 IS. (to have more readable CURL commands.)</p><p>Export those values to variables as follows. (If you are in Windows OS, download WSL and try this or you can use POSTMAN as well)</p><pre><strong>export TOKEN_EP=https://localhost:9443/oauth2/token<br>export AUTHZ_EP=https://localhost:9443/oauth2/authorize<br>export CLIENTID=sSYkKSPk3KdF5azgfqBUcZNNpSga<br>export CLIENTSECRET=NTgch95e0KGqA1a8DqdqShEdcv4a<br>export USERNAME=admin<br>export PASSWORD=admin<br>export SCOPE=openid<br>export REDIRECTURI=http://127.0.0.1:5000/<br>export CODE_CHALLANGE=_YIAvfU2J2CZXjvV2ksYkvvXMZKskBEAjp5po37KKgQ<br>export CODE_VERIFIER=hdcbbxygd39fajdfdh45dvs37sjdgdskbslkdguskm4sdfcvvcgsffg355ddgdf2</strong></pre><p>Execute the following command to get an authorized request.</p><pre><strong>echo &quot;$AUTHZ_EP?client_id=$CLIENTID&amp;scope=$SCOPE&amp;redirect_uri=$REDIRECTURI&amp;response_type=code&amp;code_challenge=$CODE_CHALLANGE&amp;code_challenge_method=S256&quot;</strong></pre><p>Now you may get an output as follows. Once you click this authorize request, your browser will open and ask user credentials.</p><pre><strong>https://localhost:9443/oauth2/authorize?client_id=sSYkKSPk3KdF5azgfqBUcZNNpSga&amp;scope=openid&amp;redirect_uri=http://127.0.0.1:5000/&amp;response_type=code&amp;code_challenge=_YIAvfU2J2CZXjvV2ksYkvvXMZKskBEAjp5po37KKgQ&amp;code_challenge_method=plain</strong></pre><p>After a successful authentication, you may receive the authorization code as a query parameter attached to the given redirect URL as the 302 response. So copy the authorization code and export it as follows.</p><pre><strong>http://127.0.0.1:5000/?code=d6e3fde6-dcaa-3c9d-b54b-ddc8143cec9e&amp;session_state=bc741348de88deaa7a5ec7543cfa09b5ec573e76862e124be3219d00dfdaaab7.na5tvF_jwws4CIJ3P39dYQ</strong></pre><p>Then execute the following CURL command to obtain an access token.</p><pre><strong>curl -k --user &quot;$CLIENTID:$CLIENTSECRET&quot; -d &quot;code=$CODE&amp;grant_type=authorization_code&amp;client_id=$CLIENTID&amp;redirect_uri=$REDIRECTURI&amp;code_verifier=$CODE_VERIFIER&quot; $TOKEN_EP</strong></pre><p>Finally you can obtain an access token as follows.</p><pre><strong>{“access_token&quot;:&quot;c170b49b-67e1-4efb-ab93-5aff09799a84&quot;,&quot;scope&quot;:&quot;openid&quot;,&quot;id_token&quot;:&quot;eyJ4NXQiOiJOVGRtWmpNNFpEazNOalkwWXpjNU1tWm1PRGd3TVRFM01XWXdOREU1TVdSbFpEZzROemM0WkEiLCJraWQiOiJNell4TW1Ga09HWXdNV0kwWldObU5EY3hOR1l3WW1NNFpUQTNNV0kyTkRBelpHUXpOR00wWkdSbE5qSmtPREZrWkRSaU9URmtNV0ZoTXpVMlpHVmxOZ19SUzI1NiIsImFsZyI6IlJTMjU2In0.eyJhdF9oYXNoIjoiSGhIVTFwOHlFUDVoWXIzcnBxUmdQQSIsImF1ZCI6InNTWWtLU1BrM0tkRjVhemdmcUJVY1pOTnBTZ2EiLCJjX2hhc2giOiJNNGVpZThJQ2NhQ1pxdDFrU3ZvbDlBIiwic3ViIjoiYWRtaW4iLCJuYmYiOjE2NDk2OTU4OTMsImF6cCI6InNTWWtLU1BrM0tkRjVhemdmcUJVY1pOTnBTZ2EiLCJhbXIiOlsiQmFzaWNBdXRoZW50aWNhdG9yIl0sImlzcyI6Imh0dHBzOlwvXC9sb2NhbGhvc3Q6OTQ0M1wvb2F1dGgyXC90b2tlbiIsImV4cCI6MTY0OTY5OTQ5MywiaWF0IjoxNjQ5Njk1ODkzfQ.RNS5lI3JCTt1QJZ3zgxIeqbs2mlmobhfbBMGOZ5fnwZ9UzEpkZkBeKUgtrBbIbj4VgZbrrQkCp3frcWAB7ULfOWrixfXwFQvwunhb6m5jz9b_T14yFUnnJ_nukQ23Cy9IlSbZG0DvjLUaD3RwXJ8Utb16WHapih2D4mNzBO4KY-g3MMBRe2eqiRR0uHSmzcc50NGYp3OO3U6_S2ytlAFAKHaGKObOWvCTJx55rqrj125x9Y3JTVxMIt64Ugxls3OynKxBC46JUBZRPCnHuahv2iXszdTTh4PMPye0ysriCAGSp0SfkQDWJ8IUzc_at4R5P46rpT-ntOJCmvWgSY1Cg&quot;,&quot;token_type&quot;:&quot;Bearer&quot;,&quot;expires_in&quot;:3499</strong></pre><p>Even Though PKCE flow is limited to authorization code grants, it is returning a refresh token. It never means that PKCE flow supports the refresh token grant. For the first time only it will issue a refresh token for a particular access token. Here there is no Authorization part. But in order to get another refresh token you need to send client id and secret as basic auth. Refer to the <a href="https://datatracker.ietf.org/doc/html/rfc6749"><strong>OAuth2 specification</strong></a><strong>.</strong></p><p>However you can obtain an access token just by enabling <strong>Allow authentication without the client secret </strong>option and without sending client secret in basic auth. Because it’s from an authorization code grant.</p><p>For more details on PCKE follow the <a href="https://datatracker.ietf.org/doc/html/rfc7636"><strong>PKCE Specification</strong></a>.</p><p>Hope this article makes some sense to your knowledge on PKCE flow. :blush:</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b36d7e11d61" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IdP initiated SSO and SP Initiated SSO with SAML]]></title>
            <link>https://medium.com/@dckalubowila25132/idp-initiated-sso-and-sp-initiated-sso-with-saml-4c4456b2ee34?source=rss-e56247d71f09------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c4456b2ee34</guid>
            <category><![CDATA[wso2is]]></category>
            <category><![CDATA[saml2-sso]]></category>
            <category><![CDATA[wso2]]></category>
            <category><![CDATA[identity-management]]></category>
            <category><![CDATA[identity-and-access]]></category>
            <dc:creator><![CDATA[Dinuwan Kalubowila]]></dc:creator>
            <pubDate>Sun, 19 Dec 2021 16:07:09 GMT</pubDate>
            <atom:updated>2022-01-09T10:33:44.631Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*3tsHaJ7jK_Q2yiRZR7o8Pg.png" /></figure><p><strong>Today I am going to talk about SAML based SSO. If you are not much familiar with IAM concepts, the first thing that pops into your mind is SAML. Is it really XML? Yes you are right. In a nutshell SAML is sharing user identity related data.</strong></p><p>The SAML acronym belongs to the <strong><em>Security Assertion Markup Language </em></strong>which is a XML based markup language for sharing security assertions. It is also an open standard of exchanging authentication and authorization between trusted parties. SAML is mainly Used to implement federated authentication and SSO. If you are not familiar with SSO, read the article <a href="https://medium.com/microsoft-student-champs-sri-lanka/single-sign-on-sso-capabilities-with-identity-providers-786c8ec83d52">linked here</a>. In the upcoming blogs I’ll dive into federated authentication. The following figure shows how SSO is going to work with the IdP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*m-2OTTUAOFC2X9dKx69rtw.png" /></figure><p>Oops!!! What are Open-Standards there? Even if there is only an IdP, there are some issues that arise in Single-Sign-On.</p><p>When installing a new application into the organization domain and toward the IdP, developers should consider communication protocols on both the IdP side and the application side. As a result, some Open-Standard protocols have been introduced. The common Open-Standards are as follows.</p><ol><li><strong>OIDC (Open ID Connect)</strong></li><li><strong>SAML</strong></li><li><strong>WS-Federation</strong></li></ol><p>The latest version of SAML is SAML 2.0. It has 03 participants.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*-_IADvJoCzJvAWSrZbSVMw.png" /></figure><blockquote><strong>Subject / Principal — </strong>The user who is having an account in Identity Provider and the person who is trying to access Service Provider application.</blockquote><blockquote><strong>Service Provider / Relying Party / Client Application — </strong>Web or a Mobile Application which can be accessible for the end user. The same particular service provider should be registered at the Identity Provider as well. Prior to sharing security information, there should be a trust relationship established between the Service Provider and Identity Provider. The trust relationship is based on public key cryptography.</blockquote><blockquote><strong>Identity Provider / Asserting Party — </strong>Manage the user accounts and responsible for handing the user’s authenticity.</blockquote><h4><strong>There are 03 different types of SAML Assertion</strong></h4><h4><strong>Authentication Assertions</strong></h4><ul><li>Identify the user.</li><li>Provide the time that user have logged in</li><li>State the Authentication type that has been used</li></ul><h4><strong>Attribute Assertions</strong></h4><ul><li>User’s information (username,email,mobile etc.)</li></ul><h4><strong><em>Authorization Assertions</em></strong></h4><ul><li>Decide if the user is authorized for the service or if IdP denies the request due to lack of rights to the service.</li></ul><p>Hope you all got a little understanding about what SAML is and where it is used.</p><h4>In the message flow of SAML based SSO, we can divide into two sections</h4><ol><li><strong>SP (Service Provider) initiated SAML SSO</strong></li><li><strong>IdP (Identity Provider) initiated SAML SSO</strong></li></ol><p>WSO2 Identity Server and AAD (Azure Active Directory) support both IdP initiated flow and SP initiated flows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*JKlQUMVNBzkigksEcQGTzA.png" /><figcaption><strong>SP (Service Provider) initiated SAML SSO</strong></figcaption></figure><ol><li><em>End users access the service provider through the browser.</em></li><li><em>By itself the service provider generates an Authentication request to the IDP by requesting the identity information. This is a </em><strong><em>SAML request</em></strong><em>, which contains the Service Provider’s information and </em><strong><em>SAML Request</em></strong><em> is expecting to collect some additional information from the Service Provider.</em></li><li><em>IDP validates the received request and prompts a login screen for the end user to enter credentials. Once a user enters those IDP will validate the entered credentials against the user stored credentials.</em></li><li><em>After successful authentication is done, IDP creates a session and generates a </em><strong><em>SAML Response</em></strong><em> (SAML Assertion) and passes it back to the service provider. This SAML message contains the name of the authenticated user and requested attributes if any.</em></li></ol><p><strong>In order to ensure the integrity of the SAML message, before sending it back to the Service Provider, IDP signs it with IDP’ s private key. Then the received response can be validated by the Service Provider using the IDP’ s public key. Since the response message contains sensitive data, it can be encrypted.Or else can be kept as it is.</strong></p><p><strong>AWS console supports the IdP initiated SAML SSO while Google apps supports over the SP initiated SAML SSO. However, Salesforce supports both SP initiated flow and IdP initiated flow.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*qP7Y3FeaskERuFxZMx1WbQ.png" /><figcaption><strong>IdP (Identity Provider) initiated SAML SSO</strong></figcaption></figure><p><strong>One of the most important facts in IdP initiated SAML SSO is there is no longer having a SAML request there. Just only a SAML Response.</strong></p><ol><li><em>End users access the IdP through the web browser.</em></li><li><em>IDP validates the received request and prompts a login screen for the end user to enter credentials. Once a user enters those IDP will validate the entered credentials against the user stored credentials.</em></li><li><em>If user credentials are valid IdP redirect a SAML response toward the SP.</em></li></ol><p><strong>Again, if you look at in both two diagrams, in SP initiated SAML SSO, there is a SAML request. But there was no SAML request in the IdP initiated SAML SSO.</strong></p><p>How can users select one over the other? It depends on the Service Provider and the IdP that you are using. However, most of the time SaaS applications encourage the use of IdP flow. The reason for that is that within a minimal number of steps, the minimal effort authentication process is going to be completed.</p><blockquote><strong>Note — — — — — — — — — — — — — — — — — — — — — — — — — — — -</strong></blockquote><blockquote><strong>Salesforce is a SaaS (Software as a Service) product which has multiple user tenants. Once a user logged into the Salesforce, a couple of years ago the way that Salesforce identified the logged user tenant by identifying credentials. Each user tenant has separate IdP s as well. As an example WSO2 Salesforce tenant may have their IdP as WSO2 Identity Server.Microsoft’ s Salesforce account may have their IdP as Azure AD.</strong></blockquote><blockquote><strong>In such a case, if a multi-tenant SaaS app uses IdP initiated flow, there is no correct way to identify the corresponding tenant. How salesforce was doing that, just after getting credentials, get back with the user store and identify the user tenant and redirect the authentication SAML request to the IdP.</strong></blockquote><blockquote><strong>However around 2013–2104 Salesforce introduced a feature called MyDomain. SImply a subdomain feature for each user tanant. Unlike previously, salesforce can identify the particular user tenant just looking at the URL despite having user credentials. After introducing the MyDomain feature, Salesforce supports IdP initiated SAML SSO as well. If you want to learn more about the Salesforce MyDomain feature </strong><a href="https://help.salesforce.com/s/articleView?id=sf.faq_domain_name_what.htm&amp;type=5"><strong>click here</strong></a><strong>.</strong></blockquote><h4><strong>Following part shows how SP initiated SSO with WSO2 Identity Server.</strong></h4><p><strong><em>Pre requirements</em></strong></p><ul><li><a href="https://wso2.com/identity-server/"><em>Download WSO2 Identity Server,Install and run it</em></a></li><li><a href="https://tomcat.apache.org/download-90.cgi"><em>Download Tomcat9 Server,Install and run it</em></a></li><li><a href="http://tomcat.apache.org/download-90.cgi"><em>Download sample application (Pickup dispatch &amp; Pickup Manager)</em></a></li><li><em>Enable SAML Tracer extension in your browser</em></li></ul><p><strong>Moreover you can go through the following documentation, if you are struggling to configure the above resources.</strong></p><ul><li><a href="https://www.geeksforgeeks.org/how-to-install-apache-tomcat-8-on-linux/">Install</a> and <a href="https://www.webucator.com/article/how-to-start-and-stop-apache-tomcat-fro-bqljrrpgev/">run</a> Tomcat</li><li><a href="https://is.docs.wso2.com/en/latest/learn/deploying-the-sample-app/#deploying-the-saml2-web-app-pickup-dispatch-webapp">Configure samples</a></li></ul><p>Once you configured successfully, this is how you will get.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*T0B3bQh7DzV1zdFVPnENPg.png" /></figure><p><strong>The following diagram shows how SP initiated SAML flow is going to work on your demonstration. This is something that I have included in an abstract way in the 1st diagram but specifically a use case oriented.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*56tW25JooUd2dSLqIkGMjg.png" /></figure><p>“Index.jsp” page initial front view that you may get on behalf of a service provider for the very first time. Once the user clicks the login option, a <strong>SAML request</strong> is going to trigger. Service Provider redirects to the IdP. Carefully look at how your URL is now. Obviously it is not from the Service Provider’s domain. It is entirely on the IdP host domain. There are some alternative terminologies to redirect this SAML request from Service Providers domain. Their URL’s domain will not be changed. IdP s login screen will pass via a query string attached with the same service provider’s domain.</p><p>I have already discussed this redirection mechanism, at the end of my <a href="https://medium.com/@dckalubowila25132/single-sign-on-sso-capabilities-with-identity-providers-786c8ec83d52"><strong><em>Single-Sign-On (SSO) capabilities with Identity Providers</em></strong></a><strong><em> article</em></strong></p><p>Once a user provides the valid crdentials, the IdP redirects to the<strong> <em>Default Assertion Consumer URL. </em></strong>In this example as you may see, the consumer URL is home.jsp page.This is the point where the <strong>SAML Response</strong> occurred.</p><p><strong>This is a SAML tracer extension. Just open this extension and keep a side before you click the Login button on the Service Provider. Once you click the login you may be able to see the SAML request, you may able to sea the SAML Request as follows,</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c4bb404443e4de37c801ea29fb8c412/href">https://medium.com/media/4c4bb404443e4de37c801ea29fb8c412/href</a></iframe><p>Once you provide valid credentials, SAML Response seems like below. Unlike in SAML Request, in the Response it includes the logged user’s name (<em>line 90</em>) and other requested attributes as well.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d213c9fba15ed99be0343433cd093ba8/href">https://medium.com/media/d213c9fba15ed99be0343433cd093ba8/href</a></iframe><p>So hope you have learned something new. Let’s catch up in the very next episode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*0NQ9gj-mPTTd6dIJtkBuVg.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c4456b2ee34" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Single-Sign-On (SSO) capabilities with Identity Providers]]></title>
            <link>https://medium.com/microsoft-student-champs-sri-lanka/single-sign-on-sso-capabilities-with-identity-providers-786c8ec83d52?source=rss-e56247d71f09------2</link>
            <guid isPermaLink="false">https://medium.com/p/786c8ec83d52</guid>
            <category><![CDATA[wso2-identity-server]]></category>
            <category><![CDATA[wso2is]]></category>
            <category><![CDATA[azure-active-directory]]></category>
            <category><![CDATA[single-sign-on]]></category>
            <category><![CDATA[identity-management]]></category>
            <dc:creator><![CDATA[Dinuwan Kalubowila]]></dc:creator>
            <pubDate>Tue, 07 Dec 2021 04:46:09 GMT</pubDate>
            <atom:updated>2021-12-07T04:46:09.068Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*uNNW-SGqWnz9tuk8HjuSKA.png" /></figure><h4>Exclusive for the folks having enthusiasm in Identity Access Management</h4><p>Is there anyone fresh into the IAM domain, there are some crucial concepts to learn. Even if in a very abstract approach anyone can define simply IAM as just user management, login, and registration. Yes, it’s true. However, as long as you are working in this domain you should have to have a better understanding of IAM. Therefore the following blog is exclusive for absolute beginners of this domain.</p><h4>“<em>Identity and access management (IAM) is a framework of business processes, policies, and technologies that facilitates the management of digital identities.</em><strong>” — </strong><a href="https://www.techtarget.com/searchsecurity/definition/identity-access-management-IAM-system#:~:text=Identity%20and%20access%20management%20(IAM,critical%20information%20within%20their%20organizations."><strong>TechTarget</strong></a></h4><p>In the IAM domain, there are some common terms like “Authentication”, “Authorization”, “Access Control”, “Authorization Server”, “Identity Provider” and “Single-SIgn-On” etc. As an IAM Developer, you should have a better idea regarding the above terms. Let me describe them one by one as follows.</p><h4><strong>Authentication</strong></h4><p>Who is the current user and in other words the identity of the current user? Checks whether the given user credentials are validated or not. In contrast, Authentication checks the validity of the user as the user said.</p><h4><strong>Authorization</strong></h4><p>Authorization is going to happen after successful authentication. What the user can do / what is the access level that the user has within the application. It always evaluates the right user having the right access to a certain resource in the right period of time. In more contrast, authorization means granting permission to do something.</p><p>But there is a common misunderstanding still, <strong><em>Access Control term does not mean exactly about Authorization.</em></strong></p><h4>Access Control</h4><p>Control or add some constraints to access certain entities towards the protected resources. There are a lot of types of Access Control. Mandatory Access Control (MAC), Discretionary Access Control(DAC), Role-Based Access Control (RBAC), and Attribute-Based Access Control (ABAC). Same as above we can divide Access Control into another aspect called Fine-Grained and Coarse Grained. I hope to discuss more Access Control in my upcoming blogs.</p><h4>Identity Provider</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*_-n_muM4eMZeIWOrjMqfcg.png" /><figcaption>An overview of Identity Provider</figcaption></figure><p>Simply a kind of database that stores users’ identities. But this is just not only a database.<strong> </strong>Identity Provider (IdP) creates centralized governance to handle Access Control access to various business applications both internally and externally. Using an IdP, developers can reduce the cost of development and maintenance overhead due to user management. In summary, an IdP can provide user registration, user login, password reset options, Two-Factor/Multi-Factor verification, Adaptive Authentication, Federated Authentication Account disabling features, and many more. So developers no need to worry about implementing the above features inside of the business applications. The only thing that they have to do is, just invoke the IdP functionalities inside the application. The rest will be taken care of by the IdP.</p><h4>Why IdP?</h4><p>Businesses and their information technology teams face greater regulatory and organizational demand to secure access to business resources. As a result, they are no longer able to assign and track user credentials using manual and error-prone processes.</p><p>Considering history one of the most popular Identity providers has been Microsoft Active Directory. It was introduced in 1999. It was running on On-Premises and specifically designed to manage windows usernames and passwords. Subsequently, it connected with the other windows resources. However, with the enhancement of Cloud Computing, the modern enterprise has been moved into the virtual hosted infrastructure. Therefore traditional IdP s like Microsoft Active Directory were struggling to keep continuing.</p><h4>WSO2 Identity Server</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*Y-84iEpQvZa8DsznkboXCA.png" /><figcaption>An overview of WSO2 Identity Server</figcaption></figure><p>WSO2 introduced their IdP as WSO2 Identity Server. It provides enterprise-grade features such as identity federation, single sign-on (SSO), robust and adaptive authentication, account management, and identity provisioning to assist digital-native enterprises in becoming integration agile via API security. It can deploy On-Premises, Public/Private Cloud governance, bare-metal hardware, virtual machines, and containerized environments.</p><h4>Identity as a Service (IDaaS) IdP s</h4><p>In late 2014, the JumpCloud CEO announced the invention of the world’s first-ever Directory as a Solution. (DaaS) It was a SaaS-based offering. Using DaaS organizations were able to transform their IT services from On-Prem servers to Cloud. A core tenant of DaaS is that it is the single, <a href="https://jumpcloud.com/"><em>secure directory store</em></a> for an organization. Later Microsoft launched an extended version of Microsoft Active DIrectory called <strong>Azure Active Directory (AAD)</strong> based on Azure Cloud Platform and it is an IDaaS (Identity as a Service) solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*YZtMjETF-7ZP4hrXMFtvnQ.png" /></figure><p>The term “Identity-as-a-Service,” or IDaaS, refers to a broad range of cloud-based IAM services. Essentially, IDaaS is a group of cloud-hosted technical operations that deal with the user identity. Providers of identity as a service (IDaaS) assist guarantee that users are who they claim to be, preventing cyber thieves and other unauthorized users from accessing critical data. Well, the next question that pops up in your mind is how an IDaaS solution is going to provide the identity as a service?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*NAsh7VWHmIyLt2zcoPpeXw.png" /></figure><p>Just a simple answer. The IDaaS solution will operate as tenants in the public cloud. Recently WSO2 has announced their IdaaS solution as <strong>Asgardeo. WSO2 Identity Server</strong> is utilized by several businesses worldwide, including Fortune 500 companies. <strong>Asgardeo </strong>combines these experiences and capabilities into a modernized, cloud-native, developer-focused Identity as a Service (IDaaS) environment, enabling users to take advantage of the cloud’s benefits.</p><h4>Single-Sign-On (SSO)</h4><p>SSO enables users to sign in to many applications using a single account rather than maintaining a separate login for each application. It couldn’t be possible unless having an IdP configured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*m-2OTTUAOFC2X9dKx69rtw.png" /><figcaption>Accessing multiple applications using SSO</figcaption></figure><h4><strong>Need of SSO</strong></h4><p>SSO can minimize the cost of login each application again and again. Hence it can enhance the end-user experience as well. Modern enterprises couldn&#39;t limit their business to just within one or two applications. Those consumer applications should be connected one to another. THerefore without SSO, there is no centralized governance in authentication to a series of applications in the same domain. Also using an IdD, developers can shift Identity as a layer on top of the consumer application.</p><p>Once a user has logged into the HR application via a web browser, the HR application delegates the authentication control to the IdP. Because there is a mutual trust between IdP and consumer application. (HR) According to the implementation either IdP can send consent screens to the browser or IdP can redirect HR applications to the browser by asking for the user credentials.</p><p>As we discussed earlier, there should be mutual trust between IdP and Service Provider. (Business Application or HR) I will use the HR term here onwards for the Service Provider. The dotted line shows that pre-defined trust.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*9H4m5svJ-JIpOpKGniZ8xg.png" /></figure><p>First will take a look at 1st diagram. (IdP provides a login screen) Note this is neither IdP initiated flow norSP initiated flow. <a href="https://www.youtube.com/watch?v=tCNcG1lcCHY"><em>Click here for more info</em></a></p><ol><li>Browsers access the HR application directly.</li><li>2. HR application delegates the authentication request to the IdP.</li></ol><p>3. Once an authentication request is received to the IdP, the IdP sends login consent to the browser.</p><p>4. User provides the credentials to the consent screen.</p><p>5. IdP validates the credentials and if valid, sends a successful authentication response to the browser. (Browser will save the response as a cookie)</p><p>6. For future logins, Sales and Finance applications do not ask to login again and again since the above cookie is there.</p><p><strong><em>Note: IN the 5 the step of 1st diagram and the 3rd step of the 2nd diagram, once the browser received the valid session from IdP browser again create another session that can be uniquely identified by the browser itself.</em></strong></p><p>The only difference between the 2nd diagram is it is going to redirect the HR application back to the IdP without asking anything from IdP (02ns step of the 2nd diagram). You may have experienced the same thing, once you try to login into a certain application if you have used Microsoft O365 login there, your application will pass a query string with the browser URL. Then within the service provider’s domain, your browser redirects the application URL to the IdP login screen. Then you have to provide your user credentials there.</p><p>So hope you have learned something new. Let’s catch up in the very next episode. Otherwise, the content getting more and more :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*TSZAZ8pJdtmUQCrciv3ISQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=786c8ec83d52" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft-student-champs-sri-lanka/single-sign-on-sso-capabilities-with-identity-providers-786c8ec83d52">Single-Sign-On (SSO) capabilities with Identity Providers</a> was originally published in <a href="https://medium.com/microsoft-student-champs-sri-lanka">Microsoft Student Champs — Sri Lanka</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create your first customized app with Face API using .NET]]></title>
            <link>https://medium.com/microsoft-student-champs-sri-lanka/how-to-create-your-first-customized-app-with-face-api-using-net-c94df8651240?source=rss-e56247d71f09------2</link>
            <guid isPermaLink="false">https://medium.com/p/c94df8651240</guid>
            <category><![CDATA[cognitive-services]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[cloud-api]]></category>
            <category><![CDATA[msft]]></category>
            <category><![CDATA[microsoft]]></category>
            <dc:creator><![CDATA[Dinuwan Kalubowila]]></dc:creator>
            <pubDate>Wed, 06 May 2020 11:18:02 GMT</pubDate>
            <atom:updated>2021-08-27T18:20:14.325Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_F-cWtjHXUmLHOM7O5UvQ.jpeg" /></figure><h3>How to create your first customized app with Face API using .NET SDK</h3><h4>A Beginners Guide</h4><p>In the previous part of I discussed what is the internal structural behavior of face API. Then in this part let’s move on to some practical experiments. Simply I just want to do here, how to implement face API into your customized Projects. For simplicity, I choose Microsoft .NET SDK for this purpose.</p><h3><strong>Pre-Requirement</strong></h3><p>Basic Understanding HTTP web request handling</p><p>Fundamental knowledge on Microsoft Visual Studio and POSTMAN</p><h3>Covering modules</h3><p><a href="https://medium.com/@dckalubowila25132/face-detection-with-azure-cognitive-services-cc82e6624d9e">In the previous article I covered up what is the internal interaction of Face API and how it works. </a>I had done a video tutorial also on that article.<a href="https://www.youtube.com/watch?v=sKIli832kYc">Please find it in here</a>. From the last point that we have stopped let’s start up-to the .NET customized application.Then let me divide the article into 03 main section as follows. Because it will make easy for you.</p><p><strong>1.</strong> <strong>Get a Face API subscription from Microsoft Azure</strong></p><p><strong>2.</strong> <strong>Simulate Face API using POSTMAN</strong></p><p><strong>3</strong>. <strong>Simulate Face API using .NET SDK</strong></p><h4><strong>Get a Face API subscription from Microsoft Azure</strong></h4><p>Before moving on to the Development, you have to get a Face API subscription from Microsoft Azure. let’s take a tour to the Azure portal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q0G3DANREzzEYqxnUOTY7g.png" /></figure><p>Once you logged in to your Azure Portal it will look like this. If you already have a Face API subscription key. You don’t need to have the following parts. If you having it, it will display like above. Otherwise please follow the following steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1epRGsD9g8X_s3_hmSprzg.png" /></figure><p>According to the above figure, search type Cognitive Services and search it. When you are typing that it will be auto-suggested.Then move on to the Cognitive Services section. Then you could be able to see a window as bellows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_V-5TR32BQ8gb-DxmQ8Rzg.png" /></figure><p>If you are already having subscriptions on Cognitive Services, those will be listed on here. However, If you are freshens one to this. Click on Add Button above. Then there will be displayed a window like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QIueMznO8CgNJPVX8B1arg.png" /></figure><p>On this window (Marketplace), search the Face. (In previously this one came as Face API. But from 2019 it will be renamed as “Face”)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPwbSKKqCqTZ4QTZeY5wYw.png" /></figure><p>Then you will be able to see a figure like above. Then click the create button on there and create a Face API Service. In this procedure, you have to follow a form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*_dVS83GsvOll2JRq77D09w.png" /></figure><p>Please do not give numerical values to your service name. Because it was restricted from Microsoft Azure. Then select the subscription method, location, and Pricing Tier. If you are new to Azure you will receive a 200 USD free subscription at the initial level. Then your subscription will be displayed as “Free-Trail”. Select the resource group or otherwise, you have to create a new resource group if you have not yet. Then Finish the process and move on to your Azure Portal’s dashboard. As of 1st figure, you will be able to see your subscription on there from the given name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*KZLG50BxfT3mmIsnlMhznQ.png" /></figure><p>elect the subscription on your dashboard. After the portal will automatically redirect to the inside of its configurations. From that window, you can see your current selected subscription on the Menu panel on the left side. Go to resource management and click on “Keys and Endpoint”.</p><p>Then you will be displayed a window like a bellow.</p><p>You will be getting two API keys here. In addition to API keys, your API endpoint is already here. When using Face API in your customized application you have to use this endpoint. You can use one of those API keys as an authentication token to your endpoints. At any time that you want, you can renew those API keys by clicking the refreshing button.</p><p>So this is the story so far too for getting the Face API subscription key from Azure.</p><p>Cool. Now we have an endpoint and its authentication keys. What we have to look up next? :D. No doubts its POSTMAN. :D:D. This is the super easy platform to verify your API endpoints.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*_dVS83GsvOll2JRq77D09w.png" /></figure><p>If you currently did not have the POSTMAN, you can download it as either chrome to either or desktop application.(Recommended- Desktop App)</p><p><a href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en"><strong>Download Chrome Extensions</strong></a></p><p><a href="https://www.postman.com/downloads/"><strong>Download Desktop App</strong></a></p><h4>Simulate Face API using POSTMAN</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zTup3zNGnpAr-aGblyEzsQ.png" /></figure><p>In this scenario, you are sending an input throughout your customized application via Face API. It accepts the data from your request’s body. Therefore you have to use POST as your HTTP web request. Here you are interacting with JSON formatted data as I explained in theoretical session. Therefore, make sure the content type of your data should be JSON data. That’s why you have to mention it in your header as above. Then the other key value is “<strong>Ocp-Apim-Subscription-Key</strong>”. You have to mention this one on your header and assign the API authentication key which you had got from the Azure subscription.</p><p>Then what you have to call here? Simply the API endpoint which you have got from the subscription. You can attach any amount of parameters to this endpoint. Because in the hidden implementation, inside the Face API it will capable to handle “request.params” access points in your API endpoint.</p><p>You can learn more about how to handle the above API endpoint with necessary parameters on the following link.</p><p><a href="https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236"><strong>The Detect API</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yWxL7S6Z91X_C3AUACDErg.png" /></figure><p>The above image shows you what the current available regional vice API endpoints based on Microsoft Azure Data Centers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SA8Y07Vho_yltDz-PSEaZw.png" /></figure><p>The above figure shows you the valid parameters and useful request headers. This is Microsoft’s documentation about the Detect API.</p><p>In this tutorial, I will pass my parameters as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*DlHvZVSP4ZpzbegFiAk7ag.png" /></figure><p>In the above example, I will be returning The face Attributes. So what are face attributes? I had done an in-depth analysis of face attributes on the previous blog. Then there is a video tutorial also. If you forget those theoretical parts, please follow those first. I pass here age, gender, glasses, and emotion as selected face attributes. If you want to learn more about how to pass this endpoint, you could refer to the Detect API documentation above.</p><p>The following figure shows you how to pass your image URL which can analyze using the Face API. In the body of POSTMAN, you are passing this one as a JSON object. That is why previously I mentioned you should have to configure your content-type as “application/JSON”.If you are familiar with REST API and any other Full-stack Development, you might have prior experience with this one. Make sure when u attaching a URL of the image, the particular image should be published on the Internet. Face API does not access to your local file structures inside of Azure Infrastructure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y9oLxWvDk0Na7qThbktoyQ.png" /><figcaption>image url</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sud3Y6bA__cVTEfMpQFs3Q.png" /><figcaption>uploaded image</figcaption></figure><p>Then, your output would be display as bellows. You can see here, by default it included the Face ID. Because it is the Primary key to identifying each face in a given image.</p><p>faceRectange attributes show the location of a particular face throughput of its orientation. There is a parent element called faceAtrributes and it hooked those age, gender, emotion, and glasses, etc. Please check the previous article or video on what are the possible outcomes of the above-defined attributes.</p><p>In the theoretical section, I mention there are emotion attributes listed inside the Face API. You can see here all listed emotion attributes are shown the values as probabilities on each image. The summation of all emotion attributes is equal to 1.</p><p>Then if u get the output as follows, your API configuration and part are OK. Then now we are moving on to the .NET SDK to simulate the functionalities that we had done using POSTMAN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*chSox7Fohuw2OP0p7r3oUg.png" /></figure><h4>Simulate Face API using .NET SDK</h4><p>Start your Visual Studio and open a .NET Console Application. Here you have to use a dependency. Simply a .dll file. If you are not much familiar with, NET, you herd about plugin dependencies in JAVA. Which are nothing but JAR files in JAVA contain the pre defied classes, interfaces, and some other 3rd party dependencies. Even in package managers like NPM and Yarn do the same as this. By itself, it provides some other components, which are developed by other developers. Then you know while importing the JAR file into your JAVA project, you can directly access to either classes or interfaces inside the particular JARA file.</p><p>Therefore here we are using dependency called “Microsoft.ProjectOxford.Face”.<a href="https://github.com/microsoft/ProjectOxford-ClientSDK"> It is an open-source repository. You will be able to find it here on GitHub.</a></p><p>Then the next question is popped up into your mind is, how to install this dependency on your .NET Project. Like npm. In .NET there is allowed to have a package manager console. We call it “Nuget Package Manager Console in .NET”. In the Visual Studio IDE, it is enabled on the tools menu in Visual Studio’s top menu bar.</p><p><strong>Tools → NuGet → Package Manager → Package Manager Console</strong></p><p>After you selecting the Package Manager Console at the bottom of your visual studio a console panel may open.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*20G1WwvCa1M0a-3UL5Jawg.png" /></figure><p>If you want to go to the GUI of this Nuget Package Manager you have to select PackageManager Console. Then you will be able to see a GUI on NuGet packages.</p><p>If you are using the package manager console, there is a separate site called <a href="https://www.nuget.org/">NuGet org</a>, which included all available NuGet packages with its versions.</p><p>At that site, you have to search “Microsoft.ProjectOxford.Face” and copy the command given there and paste it in previously opened package manager console and press enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uv3K-4EwRNsh0Xf1Bnljpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*7CLfsYU8pzyxwWP8gRmx6A.png" /></figure><p>Be careful on your C# version, because here we are using the async functions in C#. So the async functions are only compatible with the C# 7.2 and upper. Otherwise, you have to upgrade your C# version.</p><h3>Abstract view of the code base</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0FDi0jyWaGAGff_CH6EFdg.png" /></figure><p>We apply “Microsoft.ProjectOxford.Face” previously into the project. Then you can see here there are some red color rectangular frames. Keywords that are surrounded by red cor rectangular frames come from above “Microsoft.ProjectOxford.Face” dependency.<strong><em> </em></strong><a href="https://github.com/DInuwan97/Customized_App_from-Azure_Face_API_DOT_NET_SDK"><strong><em>You can clone this project from GitHub on here.</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ncQyJx-UaUr-6QqZ860GYw.png" /></figure><p>In this article, I discussed how to configure Face API with the .NET SDK. In the upcoming parts let see how to configure Face API into web frameworks like React JS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c94df8651240" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft-student-champs-sri-lanka/how-to-create-your-first-customized-app-with-face-api-using-net-c94df8651240">How to create your first customized app with Face API using .NET</a> was originally published in <a href="https://medium.com/microsoft-student-champs-sri-lanka">Microsoft Student Champs — Sri Lanka</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Face Detection with Azure cognitive Services]]></title>
            <link>https://medium.com/microsoft-student-champs-sri-lanka/face-detection-with-azure-cognitive-services-cc82e6624d9e?source=rss-e56247d71f09------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc82e6624d9e</guid>
            <category><![CDATA[cognitive-services]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[face-api]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Dinuwan Kalubowila]]></dc:creator>
            <pubDate>Wed, 15 Apr 2020 09:01:40 GMT</pubDate>
            <atom:updated>2020-04-15T09:53:36.194Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_0ASnQVcA-AeJpbWxUkwjQ.jpeg" /></figure><h4>Beginner’s Guide</h4><p>First of all, moving on to Azure Cognitive services, you have to have a basic idea of actually what is Azure. Azure is a cloud platform that was provided by Microsoft Corporation.</p><h4><strong>Then what is Cognitive Services?</strong></h4><p>Simply those are some machine learning API’s. It gives you some extensions from customized projects. Then in addition to face detection, what are the other Cognitive Services available in Microsoft Azure?</p><h4>·Text to Speech</h4><h4>·Speech to text</h4><h4>·Voice recognition</h4><h4>·Voice typing</h4><p>Now we are moving on to the topic. It is Face Detection. As I mentioned before cognitive services are built upon some visual API s. The next question, which pops up to your mind is, Using Azure cognitive services, can we do human face detection only? No. In a general way, face detection is a subclass of image processing. As well as there are some specific API’s are reserved for face detection, some other kinds of API’s are available fro image content analyzing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*s0_FZQsSSPzKLE2myuHVAA.png" /><figcaption>Image Processing endpoints, provided by Azure</figcaption></figure><p>As quick as when you are looking at the above picture, you would be able to understand, which API’s that we are going to use in Face detection.</p><h4><strong>Vision API</strong></h4><p>Vision API is a content-specific analysis. It gives overall classification about the whole element. It returns descriptive content found in an image. This uses tagging, some domain-specific models to identify the behavior of the image.</p><h4><strong>Emotion API</strong></h4><p>This API is also very useful in face detection. This is specific to human images. This API can not use for getting some background information about a picture. Like Vision API.</p><p>Takes the facial expression in an image as an input and returns the confidence across a set of emotions for each face in an image.</p><p>Just have a simple idea from Emotion API, simply it returns the results based on facial expressions on particular face/faces.</p><h4><strong>Face API</strong></h4><p>Detect one or more human faces in an image and get back face rectangles for where in the image faces are, along with face attributes that contain the machine learning predictions with facial features.</p><p>Up to now don’t be confused about “Face rectangles”,” Face attributes” and “ML-predictions”.I discuss those things on bellow segments.</p><h4><strong>What is face detection and why?</strong></h4><p>Face detection is<strong> “Action of locating human faces in an image and optionally returning different kinds of face-related data” </strong>(Microsoft’s definition)</p><p>It helpful for operations such as,</p><p>• Security Scenarios</p><p>• Robotics Intelligent Systems</p><p>• Mobile Applications</p><p>• Natural User Interfaces</p><p>• Image Content and Analysis of Management Applications</p><h4><strong>Let’s move on to Face API in detail</strong></h4><p>The short and sweet definition is Face API is the brain of Face detection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*l5g73aMDKpusRRQR5fAetA.png" /></figure><p>As I define early, the internal structure of the Face API is machine learning behavior. Throughout that ML structure, There may a question arise to you. Why did machine learning behaviors need for Face API? Simply this is similar to “What is ML? ”</p><p>Typically in Machine Learning, you train your program/application to provide a self-configured response, when certain things occurred. How you should do that? You have to give some prior examples to your application, at the end which you accept from it. Without having prior examples, there is no Machine Learning.</p><p><strong><em>Then in the Face API, it provides some Machine Learning algorithms that are used to detect, recognize and analyze human faces in images. This is actually what face API does.</em></strong></p><h4><strong>If we move on step vice that, how Face API works, it’s as follows.</strong></h4><p>It identifies the human faces in a given image. How does it identify? Some kind of Machine Learning technique is happening on here. As I mentioned before ML is a prior example based analysis. Azure Cognitive team had trained Face API to identify human faces when it gets an image. It included the prior examples, on what contains the human face. (eyes, nose, mouth, lips, and chin, etc.) Face API can read the locations,attributesof an image and according to the distribution of each pixel, it can self identify those prior examples that included.</p><p>At the first step, face API gets the confirmation on there is it’s trained data. Then as the next step face API evaluates, whether those identified data is on organized orientation. As an example in a face, the top part should be head, then eyes, ears, nose, mouth, lips, and chin. Those things should be located in an organized way. Otherevice it is not an face image.</p><p>If those things are in an organized manner, then Face API returns the identified faces as rectangular pieces.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*sCuzCzdukmq71or4J9jrsw.png" /></figure><p>Inside of that rectangles, face API automatically coordinates the locations of objects.</p><p>Above organized faces are listed from largest to smallest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*Zy93RR-_KbXHzMLUNLKUTw.png" /></figure><p>In the next part, the rectangular pieces returned as a JSON document, which contains the details of the face(each rectangular piece).JSON document included face attributes and face related attributes. (Age, Gender, Hair, Skin etc…) Throughout the JSON document, it declares the specific face state. For the analysis phase, the statistical algorithm is involved here. Because of the statistical algorithm, face related attributes are defined as probabilities.</p><h4><strong>What are face related attributes?</strong></h4><p><strong>Age,Blur,Emotion,Exposure of the face,Facial hair &amp; gender,Glasses,Hair, Head Pose,Makeup,Noise,Occlusion and Smile</strong></p><p>By looking at the bellow examples, I hope there is no need for a definition for you to what is face related attributes means. :D</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*MAX_wSJCD0Lr7jtLK83R_g.png" /><figcaption><strong>Face related attributes returns from JSON document as Literal Objects</strong></figcaption></figure><h4><strong>Blur — Return blur level and blur value</strong></h4><p>The blurriness of the face in the image. Blur level returns the informal values called <strong>LOW</strong>, <strong>MEDIUM</strong> and <strong>HIGH</strong>. The value of a particular quality attribute is between 0–1.</p><h4><strong>Exposure — Return the exposure level and its value</strong></h4><p>The exposure of the face in the image. Exposure level returns the informal ratings called <strong>underexposure</strong>, <strong>goodExposure,</strong> and <strong>overExposure</strong>. The value of a particular quality attribute is between 0–1.</p><h4>Noise — Return noise level and noise value</h4><p>The visual noise detected in the image. Noise level returns the informal ratings called <strong>LOW, MEDIUM</strong> and <strong>HIGH</strong>. The value of a particular quality attribute is between 0–1.</p><h4><strong>Occlusion — Return Boolean values</strong></h4><p>Measurement of the amount of blocking parts of the face image. Returns the Boolean values for each object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*MMJXXEwGbDytimKi8Lb1_g.png" /></figure><h4><strong>Glasses</strong></h4><p>Check whether the given face has eyeglasses. Return values are <strong>NoGlasses, ReadingGlasses, Sunglasses, and Swimming Goggles</strong>.</p><h4><strong>Hair</strong></h4><p>The hair type of the face. Check whether the hair is visible, baldness is detected, and what hair colors are detected.</p><h4><strong>Makeup</strong></h4><p>Checks whether the face has makeup. Returns a Boolean value <strong>for eyeMakeup</strong> and <strong>lipMakeup</strong>.</p><h4><strong>Head Pose</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*_YCkGSkfnpl7_sa-6TX9Jw.png" /></figure><p>The face’s orientation in 3D space. This attribute is described by the pitch, roll, and yaw angles in degrees. Return ranges are</p><p><strong>pitch: -90 degrees to 90 degrees</strong></p><p><strong>roll : -180 degrees to 180 degrees</strong></p><p><strong>angles : -90 degrees to 90 degrees</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*06JTy1d2ZAfYRcwdBpUjfg.png" /><figcaption>JSON doc with emotional attributes</figcaption></figure><h4><strong>Emotions</strong></h4><p>Here is the place that Emotion API is invoking. That is why I mentioned before it is a very essential one on face detection.</p><p>A list of emotions with their detection confidence for the given face. There are 8 face emotions.</p><p>Those are, <strong>Happiness,Sadness,Neutral,Anger,Contempt,Disgust,Surprise and Fear.</strong></p><p><strong><em>For each emotion, face API returns the values between 1 and 0.</em></strong></p><p>In the definition of face API, I mentioned earlier, “<strong>Detect one or more human faces in an image and get back face rectangles for where in the image faces are, along with face attributes that contain the machine learning predictions with facial features</strong>.”</p><p>So, I hope now you can gain a complete understanding of the above definition.</p><p><strong><em>But one thing you have to strictly remember, Face attributes are predicted through the use of statistical algorithms. They might not always be accurate.</em></strong></p><h4><strong>How to use Face Detection Real World Scenarios</strong></h4><p>In real-world scenarios such as security reasons, image analyzing software and robotics systems, etc.. are based on one common factor. <strong>To those purposes need to identify a particular face uniquely</strong>.</p><p>Then this is the point when Face Verification is becoming very important via Azure Cognitive Face Detection.</p><p><strong>Face Verification and Find Similar Faces in an image</strong></p><h4><strong>Face Verification</strong></h4><p>Evaluates whether two faces belong to the same person. This capability is potentially useful in security scenarios.</p><h4><strong>Find Similar Faces</strong></h4><p>API compares a target face with a set of candidate’s faces. And finally, find a smaller set of faces that look similar to the target face. There are two working modes here.</p><p><strong>1) matchPerson</strong> — returns similar faces after it filters for the same person.</p><p><strong>2) matchFace — </strong>return s a list of similar candidate faces that might or might not belong to the same person.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*7C4U0lbhV3lw9oprtHWYHA.png" /><figcaption>Difference between machFace and matchPerson</figcaption></figure><p>According to the above image, finding similar faces from target face Face API used a procedure called, <strong>Face Grouping. </strong>In face Grouping, divides set of unknown faces into several groups based on the similarity. Each group is a disjointed proper subset of the original set of faces. All of the faces in a group are likely to belong to the same person. There can be several different groups for a single person.</p><h4><strong>When using Face API, you should be careful about the following cases.</strong></h4><p><strong><em>·The supported input image formats are JPEG, PNG, GIF, and BMP.</em></strong></p><p><strong><em>· The image file size should be no larger than 4 MB.</em></strong></p><p><strong><em>· The detectable face size range is 36 x 36 to 4096 x 4096 pixels.</em></strong></p><p><strong><em>· Some faces might not be detected because of technical challenges.</em></strong></p><p><strong>If you’re detecting faces from a video feed,</strong></p><h4><strong>Smoothing</strong></h4><p>Many video cameras apply a smoothing effect. Turn this off, because it creates a blur between frames and reduces clarity.</p><h4><strong>Shutter Speed</strong></h4><p>A faster shutter speed reduces the amount of motion between frames and makes each frame clearer. Recommend shutter speeds of 1/60 second or faster.</p><h4><strong>Shutter Angle</strong></h4><p>Some cameras specify a shutter angle instead of shutter speed. For the betterment lower shutter angle will result in clearer video frames.</p><p>Download a flowing desktop application from your Microsoft Store. From here the most important thing that you can simulate, how the above behaviors occur in your way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*ZssPVZ6oynyxXUNJulnLEw.png" /><figcaption>Intelligent Kiosk</figcaption></figure><h4><a href="https://aka.ms/kioskapp"><em>Download Here →</em></a></h4><p>References : Microsoft Documentation</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc82e6624d9e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/microsoft-student-champs-sri-lanka/face-detection-with-azure-cognitive-services-cc82e6624d9e">Face Detection with Azure cognitive Services</a> was originally published in <a href="https://medium.com/microsoft-student-champs-sri-lanka">Microsoft Student Champs — Sri Lanka</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JWT Bearer token authentication for Express JS]]></title>
            <link>https://medium.com/ms-club-of-sliit/jwt-bearer-token-authentication-for-express-js-5e95bf4dead0?source=rss-e56247d71f09------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e95bf4dead0</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[middleware]]></category>
            <category><![CDATA[express]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[json-web-token]]></category>
            <dc:creator><![CDATA[Dinuwan Kalubowila]]></dc:creator>
            <pubDate>Sat, 21 Mar 2020 18:05:34 GMT</pubDate>
            <atom:updated>2021-07-26T20:03:27.416Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*64xWqde8C_h70jlmNMertA.jpeg" /></figure><h3><strong>JWT Bearer token authentication for Express JS via Middlewears and Request-Response pipeline.</strong></h3><h4>Express API s with JWT Auth</h4><h3><strong>Pre-Requirements</strong></h3><p>REST API handling with Express JS</p><h4><strong>Why Authentication in REST API’s ?</strong></h4><p>In either MERN or MEAN stack development, usually, we integrate our REST API s using Express JS. Maybe POST, GET, PUT and DELETE requests are there. When developing a backend to the enterprise level web application, we have authenticated some required routes. Simply we put some restrictions to access to user route according to the user levels. For the authenticate purpose JavaScript developers typically use JSON Web Tokens(JWT).</p><p>This is the story that binds with JWT and ExpressJS.</p><h4><strong>How it actually works?</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*ee-gjkzzn6JcS5qeP5EtjA.png" /></figure><p>You can do this authentication either synchronously or asynchronously. If you visit the above GitHub repository you can get the documentation of JWT. If synchronously, you can set a variable to the JWT sign method and pass it into the payload with the secret key. Asynchronously, you have to use a callback function for this purpose.</p><p>You can require the above-installed node module of JSON Web Token using the require statement. The bellow picture shows the current coding that you should have.</p><p>Inline 16–20 in the above code block, It generates an authorization key according to the logged user in the above scenario.</p><p>Inline 16–20 in the above code block, It generates an authorization key according to the logged user in the above scenario. I use here asynchronous approach to do it. How id does that, accept the above hard-coded user object with relevant details as 1st parameter. As a 2nd parameter, you have to pass some string value. simply a secret key that you prefer. In the 3rd parameter, the sign function calls the callback function to generate the authentication token. If you got any errors,you can print it also.Otherwise, the secret key will be displayed as bellow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h0dtGqovxjCRbnxGJNa6-Q.png" /></figure><p>How to authenticate those routes? Therefore before developing any kind of REST API, you should have to understand how requests and responses will be going to control. For that purpose, you need to identify the Request-Response pipeline.</p><h4>What is a Request-Response Pipeline?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*00u1nN_RQnXyK83v2mAuUw.png" /></figure><p>First I don’ say anything :D . Try to get some understanding by only watching the above picture.</p><p>As an example, if you are not logged into your Facebook account,you will not be able to change your passwords, If you have not logged in to an E-Commerce app, the application does not allow to add products into the cart without a valid login. Before login, you should have a user account. Otherwise, user neither accesses to the profile nor add products into cart in the above E-Commerce site example. How did these things happen in REST API?</p><p>This is the place that the Request-Response pipeline is involving. It validates the user request step by step. So we call those steps as middlewares.</p><p>As the above picture once a request is created it appears to the Middleware 01. If the condition on the middleware 01 is approved, the particular request passes to the 2nd middleware. Unless the request passes to the upcoming middlewares, the request is lost. Neither forwarding the request anymore nor executing at the same positions. That is why we are getting some Forbidden messages sometimes. (403 requests).</p><p>When responding to a request the same procedure is happening, but reverse order. The response will trigger middleware 03 first, then 2 and 1.</p><p>This is the abstract execution behind the middlewares and request-responses pipelines.</p><p>As an example even if there is a logged user in an E-Commerce application, every user not allows the admin features. Only admin can access those admin features. Then how can application differentiate whether the logged user either administrator or not?. Do developers need to separate login portals? No.It needs only one login.but when generating the JWT token when the login process,it is a unique one. That token embedded whether the logged user either admin or not. How REST API track that scenario? Completely checking the above middlewares through the request-response pipeline. Even single middleware validation will fail, the entire request is going to lose.</p><h4>So now we are going to implement a specific middleware for the login authentication.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*G4KsipGXiQ5yHVsefiz-Ww.png" /></figure><p>According to the above picture, you have to implement the <strong>verifyToken</strong> method as your middleware function. <strong>Simply those middlewares are function</strong>. Either they will return something to the endpoint or execution reference to the next middleware function.</p><p>In the above function is for validation purposes. You already know what is the req, res words are. So what is ‘<strong>next</strong>’.It implies the next middleware function that has to be executed.</p><p>So in the above get request, it gets a <strong>executable reference</strong> from verifyToken middleware function. The verifyToken function is going to execute from here. After executing the verify token middleware <strong>next()</strong> command is ready to execute another middleware next to the verifyToken. But in the get request, I did not attach another executable reference to the 2nd middleware to be called. If you want to attach another middleware authentication you can implement a separate method and add it’s a reference to the get request’s pipeline as bellow.</p><p><strong>app.get(‘/api/login’,verifyToken,&lt;midlw 02&gt;…&lt;midlw 03&gt;,(req,res))</strong></p><p>Let’s move on to the <strong>postman testing</strong> for this scenario now. At last, we can discuss the body part of the verifyToken method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YVscHczaOtKfr7RjFrwGFQ.png" /></figure><p>To access the profile user have to login first. At the login, the user will get a secret token key as previously. So you can copy that token and paste it like above.</p><p>If you do not attach the secret token into here, you might not be allowed to access the profile. You might get the Forbidden message.</p><p>If there is a valid token in Authorization, logged user can get the details embedded inside the token. Why you get all user details here? Because you have already passed the entire user object into jwt.sign() function.(See the 16th line of 1st picture)</p><p>So how those Headers keys came?. Why we put our token as ‘Bearer &lt;token&gt;’?Lets’s move on to previous image that we temporarily skipped. :D</p><h4>Implementation of the verifyToken() method</h4><p>To access the profile user have to login first. At the login, the user will get a secret token key as previously. So you can copy that token and paste it like above.</p><p>If you do not attach the secret token into here, you might not be allowed to access the profile. You might get the Forbidden message.</p><p>If there is a valid token in Authorization, logged user can get the details embedded inside the token. Why you get all user details here? Because you have already passed the entire user object into jwt.sign() function.(See the 16th line of 1st picture)</p><p>So how those Headers keys came?. Why we put our token as ‘Bearer &lt;token&gt;’?Lets’s move on to the previous image that we temporarily skipped. :D</p><p>Let’s move to the body of the verifyToken function. It requests something on header. Simply it is requesting the ‘Bearer &lt;&gt;’ string that we paste from login. Either Angular or React you will be passing this to your local storage.In the postman our key is the ‘Authorization’ value of the key is ‘Bearer &lt;&gt;’ string.The root topic of the ‘Authorization’ key is ‘Header’.</p><p>At the 41 st line in one before the last picture, ‘bearerHeader’ variable assigns the string in the ‘Authorization’ keyword under the Header part. That is why it says ‘req.headers’.</p><p>After you get the token, the application will check either if there is token available or not or if available, check the validity of the token. The entire process is happing on single line.’undefined’ the key is responsible for the availability and validity of the token. Otherwise else part executed and send the Forbidden message. Then the request will be going to lose.</p><p>In the above case, it takes enter string (Bearer&lt;&gt;). So we have to splice above string to array elements. We split the space between Bearer and token value. Then in line 45 we take the 2nd element of the array to the separate variable. Thereafter our token of the ‘req’ parameter will assign the above element.(2nd array index).</p><p>Then it passes to the next middleware. In this example as we discuss earlier there is no any middlewares more, it will be accessed the request in the out get method. And also passes it t as a parameter to the callback function.</p><p>So if there is no error, JSON object with logged user’s data will receive.</p><p>It is long story so far.Anyway this is how JWT authentication,Middlewaers and Request-Response Pipeline works inside Express REST API.</p><p><a href="https://github.com/DInuwan97/week7_express_jwt_req_rest_pipline_middlewear">Get source code from here.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e95bf4dead0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ms-club-of-sliit/jwt-bearer-token-authentication-for-express-js-5e95bf4dead0">JWT Bearer token authentication for Express JS</a> was originally published in <a href="https://medium.com/ms-club-of-sliit">MS Club of SLIIT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WEBPACK?]]></title>
            <link>https://medium.com/@dckalubowila25132/webpack-3199e0027aa5?source=rss-e56247d71f09------2</link>
            <guid isPermaLink="false">https://medium.com/p/3199e0027aa5</guid>
            <category><![CDATA[bundle]]></category>
            <category><![CDATA[modularity]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Dinuwan Kalubowila]]></dc:creator>
            <pubDate>Sat, 14 Mar 2020 16:50:51 GMT</pubDate>
            <atom:updated>2020-03-14T17:20:26.556Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HgvL9NNcWZ7uJcFRWr5W_Q.jpeg" /></figure><h3>Waht is WEBPACK?</h3><h3>Pre-Requirements</h3><p>Basic Understanding about HTML,CSS and JavaScript binding</p><p>Simply webpack is bundle your assets,modules,dependencies and static assets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B-j5fQM-Y-6kH_mEgMp6BA.png" /><figcaption>an abstract behavior of webpack</figcaption></figure><p>In above figure simply you can get an basic understanding about what does webpack?</p><p>It takes a bunch of files that are connected in some way, SASS, JS file, images. Then it turns through an above object like a cube which that assuming is webpack.</p><p>In the right hand, there are standard JS,CSS and JPEG images. Webpack is a perfectly build process. If you are familiar with “gulp.js”, it is doing something the same. But the process is different. As an example, if we take virtual machines and Docker containers the objective is the same. But when approaching the particular objective it’s technique is quite different.</p><p>Through a webpack we can organize our code in an organized way. The modularity of the webpack is the most important factor. You can apply this we back technology into AngularJS, ReactJS, and VueJS also.</p><p>Besides, to handle the above modules, it also handles the version conflictions with our codebase vs browser.</p><p>eg: NextJS to ES6</p><p>Simply using a webpack, it builds your code segment, something browser can read. That’s why at the very first I have mentioned webpack is a certain kind of systematic build process.</p><p>There also some advanced features in webpack like Dead Code Elimination. It can find the code that you are not actually using or maybe it can bundle up smaller modules of JS. Because it is flexible in configuration.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3199e0027aa5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React JSX implementation beyond BABEL]]></title>
            <link>https://medium.com/ms-club-of-sliit/react-jsx-implementation-beyond-babel-8698ae2f0b6?source=rss-e56247d71f09------2</link>
            <guid isPermaLink="false">https://medium.com/p/8698ae2f0b6</guid>
            <category><![CDATA[virtual-dom]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[jsx]]></category>
            <category><![CDATA[react-jsx]]></category>
            <category><![CDATA[babel]]></category>
            <dc:creator><![CDATA[Dinuwan Kalubowila]]></dc:creator>
            <pubDate>Sat, 07 Mar 2020 14:57:44 GMT</pubDate>
            <atom:updated>2021-07-26T20:18:21.883Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MJDm4nSShvfUch6SVvrCOA.jpeg" /></figure><h4>JavaScript + HTML</h4><h4>Pre-requirements : <a href="https://reactjs.org/">Basic knowledge of React.</a></h4><h4>From the Basic of React JS</h4><p>After you are getting started with the React project, your directories are like below. After creating the react project you will have to create a component folder and inside of that, you must add your components. These are some basics of React JS.</p><h4>Why JSX?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/1*g4dT8LG9MhvD6H85xipZJA.png" /><figcaption>Folder structure of React Project</figcaption></figure><p>You can see where those files inside the dashboard folder are, styled with react icon. (to get these kinds of icons you have to install the material theme to your visual code editor).Extension of those files are.JSX. Then what happened to conventional.JS extension. Most of the time react developers use. JS extension files in here.Then what is the reason and what is the advantage of using.JSX extension here? You can get better code completion by using it. JSX extension. Developers can easily identify what are the front end parts directly while identifying the React icon on .JSX file.Then let see actually what is this.JSX means. As a react developer you all are crating your front end using basic HTML and CSS. Yes, there are some differences. As an example, you do not allow use “class” attribute inside the .JSX files, inline CSS methodologies are little different from conventional inline CSS.</p><p>Even if, you are adding HTML elements here.JSX file is not an HTML file. It represents some kind of abstraction to the developer. It converts those HTML elements into JS elements. Simply JSX is neither HTML nor String. JSX stands for JavaScript XML. We use HTML tags because most of the time developers are familiar with that. It describes what the UI is going to look like.</p><h4>Behavior of Parent Element</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fXD6xCAsfRo-YLi8rJFipQ.png" /><figcaption>Sample Rendering content in React</figcaption></figure><p>In the above picture, you can see above every content is wrapped by one div element. As a React developer, you should know, the JSX element must have one parent element. If you are not wrapped such content, you would be getting run time error. So did you think about why we have to wrap from parent element. What is the abstract implementation behind it? Here, your JS engine gets the assist of the “BABEL”. Because the JS engine can not understand what JSX is.BABEL is the engine that creates JSX into JavaScript.</p><h4>Why Babel?</h4><p>Front end HTML part on JSX page is going to embed inside “React.createElemet()” statement. If you don’t use one wrapped element, babel can not understand what your browser says. BABEL engine confuses with what is the react element that should return on behalf of the above front-end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*E2XiJoHGzLoa-p8Ru4UndA.png" /><figcaption>Rendering content, that without having parent element</figcaption></figure><p>If you wrapped your content using, parent element, React will understand is as “<strong>React.createElement(‘&lt;parent-element&gt;’)”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*NBejU8h3Ege1nzjTxBBcMg.png" /><figcaption>Rendering content, that with having parent element</figcaption></figure><p>If you browse babeljs.io/repl you get the online babel engine. You can try some examples there. If you use your front end without one parent element your code base not be working, owing to this babel’s problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YP9MS4sEYAKYARRG95NjLQ.png" /><figcaption>BABEL execution of JSX vs JS</figcaption></figure><p>Throughout this story, I cover why developer use.JSX extension for front end parts and another one is what is the actual execution behind the JSX.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8698ae2f0b6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ms-club-of-sliit/react-jsx-implementation-beyond-babel-8698ae2f0b6">React JSX implementation beyond BABEL</a> was originally published in <a href="https://medium.com/ms-club-of-sliit">MS Club of SLIIT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>