What are the steps needed in order to isolate ASP.NET Core Identity inside a .NET Standard Class Library targeting a SQL Server database? - asp.net

I am currently working on a legacy application and we need to re-implement the Authentication and Authorization part in a separate .NET Standard library using ASP.NET Core Identity.
The starting point and implementation path is not clear for me. I installed the following packages:
Microsoft.AspNetCore.Identity
Microsoft.AspNetCore.Identity.EntityFrameworkCore
I don't know how to configure it to use SQL Server or to run migrations.
I apologize if I'm asking simplistic questions.
Please help if you can.
Thanks in advance

You might want to start by going though some of the tutorials. Introduction to Identity on ASP.NET Core
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
I moved a legacy user database over to asp .net identity recently what i ended up doing was creating the identity tables and then creating a sql script which migrated all of my users over to the new data structure. The only trick was converting the passwords.

Related

Migrating from OWIN .NET Framework to OpenIddict .NET Core

I have an existing .NET Framework Web API currently in production which is in the process of being upgraded to .NET 6.
The application uses the built-in .NET Framework OWIN solution for generating tokens and handles the authorisation for the client_credential flow.
We have a couple of custom MySql tables that hold the ClientId, ClientSecret info and another for granted token requests, e.g. storing the OWIN ticket, scope details etc.
One limitation we have is that we are using EF Core 3.1.x which we cannot upgrade.
I want to build a solution so that:
existing active OWIN tokens in the database can still be used for
authorisation into the new .NET Core API using OpenIddict, once it goes live. (so
that the end users are not impacted)
I also want to be able to generate new tokens using OpenIddict and
store those tokens in the same existing MySql tables.
I don't know if this is possible and if so how to tackle it.
Has anyone here achieved a similar migration?

.Net Identity 3 on existing solution

I believe that .NET Identity 3 cannot run on an existing (v4.5) ASP.NET solution, but requires .NET Core. I cannot update to .NET Core. Is there a workaround for this? If not then how are people supposed to migrate from ASP.NET Membership to ASP.Net Identity?
First of all, I need to note that ASP.NET Core (which works with Identity 3) does not require .NET Core. It can be used either over .NET Core or .NET Framework 4.6.1 (or higher).
I guess you use the default approach in both cases (Membership and Identity) when all information about users, roles, passwords, etc, is stored in some database.
So, the best way to migrate from Membership to Identity is the following:
create a new ASP.NET Core project using the default template and with "Authentication" turned on
then write a small console program which will move all user-related information from your old membership tables to the new ones (created automatically by ASP.NET Identity)
then move all other your controllers and views one by one.
The only problem here - is that Identity will not recognize the passwords' hashes created with Membership. To resolve it you will need to define your own implementation of IPasswordHasher interface and register it in DI container as it's described in this article.

Configure database for MVC authentication

I've been Googling terms like
configure database for mvc authentication
But I can't find anything from this decade that relates to my configuration.
I've created an MVC application using .NET Framework 4.6 with authentication support (database first). Now where do I find step-by-step instructions for creating the database tables and configuring MVC to use them?
Thanks for any tips!
The correct thing to google for is 'ASP.NET Identity'.
If you generate an MVC app straight from one of the templates it will generate a number of classes to handle security and identity.
One of these classes will implement interface IUserStore. The class provided will inherit from Microsoft.AspNet.Identity.EntityFramework.UserStore<TUser>, and uses Entity Framework to check the database if the tables exist, and create them if they are not there.
If you are uneasy about giving your application enough privileges to modify your data schema (ew!), you can create your own class that implements IUserStore and plug that into the system.
It's a big topic, but hopefully this is enough to get started with.

Setting up equivalent of SQLMembershipProvider for ASP.NET vNext

How do I go about setting up an equivalent of a SQLMembershipProvider for individual account authentication for a web app built using ASP.NET vNext. Based on what I am reading, the authentication framework has changed. I would appreciate if you can point me to some reading material on this.
Never mind my question. My SQL Server Explorer in VS 2015 RC had some refresh issues and so I was unable to see the new database right away. In any event, the following link describes how to do it:
Using Identity in ASP.NET vNext

Client for Custom OpenId provider in Asp.Net web application

I am relatively new to asp.net so sorry if the question sounds silly.
I have to build an Asp.net web application able to login on a OpenId custom server (i.e. not included in the DotNetOpenAuth library). I am using vs2010 and .net framework 4.0.
After many searches I found these posts where it is explained.
http://blogs.msdn.com/b/webdev/archive/2012/08/23/plugging-custom-oauth-openid-providers.aspx
How to use OpenID providers with unique identifier URLs in ASP.NET MVC4
http://blogs.msdn.com/b/webdev/archive/2012/08/15/oauth-openid-support-for-webforms-mvc-and-webpages.aspx
All of them refer to MVC and to a directory/file called /App_Start/AuthConfig.cs where you have to register your new provider in order to be able to use the client that comes built-in with the library.
From other searching I have understood this directory is not available in Asp.net web application.
Does exist a way/workaround for achieving the same results in Asp.net web application?
Do you have any suggestion/link on how to implements such custom client in my server?
Thank you
stmod
thanks for your help.
After your comment I was back to the provider for asking clarification, but so far, they cannot help me more than providing that link.
So I tried to manage it working in Java and I did it using openid4java library and the following code:
URL u = new URL("https://logint2.idm.toon.sul.t-online.de/gcp-web/login/10000112/");
Identifier i = new MyIdentifier();
*//myIdentifier is my implementation of interface openid4java.discovery.Identifier and returns* "http://specs.openid.net/auth/2.0/identifier_select"
DiscoveryInformation discovered = new DiscoveryInformation(u,i);
AuthRequest authReq = manager.authenticate(discovered, returnToUrl);
With this code (and others for managing the response) I have it working.
I am trying now to apply the same to my dot.net solution.
Can you help me in writing the code for having the DotnethOpenauth working with this endpoint?
I think I have to override the Identifier class as I did in Java, but I am stuck.
Thanks stmod
Adding OpenID Relying Party support to your ASP.NET web application is actually quite easy, and does not require an AuthConfig.cs file. If you are using web forms, the easiest way to go is just drop an OpenIdLogin control onto your web form. If you are using MVC, it's just a few lines of code to write, and you can check out the OpenIdRelyingPartyMvc sample that is included in the dotnetopenauth .zip download from SourceForge to see how it can be done.

Resources