Implicit flow with Identity Server and ASP NET Core

Implicit flow with Identity Server and ASP NET CoreFew months ago I talked about Resource owner password flow with Identity Server and ASP NET Core. But as mentioned in multi places, ROP is an anti pattern when it comes down to a correct implementation of Open ID Connect. A more appropriate flow for API <-> SPA authentication is the Implicit flow. Today we will see how we can implement it in 5 steps:1. Configure Identity server 2. Configure Identity server Login 3. Protect our Api 4. Log in from the JS client 5. Configure Identity server Consent 1. Configure Identity serverWith the Implicit flow, all the authentication process happens through the browser. The user will be redirected to a login page delivered by the Identity server, then the redirect authentication will all taken place within the Identity server.
For our example, we will be using the test users and will only be demonstrating login.We start first by creating a ASP NET Core 1.1 web application which will host our I…

Manage assets and static files with Angular CLI

Manage assets and static files with Angular CLIOne of the easiest way to build Angular applicationns is through Angular CLI. Using the ng serve command will build and serve the whole application or we can use ng build to output the app into the outputDir folder, but there might be occasions where we need to serve files which aren’t part of the Angular process, like static files or images. Those files are referred to as assets. Today we will see how we can configure Angular CLI to copy assets to the output directory and what sort of configuration is available.1. Copying assets 2. Glob file, input, output 1. Copying assetsFiles which need to be served by AngularCLI must be registered under assets in the .angular-cli.json file.
When we first boostrap a project, there are two places registered under assets:{ "apps": [{ "root": "src", "outDir": "dist", "assets": [ "assets", "fav…

Create type extensions in Typescript

Create type extensions in Typescript Typescript is a superset of JavaScript. It provides type safety on top of the JS libraries. Type safety is an important part of the development experience as it allows us to detect problems early thanks to the compiler preventing us from writing broken code.
JS being dynamic it is very easy to extend since anything is assumed to exist. In the context of extension methods, the only step needed is to add the method to the prototype of the class and we are done.
Typescript kept that flexibility but in order to provide type safety on top of it, extra steps are needed.Today I would like to share how we can create extension methods in Typescript by extending existing types. This post will be composed by 2 parts:1. Extending a core type 2. Extending a library type 1. Extending a core typeThe first thing we need to do is create the function which will become the extension.
Here we will create a sumBy function to extend the Array core type.function sumBy&l…

Implement a breadcrumb in Angular with PrimeNg

Implement a breadcrumb bar in Angular with PrimeNgA breadcrumb bar is a very important piece of any website. It gives an idea where the user is currently in, from where the user landed on this page and finally allow the user to navigate back to any steps wanted.
I like to call it an “enhanced version of the URL path”. The URL path in itself has the information but it might, at time, not be human readable. That is where the breadcrumb become indispensable.
I showed few features of PrimeNg in my previous posts about building an inline form and about building a tree structure. It turns out that they also provide a Angular friendly breadcrumb component.
Today we will see how we can make use of the breadcrumb component together with the Angular router to provide a breadcrumb bar.
This post is composed by 3 parts:1. PrimeNg Breadcrumb component 2. Breadcrumb service, parent/child component communication 3. Use the breadcrumb service together with the PrimeNg Breadcrumb component 1. PrimeNg …

Difference between CanActivate and CanActivateChild in Angular Router

Difference between CanActivate and CanActivateChild in Angular RouterFew weeks ago I spoke about the functionality of the Angular Router It was a brief overview of all the router features but one of the feature was not totally explain, the CanActivate feature. From there a question emerged, what is the difference between CanActivate and CanActivateChild?. Today I will answer this question and at the same time discussing extra behaviours of the router with this post composed by 4 parts:1. Refresh on CanActivate and CanActivateChild 2. Difference 3. Some considerations 4. Component reusability with router 1. Refresh on CanActivate and CanActivateChildAs we saw in my previous post, CanActivate is a interface with a single function canActivate(...).@Injectable() export class GuardTest implements CanActivate, CanActivateChild { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { return…

Inline form Angular and PrimeNg

Inline form Angular and PrimeNgInline form are used to edit portion of long forms. This makes the process of editing a long form less tedious and less error prone as the focus is on a small portion.
The process of allowing the fields to be editable can be hard as the state of the field currently selected for editing needs to be tracked and the right input fields must be shown.
Angular offers convenient directives to handle showing and hiding elements, together with ngrx store to handle the state and PrimeNg UI components, it is an ideal solution to build inline forms. In this post we will see how to build a user friendly form in 3 steps: 1. Build a diplay of segmented forms data 2. Build the segmented forms 3. Bind the display edit buttons to the forms displays This is a preview of what we will be building:The full source code is available on my GitHub.1. Build a diplay of segmented forms dataFor the form we will be using Bootstrap, PrimeNg and FontAwesome.
Bootstrap provides univer…

Easily ensure that data are loaded with Ngrx store and router guards in Angular

Easily ensure that data are loaded with Ngrx store and router guards in AngularLast month, I describe a way to manage global state with ngrx/store. With the store, we manage the overal state of the Angular application in a single global object. Loading and retrieving data affects a single main state object. This simplication gives opportunities to other simplications. Like for example, if we loaded once a collection of items, we wouldn't need to reload it when a component is displayed as it is available in the state. But how can we ensure that and more importantly how can we keep the check logic in a maintainable state. Here enter the Angular router route guard which I also described few weeks ago in my post on how we could create and manage routes with the Angular router. Today I will show how we can use both together to solve the issue of ensuring data is loaded before displaying a route. This post will be composed by 3 parts: 1. Extand the previous sample to load users 2. Rout…