Add identity to existing aurelia .net core project - c#

I have followed this guide https://github.com/aspnet/JavaScriptServices to create an asp .net core 2 aurelia project.
But I would like to add identity to this project but I can't find a good guide how to do it...
Anyone who has done this or have an idea where I can start?
Best regards
Andreas

Edit: since I felt this question requires more explanation, I wrote a blog post and a sample on GitHub.
Depending on how far you want to go down the rabbit hole, you could either:
Reimplement the whole ASP.NET Core Identity UI in Aurelia.
Have the default implementation of Identity in MVC.
Have something in between, like have login only implemented in Aurelia and the rest (registration, forgot password, management, etc) implemented in MVC.
For most of my projects, I simply create a new ASP.NET Core MVC app with Identity and then add Aurelia to it (within the same or separate project). Security is hard and it's easy to mess something up. If you leave the default Identity implementation, you can serve Aurelia app via default route (/home/index) and have [Authorize] attribute on the controller or action method to require users to log in before accessing it.
At one point I was thinking about #1, to create a sample app (or even a .NET Core template) with entire Identity UI re-implemented in Aurelia and blog about it, but of course, time was an issue and I never started it.
So, my suggestion is to go with #2.
If you are on ASP.NET Core 2.1 (and you really should upgrade to it, since 2.0 end of life comes in a few months), there are some Identity changes that might help you. Identity in 2.1 is implemented as a separate Razor Class Library, which is a new feature in ASP.NET Core 2.1.
You can find more details about how to scaffold Identity to existing ASP.NET Core projects in the documentation.

Related

Making identity providers in ASP.NET MVC and ASP.NET CORE co-exists

I have migrated a ASP.NET MVC project to ASP.NET Core and currently testing it.
I would like to keep the current version and the new version using the same database during these testing and staging phases.
Both apps uses ASP.NET identity providers. When we have green light, we put the new app in production while the database is already in place.
To make the database work in ASP.NET Core, I had to do some changes, like adding new columns for some normalized values and add the AspNetRoleClaims table as well. After that .NET Core works fine, but the old application is failing authentication at login operation.
My desktop client applications are also failing to get the authentication bearer tokens. I read something that bearer tokens are no longer default in .NET Core 3.1.
Not sure how and if these two problems are related, but is there any changes I could make this work, so I could make a smooth transition?
Your need:
Making identity providers in ASP.NET MVC and ASP.NET CORE co-exists.
It's worse practice. Because your mixed system is not unified, many errors. Let's try to migrate to ASP.NET Core with (ASP.NET Core Identity) totally.

Is it possible to add ASP.NET Core Identity to a WebForms project?

I know it is possible to add ASP.NET Identity (note NOT Core) to a WebForms project. But what I want to do is add ASP.NET Core Identity to an existing WebForms project.
Is this possible?
If 1. is not possible, then how do I share an ASP.NET Core Identity user database between my .NET Core application and WebForms application so that I can implement https://learn.microsoft.com/en-us/aspnet/core/security/cookie-sharing?view=aspnetcore-2.2#use-a-common-user-database
It is definitely possible to share the database
Option 1: you will need to do some custom implementation since Core Identity (v3) might have a slightly different schema than .NET Framework Identity (v2). Take a look at the following link https://learn.microsoft.com/en-us/aspnet/identity/overview/extensibility/index
You might need to also override the PasswordHasher if they are different implementations. Check the following article out: https://andrewlock.net/exploring-the-asp-net-core-identity-passwordhasher/
Option 2: You can expose login/registering/membership functionality from your Core project and consume from your WebForm as a rest service. There are several rest security schemes and middleware.
See:
https://garywoodfine.com/asp-net-core-2-2-jwt-authentication-tutorial/
https://learn.microsoft.com/en-us/dotnet/standard/microservices-architecture/secure-net-microservices-web-applications/
Those are a few quick ones. You can probably extrapolate and get some other ideas from looking at the source for Identity lib (https://github.com/aspnet/AspNetCore/tree/master/src/Identity) If you scroll down the readme you'll see different Store providers. For Option 1 you would need to essentially write a Core Store for your Web Forms Identity lib (https://archive.codeplex.com/?p=aspnetwebstack)

Is it still relevant to use Owin / Katana with ASP.NET Core (actual use case)?

Based on the answer here: How to explain Katana and OWIN in simple words and uses?
Regarding the comment above, OWIN is not a framework. OWIN is a
specification on how web servers and web applications should be built
in order to decouple one from another and allow movement of ASP.NET
applications to environments where at the current state it is not
possible.
Prior to OWIN, when you are building ASP.NET application, you are
inheritedly bound to IIS due to the heavy dependency on System.Web
assembly.
System.Web is something that exist ever since ASP (non .NET version)
and internally contains many things that you might not even need (such
as Web Forms or URL Authorization), which by the default run on every
request, thus consuming the resources and making ASP.NET applications
in general lot slower than it's counterparts at i.e. Node.js.
So OWIN itself does not have any tools, libraries or anything else. It
is just a specification.
If OWIN is just a specification with Katana its .NET implementation in order for ASP.NET applications to not be bound with IIS, then in the case of ASP.NET Core applications working with Kestrell and another webserver like nginx (acting as a reverse proxy) why we would still need OWIN?
ASP.NET Core is an evolution of the Microsoft.Owin.*, what Microsoft refers to as Katana.
The Microsoft.Owin.* libraries are not available for .NET Core because ASP.NET Core has equivalent replacements for them. See https://learn.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/

ASP.NET Core 2.0 Using old ASP.NET 2.0 database structure for authentication

So I've been developing an ASP.NET Core 2.0 application for a while now and I was wondering if it's possible to use an older SQL database with the following tables in my ASP.NET Core 2.0 application.
As I read online this is the default database structure for using ASP.NET 2.0 SqlMemebershipProvider classes. Is it possible to implement this into my application and if so, how should I approach this?
The structure you talk about is called ASP.NET Membership and it works for any ASP.NET version, up to 4.5.
There's no built-in way to run Membership in ASP.NET Core because Membership has been dead for many years. You have two paths to follow:
Move to ASP.NET Identity, works for both ASP.NET 4.x and Core. You will need to migrate your data manually.
Create the classes to consume the data manually. Notice that you won't have any of the security features of Membership so I strongly discourage this.
Of course, a 3rd path would be to keep using the outdated Membership on an ASP.NET MVC 5 application.
The old table structure is not compatible with ASP.NET Identity. Plain and simple. Your best path forward is to generate the tables that Identity does use, and then migrate the data from the old tables to those. Nothing else will work.

use old asp membership database for identity with mvc

We have an old asp.net(web.forms) membership database(aspnet.users,membership,roles,etc..)
how can I integrate this with new mvc application.
I checked this answer but this uses a completely new database, and according to this post , it's gonna be a pain. I'm wondering whether this solution would work. I will of course hook up our custom user identity. I just need the core or main steps to do this.
Thanks..
Take a look at the answer to this question. It demonstrates how to implement IUserStore, IUserPasswordStore, IUserEmailStore and IPasswordHasher to consume an exising ASP.NET Membership database in ASP.NET Identity.

Categories

Resources