<?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[Lanka‘s Blog - Medium]]></title>
        <description><![CDATA[Dev | .NET | JavaScript - Medium]]></description>
        <link>https://medium.com/lankapura?source=rss----ac58d28ce54e---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Lanka‘s Blog - Medium</title>
            <link>https://medium.com/lankapura?source=rss----ac58d28ce54e---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 09:48:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/lankapura" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Webpack 4 Resources]]></title>
            <link>https://medium.com/lankapura/webpack-4-blog-post-collection-2f09318ab012?source=rss----ac58d28ce54e---4</link>
            <guid isPermaLink="false">https://medium.com/p/2f09318ab012</guid>
            <category><![CDATA[node]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Priyantha Lankapura]]></dc:creator>
            <pubDate>Mon, 26 Feb 2018 06:54:33 GMT</pubDate>
            <atom:updated>2018-02-27T04:06:05.678Z</atom:updated>
            <content:encoded><![CDATA[<p>Webpack 4 : Legato is out with a lot of new features. Here’s a curated list of related blog posts that I found.</p><ul><li><a href="https://medium.com/webpack/webpack-4-released-today-6cdb994702d4">🎼webpack 4: released today!!✨</a>by <a href="https://medium.com/u/393110b0b9e4">Sean T. Larkin</a></li><li><a href="https://github.com/webpack/webpack/releases/tag/v4.0.0-beta.0">Webpack 4 release notes</a></li><li><a href="https://medium.com/@sokra/latest">Webpack series</a> by <a href="https://medium.com/u/cccc522e775a">Tobias Koppers</a></li><li><a href="https://auth0.com/blog/webpack-4-release-what-is-new/">Webpack 4.0 Release: What’s New?</a> by <a href="https://medium.com/u/9ef9638b3092">Auth0</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f09318ab012" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lankapura/webpack-4-blog-post-collection-2f09318ab012">Webpack 4 Resources</a> was originally published in <a href="https://medium.com/lankapura">Lanka‘s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Copy to Clipboard Using Javascript]]></title>
            <link>https://medium.com/lankapura/copy-to-clipboard-using-javascript-b36b972366f?source=rss----ac58d28ce54e---4</link>
            <guid isPermaLink="false">https://medium.com/p/b36b972366f</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Priyantha Lankapura]]></dc:creator>
            <pubDate>Mon, 29 Jan 2018 10:01:22 GMT</pubDate>
            <atom:updated>2018-01-29T10:01:28.542Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wanted to copy something to the clipboard programmatically using JavaScript? Here’s how to do it for few different use cases.</p><h3>Simple Use Cases</h3><p>We can use following simple function to copy any variable to clip board.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35043cf954d8efcf4004bae7e78f3fae/href">https://medium.com/media/35043cf954d8efcf4004bae7e78f3fae/href</a></iframe><h3>Advanced Use Cases</h3><p>We can use <a href="https://clipboardjs.com/">clipboardjs</a> to implement advanced requirements. You can set it up with few lines of code, it doesn’t have any external dependencies, and it’s only 3KB. More examples can be found on <a href="https://github.com/zenorocha/clipboard.js/tree/master/demo">GitHub</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4adb6339fbc0123027f57903eb9e1fa2/href">https://medium.com/media/4adb6339fbc0123027f57903eb9e1fa2/href</a></iframe><h3>Important</h3><ul><li>Copy commands triggered from document.execCommand() will only work if the event is dispatched from an event that is trusted and triggered by the user.</li><li>Browser compatibility</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*K-59NQ_gqxTGLs_nlJm1yw.png" /></figure><p><em>Originally published at </em><a href="http://www.lankapura.net/blog/2018/01/29/JavaScript-Copy-To-Clipboard"><em>lankapura.net</em></a><em> on January 29, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b36b972366f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lankapura/copy-to-clipboard-using-javascript-b36b972366f">Copy to Clipboard Using Javascript</a> was originally published in <a href="https://medium.com/lankapura">Lanka‘s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular/Asp.Net Core Server Side Rendering for Authenticated Users]]></title>
            <link>https://medium.com/lankapura/angular-server-side-rendering-for-authenticated-users-a021627fd9d3?source=rss----ac58d28ce54e---4</link>
            <guid isPermaLink="false">https://medium.com/p/a021627fd9d3</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[authentication]]></category>
            <dc:creator><![CDATA[Priyantha Lankapura]]></dc:creator>
            <pubDate>Thu, 14 Dec 2017 04:56:55 GMT</pubDate>
            <atom:updated>2017-12-14T07:01:24.260Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HMdu_LFqR9EjIvsxrWIQ3g.png" /></figure><p>This is a follow up to “<a href="https://medium.com/@lankapura/angular-asp-net-core-authentication-with-identity-server-4-65db6b9f7c2a">Angular/Asp.Net Core Authentication with Identity Server 4</a>.” I’ll be using the same source code in this post.</p><p>Once you set up authentication in the Angular application, you will notice that the server side renderer no longer returns pre-rendered HTML.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fi.imgur.com%2FDkbH2ix.mp4&amp;src_secure=1&amp;url=https%3A%2F%2Fi.imgur.com%2FDkbH2ix.gifv&amp;image=https%3A%2F%2Fi.imgur.com%2FDkbH2ix.gif%3Fnoredirect&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=video%2Fmp4&amp;schema=imgur" width="1902" height="946" frameborder="0" scrolling="no"><a href="https://medium.com/media/50188b7b97c3af37bfdcf66cc1f7ff8b/href">https://medium.com/media/50188b7b97c3af37bfdcf66cc1f7ff8b/href</a></iframe><p>This is because angular-oauth2-oidc is using browser session storage to store the OAuth token that received from the Identity Server. Therefore, the server pre-renderer can’t make authenticated HTTP requests, since session storage is not available during the server pre-rendering step. So how are we going to send the OAuth token to the server side?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0_r-fdKvB75wkkqOdPSNw.png" /><figcaption>OAuth Token in Session Storage</figcaption></figure><p>By using good old <strong>Cookies!</strong></p><p>angular-oauth2-oidc has a OAuthStorage interface that we can use to implement and define our own token storage implementation. But we need different implementations for client side and server side. This is because, even though we can access cookies directly on the client side, it is not possible to do so during server pre-rendering due to the nature of how pre-rendering works inside ASP.NET core SPA services. Could there be a way to access cookies during pre-rendering?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c391bba60277971abad7238c7ec8d3b8/href">https://medium.com/media/c391bba60277971abad7238c7ec8d3b8/href</a></iframe><p>ASP.NET core has provided the ‘asp-prerender-data’ prop to pass any data to the server renderer function. Using that, we can retrieve the same parameter and pass it to Angular as a provider which can be resolved in any Angular service or component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/571a4f5983a4fee95eda7ba377a58612/href">https://medium.com/media/571a4f5983a4fee95eda7ba377a58612/href</a></iframe><p>The next step is to implement the Token store service for server renderer. Here, we can resolve ‘cookies’ which contains cookies of the current request. So when the server renderer requests the OAuth token, it can be retrieved from cookies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50d3b06eea20b87aa98cdbd7499fff5c/href">https://medium.com/media/50d3b06eea20b87aa98cdbd7499fff5c/href</a></iframe><p>Finally, we need to tell Angular to use our token store implementations for OAuthStorage interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91b8a6841fdf8436ef2c9c57b1ac5b24/href">https://medium.com/media/91b8a6841fdf8436ef2c9c57b1ac5b24/href</a></iframe><p>Once the user is authenticated from Identity server, the OAuth token should be available to the server renderer now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bNDdNMD6tveAgfdZ63NZEA.png" /><figcaption>OAuth Tokens in Cookies</figcaption></figure><p>Therefore, we should be able to see pre-rendered HTML during the initial loading of our application.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fi.imgur.com%2FPCTYMst.mp4&amp;src_secure=1&amp;url=https%3A%2F%2Fi.imgur.com%2FPCTYMst.gifv&amp;image=https%3A%2F%2Fi.imgur.com%2FPCTYMst.gif%3Fnoredirect&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=video%2Fmp4&amp;schema=imgur" width="1902" height="946" frameborder="0" scrolling="no"><a href="https://medium.com/media/7985ff19aec8d1349b4150e320de2122/href">https://medium.com/media/7985ff19aec8d1349b4150e320de2122/href</a></iframe><p>Complete source code can be found on github.</p><p><a href="https://github.com/lankaapura/Angular-AspNetCore-Idsvr">lankaapura/Angular-AspNetCore-Idsvr</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a021627fd9d3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lankapura/angular-server-side-rendering-for-authenticated-users-a021627fd9d3">Angular/Asp.Net Core Server Side Rendering for Authenticated Users</a> was originally published in <a href="https://medium.com/lankapura">Lanka‘s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular/Asp.Net Core Authentication with Identity Server 4]]></title>
            <link>https://medium.com/lankapura/angular-asp-net-core-authentication-with-identity-server-4-65db6b9f7c2a?source=rss----ac58d28ce54e---4</link>
            <guid isPermaLink="false">https://medium.com/p/65db6b9f7c2a</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Priyantha Lankapura]]></dc:creator>
            <pubDate>Wed, 13 Dec 2017 09:55:55 GMT</pubDate>
            <atom:updated>2017-12-14T05:05:27.911Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HMdu_LFqR9EjIvsxrWIQ3g.png" /></figure><p>Setting up Authentication for applications can be intimidating. Usually it doesn’t involve writing a lot of code, because <a href="https://github.com/IdentityServer/IdentityServer4/graphs/contributors">good</a> <a href="https://github.com/openiddict/openiddict-core/graphs/contributors">folks</a> <a href="https://github.com/aspnet/Identity/graphs/contributors">like</a> <a href="https://github.com/keycloak/keycloak/graphs/contributors">these</a> <a href="https://github.com/manfredsteyer/angular-oauth2-oidc/graphs/contributors">have</a> <a href="https://github.com/jaredhanson/passport/graphs/contributors">invested</a> <a href="https://github.com/oauthjs/node-oauth2-server/graphs/contributors">their</a> time to do all the hard work for us. As a result, most of the time we are dealing with configurations. Setting up authentication for Angular SPA is no different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*hYqQ_YFSxoP_rHEb.jpg" /></figure><p>This post covers the following topics:</p><ol><li><em>Integrating Angular SPA with Identity Server Implicit Flow</em></li><li><em>Configuring Asp.NET core web API to validate tokens</em></li></ol><p>This post doesn’t cover setting up Identity Server. I’ll be using this <a href="https://demo.identityserver.io/">Identity Server demo site</a> in my sample since it can be easily accessed and integrated. Read <a href="https://www.scottbrady91.com/Identity-Server/Getting-Started-with-IdentityServer-4">this post </a>by <a href="https://twitter.com/scottbrady91">Scott Brady</a> to learn more about Identity Server.</p><h4><strong>Identity Server Implicit Flow</strong></h4><blockquote>The implicit grant type is optimized for browser-based applications. Either for user authentication-only (both server-side and JavaScript applications), or authentication and access token requests (JavaScript applications).</blockquote><blockquote><a href="http://docs.identityserver.io/">http://docs.identityserver.io</a></blockquote><h4>Create Angular Project</h4><p>Let’s create an angular application using dotnet CLI.</p><pre>dotnet new angular</pre><p>Default template has old angular packages. So, let’s update them to their latest versions. We will be using Angular 4.4.6 Since the <a href="https://github.com/aspnet/JavaScriptServices/issues/1288">AspNet core template doesn&#39;t support Angular 5 properly</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J5ARbeogJAhS44NByjCS4g.png" /><figcaption>Comparison between default package.json and updated package.json</figcaption></figure><h4>Angular OAuth Packages</h4><p>Identity Server has provided a JavaScript plugin <a href="https://github.com/IdentityModel/oidc-client-js">odic-client-js</a> to integrate browser based applications. However, it was not implemented targeting modern browser-based applications such as Angular and React. So you will run in to issues when using server-side rendering and AoT compilation. Thankfully, the community has come forward with solutions! There are two <a href="https://openid.net/certification/">OpendID Certified</a> plugins for Angular:</p><ul><li><a href="https://github.com/manfredsteyer/angular-oauth2-oidc">angular-oauth2-oidc by</a> <a href="https://medium.com/u/acb3f1945710">Manfred Steyer</a></li><li><a href="https://github.com/damienbod/angular-auth-oidc-client">angular-auth-oidc-client</a> by <a href="https://damienbod.com/">Damien Bowden</a></li></ul><p>I chose angular-oauth2-oidc since it supports password flow as well.</p><pre>npm i angular-oauth2-oidc --save</pre><p>I had to install es-promise package to prevent build failure.</p><pre>npm install es6-promise --save</pre><h4>Angular-oauth2-oidc Setup</h4><p>Now that we have the base project, it’s time to configure angular SPA for identity server. First, we should import the OAuth Module and HttpClient Module to our application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3adb165beb5b32a493ef14af950d4e89/href">https://medium.com/media/3adb165beb5b32a493ef14af950d4e89/href</a></iframe><p>Then we should define Identity sever details.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac326a7f32504dc7f329868b5593e369/href">https://medium.com/media/ac326a7f32504dc7f329868b5593e369/href</a></iframe><p>Next, OAuth Module should be initialized using config object. We don’t need our application trying to connect to Identity Server and retrieve tokens during server pre-rendering, so everything is wrapped inside isPlatformBrowser code blocks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/674dfa4744d978b8582e01c65003ac8c/href">https://medium.com/media/674dfa4744d978b8582e01c65003ac8c/href</a></iframe><p>Now, how are we going to force users to log-in to our application?</p><h4>Setup Route Guard</h4><p>We can define a logic in a route guard to be validated before navigating to a requested route. Using a route guard, we can prevent users navigating to our application without a valid token.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fbcffc7554763dcfc6d07b3820c020a/href">https://medium.com/media/8fbcffc7554763dcfc6d07b3820c020a/href</a></iframe><h4>Setup OAuth Callback</h4><p>If you check the authConfig redirect URI, Identity server is configured to redirect to ‘/’ after a successful authentication attempt. It is important <strong>NOT</strong> to have an AuthGuard for that particular route. Otherwise the application won’t be able to retrieve the token from the query string, resulting in a redirect loop.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64bea4519b84f8adf4ac9abbd80d2547/href">https://medium.com/media/64bea4519b84f8adf4ac9abbd80d2547/href</a></iframe><p>Now we should be getting a token from Identity server. But how do we add it to our API requests and validate it from Web API side?</p><h4>Making HTTP Requests with OAuth Tokens</h4><p>We can use HTTP interceptor, that was introduced in Angular 4.3, to include the OAuth token in all HTTP requests. You might notice it resolves dependencies differently. The <a href="https://github.com/angular/angular/issues/18224">reason is a known issue</a> which makes circular dependencies between modules.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e126255f5a7c1aebfba70ae0373a9518/href">https://medium.com/media/e126255f5a7c1aebfba70ae0373a9518/href</a></iframe><h4>ASP.NET Core OAuth Token Validator</h4><p>Finally we need to validate OAuth tokens in the web server. That can be easily achieved using the Identity Server Access Token Validation package.</p><pre>dotnet add package IdentityServer4.AccessTokenValidation</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc026a447df9b2abd7ce3e8c3dfc6527/href">https://medium.com/media/bc026a447df9b2abd7ce3e8c3dfc6527/href</a></iframe><p>Now Angular SPA should be redirected to Identity server to authenticate, and should redirect back to angular SPA upon successful authentication.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fi.imgur.com%2FpCLiQkE.mp4&amp;src_secure=1&amp;url=https%3A%2F%2Fi.imgur.com%2FpCLiQkE.gifv&amp;image=https%3A%2F%2Fi.imgur.com%2FpCLiQkE.gif%3Fnoredirect&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=video%2Fmp4&amp;schema=imgur" width="1902" height="946" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a50d500dcd605b6d73aa7db0fe85169/href">https://medium.com/media/6a50d500dcd605b6d73aa7db0fe85169/href</a></iframe><p>Full source code can be found on <a href="https://github.com/lankaapura/Angular-AspNetCore-Idsvr/tree/edf1c542e4821b3b0a8976412afca7b917634a42">github</a>.</p><p><a href="https://github.com/lankaapura/Angular-AspNetCore-Idsvr/tree/edf1c542e4821b3b0a8976412afca7b917634a42">lankaapura/Angular-AspNetCore-Idsvr</a></p><p>Next, how do we use server side rendering for Authenticated users? Find out in <a href="https://medium.com/lankapura/angular-server-side-rendering-for-authenticated-users-a021627fd9d3">my next post</a>.</p><p><a href="https://medium.com/lankapura/angular-server-side-rendering-for-authenticated-users-a021627fd9d3">Angular/Asp.Net Core Server Side Rendering for Authenticated Users</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65db6b9f7c2a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/lankapura/angular-asp-net-core-authentication-with-identity-server-4-65db6b9f7c2a">Angular/Asp.Net Core Authentication with Identity Server 4</a> was originally published in <a href="https://medium.com/lankapura">Lanka‘s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>