Filters in ASP NET Core - what are they and how to use them

Filters in ASP NET Core - what are they and how to use themASP NET Core comes with a concept of filters. Filters intercept the stages of the MVC pipeline and allows us to run code before/after their executions. They are meant to be used for cross-cutting concerns; logics which is required accross the whole application, generally not business oriented. One example is authorization where in a Web API, we would use to prevent unauthorized request to execute the code in our controllers. In order to do that we would have a filter at the entrance of the pipeline. In fact, ASP NET Core has predefine stages, the diagram can be found on the documentation Another example of a cross-cutting concern would be for logging and timing functions. While the concept of filters is easy to understand, the way to implement those aren’t always straight forward, especially when the filter instantiation itself requires simple objects. In or…

Different types of authorization in ASP.NET Core

Different types of authorization in ASP.NET CoreLast week I touched on how we could authenticate users using Resource Owner Password flow with identity server. Authentication is the act of taking the information provided and verifying the “identity” of the user, ensuring that Alice (our beloved example user) is who she “claims” to be.
In the program itself, we take her credentials and verify it and create an identity stating that the user is Alice and has claims A, B and C.Authentication is the first part of the access security, the second part is the authorization. The difference being that for authorization, we know who the user is, what we are verifying is if Alice is allowed to perform what she is trying to perform. The easiest example is the difference between user access and admin access commonly seen in software where users are authenticated but aren’t authorized to perform all the actions available in the system.ASP.NET Core comes with a set of useful tools to perform authoriz…

Resource owner password flow with Identity Server 4 and ASP.NET core

Resource owner password flow with Identity Server 4Few week ago I described how to build a custom Jwt authentication.
Today I will show how we can use Identity server together with Resource owner password flow to authenticate and authorise your client to access your api.This post will be composed by 3 parts:1. Identity server 2. Protect an api 3. Configure a client The full source code is available on my GitHub Identity serverIdentity server is a framework which implements Open ID Connect and OAuth 2.0 protocols.
The purpose of Identity server is to centralize the identity management and at the same time decouple your api(s) from authentication and authorization logic.
Centralizing has many advantages:If you have multiple apis, you can hold your identities in a common placeIf you have multiple apis, it provides single sign on - user only sign in into one client and is automatically sign in in all apis. This works because all clients …

Cost of living in London

Cost of living in LondonIn 2015, I decided to relocate from Singapore to London. At the time I had no idea about the cost of living, the places where I should rent and places where the groceries would be the cheapest. Fast forward to today, March 2017, I moved back from London to Singapore. I stayed around London for more than a year and a half and while I was there, I kept an extremely close look to every in and out from my bank account. I even created an app Expense King to track my expenses coming out from my bank account.Today I would like to share what I wish someone would have shared before I relocated, a post about cost of living in London. This post will be composed by 5 parts:1. Situation 2. Recurring expenses 3. Rent a place 4. Bills 5. Grocery shopping1. SituationMy fiancee and I lived in a one bedroom apartment. The apartment was located at Pontoon Dock on the east of Canary Wharf with access to the DLR (but not the underground). It is about 40min by DLR+underground from B…

Create a responsive navbar with flexbox and boostrap v4

Create a navbar responsive display with flexbox and boostrap v4Last week we saw how to setup vscode to compile sass. Today we will see how we can compile bootstrap sass files together with our own sass and define a grid layout for the collapsed nav in smaller screen using flexbox.FlexboxBootstrap sass media directiveBuild the nav styleWe will be creating the style for the following navbar:1. FlexboxFlexbox allows to control how elements are rendered in a responsive layout.
We can control precisely how the space available is occupied by elements together with the order of appearance.
There’s few settings for it which are applied to the container and the elements within the container.Refer to MDN documentation if you want more explanation this tutorial, I will only use the following css properties:For the container:display: flex; flex-flow: row wrap; display:flex is used to specify that …

Setup vscode to work with sass effortlessly

Setup vscode to work with sass effortlesslyWriting sass is very easy with code. Today we will see how we can leverage some NPM packages to compile SASS to CSS, watch file changes and live update the browser for an effortless style development. This post will be composed by 3 parts: 1. Setup vscode task 2. Create a Gulp build script 3. Use live-server for live reload The tasks are from the example of vscode documentation to compile sass Setup vscode taskTo use code tasks, we need to create a tasks.json file under the hidden /.vscode folder.| - .vscode - tasks.json | - style.scss | - index.html The tasks allow us to execute programs by selecting from the search bar CMD + shift + P, Run build task. If a default task is set, it can directly be triggered by CMD + shift + B.As a first example we can start by installing the sass compiler with node-sass.npm install -g node-sass less And create a tas…

How to make a sticky navbar using Bootstrap

How to make a sticky navbar using BootstrapToday I will demonstrate one way to achieve a sticky navbar in Bootstrap v4 using fixedsticky.
This post will be composed by three parts:1. Get the librairies 2. Page without the nav sticking 3. Make the nav stick 1. Get the librairiesAs mentioned in the introduction, we will be using fixedsticky and bootstrap v4.
We start first by getting those via bower:Bootstrap v4bower install bootstrap#v4.0.0-alpha.6 Fixed-stickybower install filament-sticky You should then have it locally in your bower folder.2. Page without the nav stickingWe build a sample page without sticky.<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Example</title> <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" /> <style> .content { background-color: rgba(0, 0, 255, 0.21); height: 2000px; margin: 1…