Skip to main content


Showing posts from April, 2017

How to do JWT Authentication using a DelegateHandler in WEBAPI

According to AuthO, JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA.

In using jwt, the information in the token, is the only thing required to authenticate a user. so our main here is to validate the information in the token and convert jwt to IPrincipal object. Iprincipal object, according to msdn, simply means the functionality of a principal object, what then is a principal object, A principal object represents the security context of the user on whose behalf the code is running, including that user's identity (IIdentity) and any roles to which they belong. To make this JWT authentication to work, we must utilize a message handler, a message handler is simply a class that receives an HTT…

Top 2 ways to pass parameters to a view component

View components is a feature of ASP.NET Core MVC, that’s similar to partial view and child actions, one cool thing about view component it allows you to create reusable components with or without logic.
The purpose of this post is to show you how to pass view component as a parameter when invoking it from view and controller.
Another  cool thing about View Components is that it separates the logic of which markup to display from the markup itself. It’s a class that inherits from View component and implements Invoke and InvokeAsync Methods, the return type can vary, and that depends on largely what you intend to render.
Example of Simple View Component
public class ItemViewComponent : ViewComponent
   public IViewComponentResult Invoke()
       return View();
To use the View Component, we have to invoke the Item View component from _Layout.cshtml