Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiAuthorizationDbContext<TUser> force TUser to extends IdentityUser instead of IdentityUser<TKey> #9548

Closed
nguyenquyhy opened this issue Apr 19, 2019 · 10 comments
Assignees
Labels
area-identity Includes: Identity and providers ✔️ Resolution: Won't Fix Resolved because we decided not to change the behavior reported in this issue. Status: Resolved
Milestone

Comments

@nguyenquyhy
Copy link

nguyenquyhy commented Apr 19, 2019

Describe the bug

At the moment, ApiAuthorizationDbContext<TUser> force TUser to extends IdentityUser instead of IdentityUser<TKey>. This means it is impossible to use Identity Server on application with ApplicationUser : IdentityUser<Guid> (or anything different from IdentityUser<string>)

To Reproduce

Steps to reproduce the behavior:

  1. Using ASP.NET Core 3.0 Preview 4
  2. Create a new React or Angular template with Identity
  3. Change ApplicationUser to extends IdentityUser<Guid> instead of IdentityUser
  4. Get error: Error CS0311 The type 'WebApplication.Models.ApplicationUser' cannot be used as type parameter 'TUser' in the generic type or method 'ApiAuthorizationDbContext<TUser>'. There is no implicit reference conversion from 'WebApplication.Models.ApplicationUser' to 'Microsoft.AspNetCore.Identity.IdentityUser'.

Expected behavior

I would expect ApiAuthorizationDbContext to accept another generic to indicate the key type (e.g. ApiAuthorizationDbContext<ApplicationUser, Guid>)

@Eilon Eilon added the area-identity Includes: Identity and providers label Apr 19, 2019
@ajcvickers
Copy link
Member

@HaoK @blowdart Where does ApiAuthorizationDbContext come from?

@blowdart
Copy link
Contributor

blowdart commented May 1, 2019

Part of the identity server support I believe. @javiercn ?

@javiercn
Copy link
Member

javiercn commented May 2, 2019

ApiAuthorizationDbContext is just a convenience class for the templates.

We don’t plan to support all the variants IdentityDbContext supports.

If you want to customize the key you can extend IdentityDbContext directly and implement IPersistentGrantDbContext as ApiAuthorizationDbContext does.

https://github.com/aspnet/AspNetCore/blob/master/src/Identity/ApiAuthorization.IdentityServer/src/Data/ApiAuthorizationDbContext.cs

@javiercn javiercn closed this as completed May 2, 2019
@ajcvickers
Copy link
Member

Re-opening, since ApiAuthorizationDbContext doesn't follow best practices for a DbContext shipped for others to use. In particular:

  • It should expose a public constructor that takes a generic DbContextOptions<TContext>. Otherwise people resolving this directly will have issues when multiple contexts are registered in D.I.
  • It should expose a protected constructor that takes a non-generic DbContextOptions for use when other classes inherit from it.

@ajcvickers ajcvickers reopened this May 2, 2019
@ajcvickers
Copy link
Member

@javiercn Is this the correct repo to track this issue? If not, where should I move it?

@javiercn
Copy link
Member

javiercn commented May 2, 2019

@ajcvickers This is the correct repo.

Could we use a separate issue to track the items you mention?

@cherchyk
Copy link

cherchyk commented Jan 4, 2020

2020 Looks like it was not fixed yet...

Am I wrong?

@StevenRasmussen
Copy link

@blowdart , @ajcvickers - Would you accept a PR from the community on this one? I have opened up #21100 that should hopefully address everything. Thanks for your consideration.

@HaoK
Copy link
Member

HaoK commented Aug 7, 2020

We've decided not to support this

@HaoK HaoK closed this as completed Aug 7, 2020
@HaoK HaoK added the ✔️ Resolution: Won't Fix Resolved because we decided not to change the behavior reported in this issue. label Aug 7, 2020
@ghost ghost added the Status: Resolved label Aug 7, 2020
@HaoK
Copy link
Member

HaoK commented Aug 7, 2020

The idea is that apps can derive from IdentityDbContext directly and utilize the generic support there, this class is just meant to be sugar for the most common scenario

@dotnet dotnet locked as resolved and limited conversation to collaborators Sep 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-identity Includes: Identity and providers ✔️ Resolution: Won't Fix Resolved because we decided not to change the behavior reported in this issue. Status: Resolved
Projects
None yet
Development

No branches or pull requests

8 participants