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

Scaffolding over existing authorization #7042

Closed
alexiordan opened this issue Jun 14, 2018 — with docs.microsoft.com · 7 comments
Closed

Scaffolding over existing authorization #7042

alexiordan opened this issue Jun 14, 2018 — with docs.microsoft.com · 7 comments
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue
Milestone

Comments

Copy link

Authentication works, but User.IsInRole("X") does not return the expected value (it worked with previous version).
Is this expected?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Copy link
Author

alexiordan commented Jun 14, 2018

Ok, so in the first place I hade to add the AddRoles to Identity configuration
services.AddDefaultIdentity()
.AddRoles()
.AddEntityFrameworkStores();

Now it still doesn't work. However, it works the following construction

var user = await UserManager.GetUserAsync(User);
var roles = await UserManager.GetRolesAsync(user);

So, how come User.IsInRole does not work while UserManager.GetRolesAsync works?

@guardrex
Copy link
Collaborator

@guardrex guardrex added Source - Docs.ms Docs Customer feedback via GitHub Issue question labels Jun 14, 2018
@guardrex guardrex added this to the Backlog milestone Jun 14, 2018
Copy link
Author

Yes, but what is the actual answer to my question though?

@guardrex
Copy link
Collaborator

ping @HaoK

@Rick-Anderson
Copy link
Contributor

@HaoK see related #7041

Formerly one could use something like this in Account Controller:

 [HttpGet]
 [Authorize(Roles = "Master")]
 public IActionResult Register(string returnUrl = null)

How can I do the same thing with the new approach?

@HaoK
Copy link
Member

HaoK commented Jun 14, 2018

Its a bug in AddDefaultIdentity/AddIdentityCore, see: aspnet/Identity#1813

Copy link

I followed instructions "Create full identity UI source" after creation of an MVC project with authorization.
When I start the application, click register, fill the form and click "register" button I got an exception : NotSupportedException: No IUserTwoFactorTokenProvider<TUser> named 'Default' is registered.

I fixed it by calling .AddDefaultTokenProviders() in the ConfigureServices method like this:

services.AddIdentity<IdentityUser, IdentityRole>()
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultTokenProviders();

@dotnet dotnet locked and limited conversation to collaborators Oct 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

5 participants