<?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 Malshan Ranawella on Medium]]></title>
        <description><![CDATA[Stories by Malshan Ranawella on Medium]]></description>
        <link>https://medium.com/@malshanranawella?source=rss-c79ef72536e4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LMBfwQwa1SlRsC6wPtx7fA.jpeg</url>
            <title>Stories by Malshan Ranawella on Medium</title>
            <link>https://medium.com/@malshanranawella?source=rss-c79ef72536e4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 02:25:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@malshanranawella/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[Don’t worry, be happy!]]></title>
            <link>https://medium.com/@malshanranawella/dont-worry-be-happy-2451d4c83e1e?source=rss-c79ef72536e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/2451d4c83e1e</guid>
            <category><![CDATA[worrying]]></category>
            <category><![CDATA[relaxation]]></category>
            <category><![CDATA[happiness]]></category>
            <category><![CDATA[meditation]]></category>
            <category><![CDATA[mind]]></category>
            <dc:creator><![CDATA[Malshan Ranawella]]></dc:creator>
            <pubDate>Mon, 17 Apr 2023 13:13:00 GMT</pubDate>
            <atom:updated>2023-04-17T13:13:00.376Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*fwoNTuvv0iOcnHBc" /></figure><h3>“Oh my god! Why did this happen?”</h3><p>If not exactly these words, at least some phrase with a similar worrisome meaning come to our minds when something awful and unexpected happens in our lives. It’s a very natural emotion that a human being feels. You must have experienced this at many points in your life. You might be going through such an experience even in this very moment!</p><p>But according to my opinion and personal experience, worrying and solving the problem that caused the worry, should not be always interrelated.</p><p>Finding a solution to a problem requires logic, reason and emotional intelligence. Solving a problem with a calm mindset is the best way. But this is often not the path that the majority takes. They seem to find solutions while the mind is not at ease, in a worrying state. The theoretical best practice would be to calm the mind first, and then go about solving the problem. Taking some time off alone, meditation and speaking to a reasonable person can help calm your mind.</p><h3>What I suggest</h3><p>But I suggest that we can train ourselves not to worry even in very surprising situations. That way, we will be able to keep our reasonable and logical mind even in extremely chaotic situations, make quick logical decisions and bring out the best possible solution.</p><p>When a problem comes, you can either keep worrying, or stop worrying and get to thinking “what should I do now?”. Often people tend to take the 1st choice, because humans are naturally driven by emotions.</p><p>What happens when you worry is, your mind becomes very turbulent and dizzy, and prevents you from thinking clearly. This is not a situation that you should be making important decisions. You naturally may end up taking very short sighted decisions and will create more problems in the future. Your world might crumble upon you, which apparently is your own doing. This can harm your self confidence as well, in time. I’m personally strictly against this happening for any person.</p><h3>How to refrain from worrying?</h3><p>Worrying and solving the problem, are two very different things. But people rarely see the separation. Worrying doesn’t help you come up with a solution. It may as well refrain you from coming to a viable solution. So it is important if we can train to separate worrying from problem solving.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*L5QGbofg9xPPwWMc.jpg" /><figcaption>(Reference: <a href="https://joshvanberkel.com/latest-blog/olderblog/doyouworrytoomuch/">https://joshvanberkel.com/latest-blog/olderblog/doyouworrytoomuch/</a>)</figcaption></figure><p>This is the most simple diagram to explain my general way of thinking, when a problem comes.</p><ul><li>If there are no major issues in your life, simple go on with your life. Don’t go looking for problems. Some people are somehow addicted to worrying, they make even the smallest issues worse by worrying about it. You don’t have to do that !</li><li>If you come across a situation, ask yourself the question “Can I do something about this?”. If there is something you can do, just do it quickly without keeping yourself in worry, and move on with yourself. Don’t waste time. The more you spend time worrying, the harder it is for you to come out of worry.</li><li>If there’s no solution that you can do <strong>within your scope</strong>, then also the answer is “do not worry”. It is so, because you worrying about it simply doesn’t solve the problem at all. It will simply harm your mental state and will take long time for you to recover. <strong>Just let it go, and move on.</strong></li></ul><p><strong><em>In addition to this, practicing meditation, yoga or other ways to calm the mind definitely trains you to keep a calm mind in turbulent situations. I will not go into much details in this article.</em></strong></p><h3>What can happen if you “get” this</h3><p>Not worrying in a turbulent situation, is not a skill that the vast majority has. Understand this. If you can practice this and be good at it, you will become an extremely unique person, since you will be able to see what many others cannot see, in times of chaos.</p><p>Such a person can keep a clear mind when all the others around are in panic, and turn the situation to his or her advantage. This can either be used for good or bad. The choice is yours.</p><p>In an emergency situation, you can stand up among others who panic, calm them down and direct all of them to safety calmly and in order. Or, you can create a panic situation and manipulate the other majority to obtain what you want out of that situation. This is commonly done in many situations in society, to obtain political, economical or religious advantages. See through, and find out the real source of the panic. You can understand the original motive.</p><p>My hope is that the information in this article will be used for a good purpose.</p><h3>Please don’t misunderstand this article</h3><p>The bottom line of this article is to help people to keep a calm mind in the difficult and turbulent moments in their lives, so that they can come up with good and logical solutions for their problems.</p><p>But this definitely doesn’t mean that you should be cold hearted. Worrying is a human nature. If you tend to worry a lot, then Congratulations ! You’re a human.</p><p>Understand this. Just try to calm yourself, so that you will not be manipulated by other parties in such situations. It’s a beautiful world to live in.</p><p>:-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2451d4c83e1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hey man, I need to talk to you…]]></title>
            <link>https://medium.com/@malshanranawella/hey-man-i-need-to-talk-to-you-377adbd29fca?source=rss-c79ef72536e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/377adbd29fca</guid>
            <category><![CDATA[listening-to-others]]></category>
            <category><![CDATA[peer-counselling]]></category>
            <dc:creator><![CDATA[Malshan Ranawella]]></dc:creator>
            <pubDate>Wed, 05 Apr 2023 15:58:38 GMT</pubDate>
            <atom:updated>2023-04-05T15:58:38.747Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*kCzJdYZNXWDg6rJXyXbUvA.jpeg" /></figure><p>Humans are social creatures by their nature. Interaction with others is woven into their DNA itself. In that interaction, listening and talking is an essential part, which makes it clear that knowing how to listen well, is a fundamental requirement a human life needs.</p><p>But do we often listen correctly? Think about it…<br>When a friend, a peer comes towards you saying “hey, I need to talk to you. I’m facing a bit of a problem. Do you have a minute?” and start telling his story, how do you handle that? Have you been able to help them calm their minds?</p><p>The way you listen, makes all the difference. There’s a saying that, if you talk to a correct person about your problems, 80% of that problem’s weight is lifted from your shoulders. But the words “correct person” matters a lot. If that person undermines your problem saying “don’t think much. Even I’ve got bigger problems than that”, would you feel like telling him your problems any further? No you won’t, right?<br>So, know the do’s and don’ts. Let me help you with some insights.</p><h3>1: The problem is serious to the person going through it</h3><p>How a person feels a problem cannot be compared to how another does. It depends on many factors such as the person’s sensitivity, life experiences, immediate past events, state of mind (eg: if the person has consumed alcohol), mental or physical illnesses etc. So, do not judge whether it is a small or a big problem.<br>Therefore always give your best priority to them when you listen. Let them feel that you understand how serious the problem is to them and that you accept the severity of the problem. If you don’t and you say “oh it’s only a small problem. Don’t worry about it”, they might not open up for you and might feel less about themselves. It can harm their self confidence, which is the last thing you need to do.</p><h3>2: How you listen, is critical</h3><p>Keep in mind that while you pay attention to them while listening, they are also subconsciously paying even harder attention towards you, since this is a moment that they feel most vulnerable. Therefore how you receive is very important. Keep firm and bright eye contact with them when they speak.<br>If you receive their problems in a positive manner, maybe with a soft smile in your face, they may get a feeling that their problem might not be unsolvable. If they see you in a positive attitude, that alone can lift the weight from their heads.<br>Listen very actively. Do not let them do all the talking. Ask questions, maybe about the background information. Show that you pay full attention towards even the smallest detail of the story. It makes them feel comfortable around you. Further more, acknowledge what they say by using phrases like “ah really?, mm hmm?” and facial expressions.<br>If they don’t feel like you’re listening, they will not go further into explaining.</p><h3>3: Be careful when you tell your personal experiences</h3><p>We generally tend to include our personal experiences when trying to comfort a person. But this must be done very carefully, due to many reasons. <br>First is, if you state too much of your personal experiences, the conversation might turn towards you rather than them. This must be avoided. The centre of attention must not be stolen by the listener.<br>Second, the listener being attached to the problem can be very problematic. The listener better maintain the role of the mediator, instead of getting included in the problem. That way, the listener gets the liberty to stay impartial, which is invaluable in some situations.</p><h3>4: Know when to direct to a professional</h3><p>This article is not meant for professionals. If you’re not a professional counsellor, keep in mind that you do not know everything in the world. Peer counselling can induce a sense of power and perfection over others, which can easily deceive you.<br>Know when the problem cannot be resolved by you and seek the support of a professional. Do not <strong>go with your best guess</strong> in a serious situation. It can be a matter of life and death, and you do not want the result to be in your hands, if something bad happened.</p><h3>5: Have an anchoring point for yourself as well</h3><p>As I said earlier, counselling is not an easy job. Maintaining the personal mindset away from the people coming to you with their problems is a tricky task. Do not get deceived by the fact that you need to be perfect to help others. Make sure to keep someone else, maybe a sibling or a parent or a teacher, for you to talk to as well. Otherwise you will be lost while trying to help others. This is an unfortunate situation which no one should be in.</p><h3>Final note</h3><p>Please keep in mind that none of these points are tricks or tactics. They are points to purely pay attention to, when someone trusts you enough to tell you their problems. I wrote this article from my life experience up to today. Therefore, my ideas might not be 100% perfect. I had to generalise a lot.</p><p>If I summarise the complete article for you, what I’m telling you to love the people around you from the bottom of your heart. It is love and caring, what manifest through how you listen and how you guide them towards attaining peace in mind. Love them truly, and you will do the rest quite naturally and in your own wonderful way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=377adbd29fca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OpenID Connect (OIDC) — A bird’s eye view]]></title>
            <link>https://medium.com/@malshanranawella/openid-connect-oidc-a-birds-eye-view-1fb7b3ec1359?source=rss-c79ef72536e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fb7b3ec1359</guid>
            <dc:creator><![CDATA[Malshan Ranawella]]></dc:creator>
            <pubDate>Mon, 06 Feb 2023 00:01:32 GMT</pubDate>
            <atom:updated>2023-02-06T00:01:32.924Z</atom:updated>
            <content:encoded><![CDATA[<h3>OpenID Connect (OIDC) — A bird’s eye view</h3><h3>What is OIDC and why OIDC?</h3><p>We learned about the OAuth2.0 protocol in the previous few articles. If you don’t have an idea on OAuth2.0, please refer to my previous articles under the theme “OAuth2.0 for dummies”. Knowledge about OAuth2.0 is essential to understand the concepts about OIDC.</p><p>OAuth2.0 is basically a framework or a protocol for a client to access protected HTTP resources of a resource owner, with an authorization server working as an intermediary. But in OAuth2.0, the client cannot get any information about the end users, AKA resource owners within the protocol. The resource owner only uses authentication to grant access to the protected resources, but doesn’t provide his/her information to the client. That information can be important to the client applications for various reasons. End-User information is technically referred to as user claims.</p><p>OIDC is introduced to cater that requirement. It is simply an authentication mechanism built on top of the OAuth2.0 framework. Earlier on OAuth2.0 we gain access to the protected resources by using an Access Token which is issued by the authorization server, after getting consent from the resource owner. In OIDC, we come across another token called ID Token, which gives the client access to the end user (resource owner) claims. ID token is a JWT (JSON Web Token).</p><h3>Terminology</h3><p>Now, according to the OIDC specification, the terminology is a bit different from the OAuth2.0 terminology. But in case you need to go through the specification and understand it further, you will need to adhere to the correct terminology. Therefore I will use the OIDC terminology in this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*m16OpcPSM1oiGVCgsoxcTw.png" /></figure><p>Please note that only the authorization servers which implement OIDC are called OPs. Also, I have only included the terminology that is used in this article. Further information about the terminology can be found in the section 1.2 of the OIDC specification document.</p><h3>OAuth2.0 to OIDC</h3><p>As I mentioned earlier, OIDC is built as an extension to OAuth2.0 to provide end-user information to the RP. Then how does a RP request for the use of OIDC flow instead of generic OAuth2.0 flow? It’s simple!</p><p>You remember the first step of OAuth2.0 flow right? It’s sending an authorization request to the authorization server (OP), from the client (RP). To invoke the OIDC flow, you simply have to set the scope of the authorization request to “openid”.</p><h3>OIDC Flow</h3><p>Now let’s go into detail about the OIDC flow. Refer to the diagram which was taken from the OIDC specification itself, to keep the originality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/0*MzhKucgw3AwjM4Or" /></figure><ol><li>: The RP sends an authorization request to the OP with the scope value set to “openid”</li><li>: The OP prompts the End-User to authenticate himself and to give permissions. The End-User authenticates and gives permissions to access the protected resources, and the End-User claims.</li><li>: The OP responds to the RP with an ID token and an Access Token. ID token contains Claims about the Authentication of an End-User by an Authorization Server. If required user’s other claims also may included in the ID token</li><li>: To obtain the End-User claims, the RP can send a UserInfo Request to the OP along with the ID Token received.</li><li>: The OP responds with a UserInfo Response, after processing and validating the UserInfo Request.</li></ol><h3>Endpoints of OIDC</h3><p>In OAuth2.0, we came across 2 main endpoints of the authorization server, the Authorization Endpoint and the Token Endpoint. An OpenID Provider also requires the same 2 endpoints, but with an additional endpoint as well, which is the UserInfo endpoint which accepts UserInfo requests and issues UserInfo responses. The request and response in the steps 4 and 5 of the above diagrams, go through the UserInfo endpoint.</p><h3>ID Token</h3><p>The ID token issued in OIDC flow contains the following fields.</p><ul><li>iss (REQUIRED) : ID to identify the issuer of the token. It is a URL containing scheme, host, and optionally a port number and path components, without any query or fragment components.</li><li>sub (REQUIRED): Subject Identifier, to identify the End-User. It’s a case sensitive string.</li><li>aud (REQUIRED): Audiences that the ID token is intended for. It is an array of IDs of the intended audience. It must contain the client_id of the RP.</li><li>exp (REQUIRED): Expiration time.</li><li>iat (REQUIRED): Time at which the token was issued. exp must be a value higher than this.</li><li>auth_time : Time when the End-User authentication occurred. It is OPTIONAL if the max_age request or an auth_time request is not made. Otherwise it is REQUIRED.</li><li>nonce : String value to associate a RP session with an ID token, and to mitigate replay attacks.</li><li>acr (OPTIONAL): Authentication Context Class Reference.</li><li>amr (OPTIONAL): Authentication Methods References.</li><li>azp (OPTIONAL): Authorized party. This is only needed when the ID token has a single audience value and it is different from the authorized party.</li></ul><p>Each of the time values mentioned in the above list is a JSON number representing the number of seconds from 1970–01–01T0:0:0Z as measured in UTC until the date/time of expiration.</p><p>It is possible that an ID Token may contain other claims. Any claims that are not understood by the OP are ignored.</p><h3>Example ID Token</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/0*GXhVVX7po_dNwFG7" /></figure><h3>References:</h3><ul><li>OIDC Specification: <a href="https://openid.net/specs/openid-connect-core-1_0.html#CodeFlowSteps">https://openid.net/specs/openid-connect-core-1_0.html#CodeFlowSteps</a></li><li>OAuth2.0 for dummies — 1 : <a href="https://medium.com/@malshanranawella/oauth2-0-for-dummies-4292a5a0bcde">https://medium.com/@malshanranawella/oauth2-0-for-dummies-4292a5a0bcde</a></li><li>OAuth2.0 for dummies — 2 : <a href="https://medium.com/@malshanranawella/oauth2-0-for-dummies-obtaining-authorization-from-the-user-1925b76bd2c6">https://medium.com/@malshanranawella/oauth2-0-for-dummies-obtaining-authorization-from-the-user-1925b76bd2c6</a></li><li>OAuth2.0 for dummies — 3 : <a href="https://medium.com/@malshanranawella/oauth2-0-for-dummies-access-and-refresh-tokens-7d2e1feca8ae">https://medium.com/@malshanranawella/oauth2-0-for-dummies-access-and-refresh-tokens-7d2e1feca8ae</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fb7b3ec1359" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OAuth2.0 for dummies — Access and Refresh Tokens]]></title>
            <link>https://medium.com/@malshanranawella/oauth2-0-for-dummies-access-and-refresh-tokens-7d2e1feca8ae?source=rss-c79ef72536e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d2e1feca8ae</guid>
            <dc:creator><![CDATA[Malshan Ranawella]]></dc:creator>
            <pubDate>Sun, 05 Feb 2023 23:59:13 GMT</pubDate>
            <atom:updated>2023-02-05T23:59:13.197Z</atom:updated>
            <content:encoded><![CDATA[<h3>OAuth2.0 for dummies — Access and Refresh Tokens</h3><p>In the previous articles, we covered the basic OAuth2.0 flow and the methods of obtaining user authorization. In the 2nd article in this series, we discussed the different methods used in obtaining authorization from the user, i.e. the grant types and flows. We came forward in the OAuth2.0 flow up to the point where the client receives the access token and refresh token from the authorization server.</p><p>Now, we are going to discuss more about the two token types that we have in our hands, how they behave and how to handle them.</p><h3>1. Access Token</h3><p>After the client receives an authorization code (we’re referring to the authorization code grant for this scenario to explain better), it then makes a token request to the authorization server, through the token endpoint of the server. The token request contains the following parameters.</p><ul><li>grant_type (REQUIRED) — value <strong>must</strong> be set to the relevant grant type (eg: “authorization_code”)</li><li>code (REQUIRED) — the authorization code received from the authorization server</li><li>redirect_uri (REQUIRED if the ‘redirect_uri’ parameter was included in the authorization request) — this <strong>must</strong> be identical to the redirect_uri provided in the authorization request. This is the URI to which the authorization server sends the tokens.</li><li>client_id (REQUIRED) — if the client is not authenticating with the authorization server in a different manner (further explained in the Section 3.2.1 in the specification)</li></ul><p>Please note that the token request takes different formats according to the grant type. Here, we have used the format according to the authorization code grant type.</p><h3>2. Successful Response</h3><p>If the request was successful, the authorization server sends back an access token and optionally a refresh token as well. If the request is invalid or unsuccessful, then the authorization server responds with an error response.</p><p>A successful token response will have the following parameters in the HTTP request, with a 200 (OK) status code.</p><ul><li>access_token (REQUIRED) — the access token issued by the authorization server</li><li>token_type (REQUIRED) — the type of token issued (will be explained later)</li><li>expires_in (RECOMMENDED) — the lifetime of the access token, in seconds.</li><li>refresh_token (OPTIONAL) — the refresh token (will be explained later)</li><li>scope — OPTIONAL if it’s identical to the scope requested by the client. Otherwise REQUIRED.</li></ul><p>These parameters are sent in the JSON format, in which the order of parameters is not important. These are included in the entity-body of HTTP response using “application/json” media type.</p><p>Example successful token response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/0*ZC8P_Ou3oPCCWaFq" /></figure><h3>3. Error Response</h3><p>If the request fails, a HTTP 400 status code is sent back with the following parameters.</p><ul><li>error (REQUIRED) — specifies what the error is. Includes one of the following.</li><li>error_description (OPTIONAL) — it’s a human readable text description on the error</li><li>error_uri (OPTIONAL) — a URI which points to a human-readable web page which describes the error</li></ul><p>We’ll now dive deeper into what kinds of errors can happen in token requesting, and which conditions can cause them.</p><h4>invalid_request</h4><p>This can happen due to,</p><ul><li>Missing a required parameter</li><li>Includes an unsupported parameter value</li><li>Repeats a parameter</li><li>Includes multiple credentials</li><li>Utilizes more than one way to authenticate client</li><li>Any other malformation</li></ul><h4>invalid_client</h4><p>Client authentication failed (authorization server returns a HTTP 401 (Unauthorized) status code). This can happen due to,</p><ul><li>Unknown client</li><li>No client authentication included</li><li>Unsupported authentication method</li><li>Other</li></ul><h4>invalid_grant</h4><p>This can happen due to,</p><ul><li>Invalid authorization grant provided</li><li>Invalid refresh token provided when trying to get a new token after the issued access token expired (can also be expired or revoked)</li><li>The redirection URI of refresh token does not match with the URI in the authorization request</li><li>The refresh token was issued to a different client</li></ul><h4>unauthorized_client</h4><p>The client is not authorized to use the grant type.</p><h4>unsupported_grant_type</h4><p>The grant type is not supported by the authorization server.</p><h4>invalid_scope</h4><p>The requested scope is invalid, unknown, malformed, or exceeds the scope granted by the resource owner.</p><p>Example error response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*RaUGbLhPXV5J7Y2t" /></figure><h3>4. Access token types</h3><p>The type of access token must be understood by the client, since it contains the information on how to utilize the access token to create a successful protected resource request.</p><p>Two example access token types are given below.</p><h4>‘bearer’ token type</h4><p>It simply includes the access token string in the request</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/0*90CEs4BBcSQMc6ww" /></figure><h4>‘mac’ (Message Authentication Code) token type</h4><p>Issues a message authentication code together with the access token</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*y3HC3_9IyejSQdkV" /></figure><h3>5. Refresh Token</h3><p>The authorization server issuing a refresh token along with the access token is optional. If it was issued, it can be used to obtain a new access token when the existing one expires. You of course must remember that along with the access token, an expiration time is also defined (expired_in). If you don’t, just look up! We just discussed this.</p><p>If a refresh token was issued, then the client can make a refresh request to the authorization server by including the following parameters.</p><ul><li>grant_type (REQUIRED) — this value <strong>must</strong> be set to “refresh_token”</li><li>refresh_token (REQUIRED)</li><li>scope (OPTIONAL)</li></ul><p>The refresh token is a long lasting credential. Therefore to ensure security, if the client type is ‘confidential’, the client must authenticate with the authorization server. It should also be done if the client was issued client credentials, from the authorization server.</p><p>Example token refresh request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1P8NQXkxn1WhtRnC" /></figure><p>If the refresh request is valid and authorized, the authorization server issues a new access token for the client. If the request verification failed or if it’s invalid, an error response is returned.</p><p>We must note that the authorization server may or may not issue a new refresh token, in the refresh response. If one was issued, the client must replace the old refresh token with the new one.</p><h3>6. Access token refresh flow</h3><p>The below diagram gives a high level idea of the token refresh flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*65S6gPk0YmHa9Fpx" /></figure><p>A: Authorization grant flow (depends on the grant type)</p><p>B: The client receives an access token and a refresh token</p><p>C: The client makes a resource request by sending the access token</p><p>D: Client accesses protected resources</p><p>(Steps C and D can happen repeatedly)</p><p>E: Client presents the access token after it is expired</p><p>F: Client receives an invalid token error from authorization server</p><p>G: Client makes a refresh request by sending the refresh token</p><p>H: Client receives a new access token and optionally a new refresh token</p><p>(From here, it continues from step C)</p><h3>References:</h3><ul><li>OAuth2.0 Specification: <a href="https://www.rfc-editor.org/rfc/pdfrfc/rfc6749.txt.pdf">https://www.rfc-editor.org/rfc/pdfrfc/rfc6749.txt.pdf</a></li><li>OAuth2.0 for dummies — Introduction to OAuth2.0 : <a href="https://medium.com/@malshanranawella/oauth2-0-for-dummies-4292a5a0bcde">https://medium.com/@malshanranawella/oauth2-0-for-dummies-4292a5a0bcde</a></li><li>OAuth2.0 for dummies — Obtaining Authorization from the User : <a href="https://medium.com/@malshanranawella/oauth2-0-for-dummies-obtaining-authorization-from-the-user-1925b76bd2c6">https://medium.com/@malshanranawella/oauth2-0-for-dummies-obtaining-authorization-from-the-user-1925b76bd2c6</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d2e1feca8ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OAuth2.0 for dummies — Obtaining Authorization from the User]]></title>
            <link>https://medium.com/@malshanranawella/oauth2-0-for-dummies-obtaining-authorization-from-the-user-1925b76bd2c6?source=rss-c79ef72536e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1925b76bd2c6</guid>
            <dc:creator><![CDATA[Malshan Ranawella]]></dc:creator>
            <pubDate>Sun, 29 Jan 2023 06:28:14 GMT</pubDate>
            <atom:updated>2023-01-29T06:28:14.161Z</atom:updated>
            <content:encoded><![CDATA[<h3>OAuth2.0 for dummies — Obtaining Authorization from the User</h3><p>In the previous article, we discussed a very high level overview of the OAuth2.0 protocol and its basic authorization flow. But in that, we did not go into details of each step of the flow. With this article, we are going to start doing that. Buckle up!</p><p>Here, we will discuss how the very first step happens, which is called the “Authorization grant”. It is simply the step in which the client obtains the authorization from the resource owner. After this step, there is no more interaction with the resource owner. Then the authorization server will basically represent the resource owner in front of the other parties.</p><p>There are 4 main ways that the authorization grant can happen, according to the specification. We will go through each method individually, to understand. But I must note that these 4 methods are not the only methods that the authorization grant can happen. There’s the possibility for extension grant types. So if you don’t like any one of the below 4, just make yourself a new grant!</p><p>Also, please note that I will not go into detail about these grant types. I will rather give you a high level understanding on how everything works. The flow diagrams are obtained from the specification itself, to keep the originality.</p><h3>Authorization code grant</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8trrLAmoA4jAmed7" /></figure><p>This grant requires the involvement of a user-agent, which is most of the time a web browser, to mediate the interactions in between the authorization server, client and the resource owner. It is optimized for confidential clients. For this flow to happen, the client must be registered with the authorization server previously, and must have a unique client identifier (Client ID) issued by the authorization server.</p><p>A: The client initializes the code flow by interacting with the user-agent. The user-agent then sends the Client ID of the client and the redirection URI to which the authorization code must be sent to, to the authorization server.</p><p><strong>Note: </strong>Here, the endpoint of the authorization server which is reached by the user-agent is the authorization endpoint. There are 2 main endpoints in the authorization server, the authorization endpoint and the token endpoint.</p><p>B: The authorization server requires the consent of the user whether to give the client access or not. Also it requires the fact that, if the client is given access, to which resources exactly it must be given access to. For this purpose, the user-agent prompts the resource owner to authenticate him or herself and to specify which resources must be given access to. Then the user-agent provides that permission information to the authorization server.</p><p>C: After processing the resource owner authentication result and the permissions granted, the authorization server generates an authorization code specifically for the client and sends it to the client via the user-agent. By this step, the preliminary steps of the authorization code grant are over.</p><p>D: The client can now send the received authorization code directly to the authorization server. It does so, requesting an access token which can be presented to the resource server for accessing the authorized resources.</p><p>E: The authorization server processes the request and generates an access token which suits the authorized access, and sends it back to the client. Optionally, a refresh token can also be sent, to be used in case the original access token is expired. Then the client can request for a new access token by presenting the refresh token. Authorization server then will send a new access token, with another refresh token as well. These tokens are issued from the token endpoint of the authorization server.</p><p>Now, these steps are the steps followed if the resource owner authenticates correctly and gives the permission to either all or a few of the resources requested. But there are two cases where this flow is not followed accordingly.</p><ol><li>If the redirection URI is missing, invalid or mismatching</li><li>If the client ID is missing or wrong</li><li>Even though client ID is correct, but the client secret is wrong</li><li>If the resource owner denies the access request</li></ol><p>In those cases the authorization server sends an error response to the client, according to the type of issue.</p><h3>Implicit grant</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GC2p1Kwm-jNXODdL" /></figure><p><strong>Note: </strong>We must keep in mind that each of these grants represent certain situations. They are not mere options which we can fit into any situation. The implicit grant is optimized for public clients.</p><p>The main difference between implicit and authorization code grants is that implicit directly receives an access token as a result of the authorization request, whereas the authorization code grant gives an authorization code back to the client.</p><p>A: The client starts the flow by sending the authorization server its client ID and the redirection URI, so that the authorization server knows which client it was started from and where exactly (to which URI) it has to send the access token to. This is done via a user-agent.</p><p>B: Then in the same way as in authorization code grant, the resource owner authenticates him or herself and gives the necessary permissions.</p><p>C: From here onwards, we assume that the resource owner grants access. The authorization server directs the user-agent to the client (to the redirection URI provided earlier). The redirection URI includes the access token in the URI fragment.</p><p>D: Saving the URI fragment locally, the user-agent sends a request to the web-hosted client resource with the redirection URI without the fragment.</p><p>E: The web-hosted client then processes the request and creates a script which can extract the access token from the URI fragment. Then it embeds the script in an HTML document and sends it back to the user-agent.</p><p>F: The user-agent then runs the script obtained and extracts the access token from the URI fragment.</p><p>G: Then the access token is passed to the client. No refresh tokens are issued in this grant.</p><p>In the same way as earlier, if an error condition occurred, an error response is sent to the client accordingly.</p><h3>Resource owner password credentials grant</h3><p>This grant is also used in special situations where the resource owner has a direct trust relationship with the client. The client is provided with the credentials of the resource owner for the authorization server. Since the major part of risk is borne by the resource owner when enabling this grant type, the process is relatively simpler than the previously discussed grants. But this is a highly risky method, which should only be used if any previous grants are not possible to be used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/0*tOA5UFLsnZnKFp_n" /></figure><p>A: The resource owner simply provides the client with his/her credentials.</p><p>B: The client acts as the resource owner himself, provides the resource owner credentials and requests for an access token.</p><p>C: The client is given an access token with optionally a refresh token as well.</p><h3>Client credentials grant</h3><p>Here, first it should be arranged with the resource owner and the authorization server on which clients are given access through this grant. This enables the client to get an access token by using the <strong>client’s</strong> credentials. It is recommended during machine to machine interactions. It is somewhat like the client is a representative of the resource owner. There is no interaction with the resource owner at all in this flow. Resource owner’s interaction is done before the flow starts. The exact way that the previous arrangement is done is not specified in the specification.</p><p><strong>Reminder:</strong> The client has to register itself with the authorization server prior to the flow in all of these grants. So the authorization server already has a unique client ID and a client secret (credentials), dedicated to the client.</p><p>So in some ways, the resource owner password credentials grant and the client credentials grant is quite similar. In this also, the major part of the risk is borne by the resource owner. So the flow is quite simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/0*yhDDp5boSYt9DRCY" /></figure><p>A: The client authenticates itself to the authorization server and requests for an access token.</p><p>B: The authorization server processes the request and provides the client with an access token. In this grant also, a refresh token is not issued, similar to the implicit grant.</p><p>In addition to these main grants, the authorization server supports any extension grant types as well.</p><h3>References</h3><ul><li>OAuth2.0 Specification: <a href="https://www.rfc-editor.org/rfc/pdfrfc/rfc6749.txt.pdf">https://www.rfc-editor.org/rfc/pdfrfc/rfc6749.txt.pdf</a></li><li>OAuth2.0 for dummies (Previous article): <a href="https://medium.com/@malshanranawella/oauth2-0-for-dummies-4292a5a0bcde">https://medium.com/@malshanranawella/oauth2-0-for-dummies-4292a5a0bcde</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1925b76bd2c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OAuth2.0 for dummies — Introduction to OAuth2.0]]></title>
            <link>https://medium.com/@malshanranawella/oauth2-0-for-dummies-4292a5a0bcde?source=rss-c79ef72536e4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4292a5a0bcde</guid>
            <dc:creator><![CDATA[Malshan Ranawella]]></dc:creator>
            <pubDate>Mon, 23 Jan 2023 02:56:22 GMT</pubDate>
            <atom:updated>2023-01-27T06:23:30.273Z</atom:updated>
            <content:encoded><![CDATA[<h3>Content</h3><p>In this article, I expect to cover the following facts.</p><ol><li>What is OAuth2.0 ?</li><li>OAuth2.0 authorization flow (from user’s point of view)</li><li>OAuth2.0 Authorization Flow (actual operation)</li></ol><h3>What is OAuth2.0 ?</h3><p>Before we dive into OAuth2.0 Authorization flows, we will first rush through what OAuth2.0 is and why it is important for us to learn.</p><p>OAuth2.0 is an Authorization protocol which is widely used in the industry today. If you ask the question “What’s an Authorization protocol?”, I’ll be in trouble. But in case you do, here’s the simple answer.</p><p>We daily use applications which require us to obtain data from other applications that we have ownership of. Let’s take an example scenario. Bob needs to use an online dating application which wants to take some basic information such as his profile picture, birthday, sex, education and occupation from our facebook account. This is a very convenient method to provide information to the dating app instead of filling out forms, but it’s also risky, since facebook accounts can contain other sensitive information which we wouldn’t like to expose to others. Therefore, Bob wants the dating app to only retrieve the information that he allows.</p><p>OAuth2.0 is a protocol or predefined set of standards which can be used in such a scenario. There are 4 main roles in OAuth2.0 basic authentication flow. Client application, Resource owner, Resource server and Authorization server.</p><p>In our example scenario, these roles map into the following entities.</p><p>But I’m altering the previous scenario a little bit, to separate the roles clearly.</p><ol><li>Client application — Dating app</li><li>Resource owner — Bob</li><li>Resource server — ‘Personal Info’ app, which contains information about Bob</li><li>Authorization server — WSO2 Identity Server (I’ll explain who this guy is)</li></ol><p>Authorization server is simply the intermediary which regulates the OAuth2.0 flow and ensures Bob that the authorization flow will be carried out responsibly.</p><p>I omitted the use of facebook in our example, since facebook has the functions of both resource server and authorization server, which will confuse you when trying to understand the flow clearly.</p><h3>OAuth2.0 authorization flow (from user’s point of view)</h3><p>Now we have identified the roles of OAuth2.0 protocol, relative to our example scenario. Now we will see how a user sees this flow from outside. Later we will dive into what’s happening inside. The following are the steps.</p><p>Let’s assume that WSO2 Identity Server has already been installed in the environment, and the dating application is already registered with WSO2. In case this sentence doesn’t make much sense, I will explain it later.</p><ul><li>Bob opens the dating application</li><li>Bob sees 2 options to provide the app with personal information (Fill out a form, Obtain information from ‘Personal Info’ app)</li><li>Bob selects the 2nd option</li><li>Bob is shown a login page saying ‘WSO2 IDENTITY SERVER’ on the top, with fields ‘Username’ and ‘Password’ to fill</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MoyiKvV0i3767QAU" /><figcaption>Sign in page for authorization server</figcaption></figure><ul><li>Bob logs in, giving his WSO2 credentials</li><li>Bob is prompted with a page similar to the following image which asks Bob’s consent to give the dating app to receive the information (profile picture, birthday, sex, education and occupation) from his ‘Personal Info’ app profile.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/0*yJby-8L19AYIrhqj" /><figcaption>Consent page</figcaption></figure><ul><li>Bob clicks “Approve”</li><li>Then the dating app processes his information and finds him a suitable companion before valentine’s day! Rest is history.</li></ul><h3>OAuth2.0 Authorization Flow (actual operation)</h3><p>Now that we understand how the user sees this flow, it’s time to dive into how this operation works from the inside. For this, we need to use a flow diagram from the original specification of the OAuth protocol. (You will find more decent diagrams if you just googled. But I wanted to keep the originality).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/0*e0CZvEdKEPYFkyQo" /></figure><p>Some words may be gibberish to you. Well that’s why I’m writing this article!</p><p>Let me explain.</p><ul><li>A : When Bob opens the application and selects the option of retrieving information from the ‘Personal Info’ app, the client (dating app) sends an ‘Authorization Request’ to the resource owner (Bob). Bob then enters his WSO2 credentials, logs in and gives his consent to retrieving certain data.</li></ul><p>(This process preferably goes through the authorization server (WSO2) although it is not mentioned specifically in the above diagram. This will be explained in a later article.)</p><ul><li>B : Then the client receives an authorization grant, which contains a credential (code) that can confirm the authorization of the resource owner. There are several types of authorization grants. If the authentication fails, the client receives an error code.</li><li>C : The client presents the received authorization grant to the authorization server (WSO2), which processes the authorization code.</li><li>D : After processing the authorization code, the authorization server sends an access token, which contains information about what information the resource server should provide for the client. Optionally, a refresh token can be also sent.</li></ul><p>(A refresh token is a token which can be used to obtain a new access token when the previous access token is expired.)</p><ul><li>E : The client presents the received access token to the resource server (‘Personal Info’ app)</li><li>F : The resource server processes the token and provides the client with the requested resources (profile picture, birthday, sex, education and occupation). If the token is invalid or erroneous, the client will receive an error code.</li></ul><p>This is the basic high-level view of the OAuth2.0 authorization flow. More information about the grant types and the grant flows are required to obtain a more detailed understanding of the flow. I hope to cover those details in my next article, on obtaining authorization from the resource owner.</p><h3>References:</h3><ul><li><a href="https://www.rfc-editor.org/rfc/pdfrfc/rfc6749.txt.pdf">Internet Engineering Task Force (IETF) D. Hardt, Ed. Request for Comments: 6749 Microsoft Obsoletes: 5849 October 20</a></li><li><a href="https://is.docs.wso2.com/en/latest/">WSO2 Identity Server Documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4292a5a0bcde" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>