0

At my job we're gradually replacing a monolithic legacy system with a microservices architecture. I've been tasked with writing an auth server using Asp.Net Core, Identity Server 4 and Entity Framework*. The legacy system already has auth and our deadline is approaching, so we're going to use the legacy system as a backend for the time being.

How can I set up Identity Server/Entity Framework to pull login info through the legacy system? So far, everything I've found involves adding a database like SQL server. Assume for the sake of argument I'm not able to pull data directly from the MySQL database that the legacy system uses, but it is easy to get the user data via a JSON API.

I have written a DbContext and an implementation of IProfileService which uses it, but I'm not sure how to actually pull the users in the DbContext, and when I try to sign in from a client I get this error:

No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions object in its constructor and passes it to the base constructor for DbContext.

However I haven't been able to find/figure out what to put in DbContext.OnConfiguring to set this up. I suppose I need to implement IServiceProvider somewhere, but can't find any details of how to do so.

*We're not married to these so suggestions for something more appropriate are welcome. We are using .Net Core.

Chris Swinchatt
  • 1,081
  • 2
  • 9
  • 18
  • Is your question about trying to connect to a MySQL db (using database first EntityFramework) in a .NET Core app? Or is it about inserting data from a JSON API into a new db? – Wurd Sep 24 '18 at 10:00
  • @Wurd Neither; I want to use the JSON API as if it were a (read-only) database. What I want to happen is: (1) user sends login details to IS4 API; (2) users are retrieved from JSON API and authentication happens in IS4; (3) IS4 API returns an auth token. – Chris Swinchatt Sep 24 '18 at 10:12
  • Ok so what EXACTLY is your question? On how to use a JSON api in EF? EF is designed to connect to databases, so it just can't do that. I suggest you write a wrapper around the JSON API and expose it as an IQueryable. That will make it look "databasy" even though it's getting the data through api calls. – Wurd Sep 24 '18 at 10:14
  • @Wurd My exact question is: How to write middleware for EF to pull data from a JSON API. So IQueryable might be the right direction; I hadn't seen that. – Chris Swinchatt Sep 24 '18 at 10:17
  • It looks like I will still need to implement DbContext, IServiceProvider and about a dozen other classes. Is that right? – Chris Swinchatt Sep 24 '18 at 10:27
  • EF will not work with a JSON api, I don't know how many more time I have to tell you this. Expose your API as IQueryable like this where your `list` variable is the data from your API. https://stackoverflow.com/questions/73542/ilistt-to-iqueryablet – Wurd Sep 24 '18 at 11:01
  • A few more times should do it. Thank you for the link. If you want to make this an answer I will accept it. – Chris Swinchatt Sep 24 '18 at 11:16

1 Answers1

0

The EF bit seems like a red herring here. If you're talking to an API in a legacy system then you won't use EF for that at all.

If using IdentityServer4 then it makes sense to use their EF implementations for the configuration and operational stores and then implement your sign in UI, IClaimsService etc using the API exposed by your existing system. To do that just create a simple client implementation that calls said API and accepts and returns whatever models you require.

mackie
  • 4,996
  • 1
  • 17
  • 17