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

Unable to authenticate #292

Closed
rajivcodes opened this issue Dec 13, 2016 · 11 comments
Closed

Unable to authenticate #292

rajivcodes opened this issue Dec 13, 2016 · 11 comments
Labels

Comments

@rajivcodes
Copy link

I am using your sample password flow. I upgraded to latest and I get this error in my log file.
Request starting HTTP/1.1 POST http://localhost:58795/connect/token application/x-www-form-urlencoded 86 (e5be5b71)
2016-12-13T02:10:25.7545959-08:00 0HL1380H89SH8 [INF] The token request validation process was skipped because the client_id parameter was missing or empty. (376dcc06)
2016-12-13T02:10:25.8501925-08:00 0HL1380H89SH8 [ERR] An unhandled exception has occurred while executing the request (cf926119)
System.InvalidOperationException: Unable to resolve service for type 'OpenIddict.Core.OpenIddictApplicationManager1[OpenIddict.Models.OpenIddictApplication1[System.Int32]]' while attempting to activate 'AuthorizationServer.AuthorizationController'.
at Microsoft.Extensions.Internal.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)

Here is my startup changes:
services.AddOpenIddict()
// Register the Entity Framework stores.
.AddEntityFrameworkCoreStores<ApplicationDbContext, int>()
// Register the ASP.NET Core MVC binder used by OpenIddict.
// Note: if you don't call this method, you won't be able to
// bind OpenIdConnectRequest or OpenIdConnectResponse parameters.
.AddMvcBinders()

            // Enable the token endpoint.
            .EnableTokenEndpoint("/connect/token")

            // Enable the password flow.
            .AllowPasswordFlow()

My Configure has
app.UseIdentity();
app.UseOAuthValidation();
app.UseOpenIddict();
app.UseMvcWithDefaultRoute();

Here is my Authorization Controller constructor
public AuthorizationController(
OpenIddictApplicationManager<OpenIddictApplication> applicationManager,
SignInManager signInManager,
ApplicationUserManager userManager)
{
_applicationManager = applicationManager;
_signInManager = signInManager;
_userManager = userManager;
}

It was all working fine before upgrade.. Do you know what could be wrong. I really appreciate your help!!

RP

@rajivcodes
Copy link
Author

rajivcodes commented Dec 13, 2016

So to add a client I have this in startup but it throws an error
var applications = context.Set<OpenIddictApplication>(); //i tried even without int

            // Add Mvc.Client to the known applications.
            if (!applications.Any())

......
exception of type 'System.InvalidOperationException'
Error is : Message: "Cannot create a DbSet for 'OpenIddictApplication' because this type is not included in the model for the context."

I searched a lot for this error and came across similar error here
dotnet/efcore#6013
but cant figure it out.

Again everything was working well before yesterdays update. May be I am missing something here to understand the new changes. Thanks in advance!

@kevinchalet
Copy link
Member

That's the problem with generics: they are viral, so you must ensure everything is configured correctly.

Replace services.AddOpenIddict() by services.AddOpenIddict<int>() and context.Set<OpenIddictApplication>(); by context.Set<OpenIddictApplication<int>>();.

@rajivcodes
Copy link
Author

I tried that too but still throws an error and

when you say for my first comment above (and on chat-gitter), that at log level it is correct, i agree but by default .RequireClientIdentification() is enabled. So this statement is there or not there doesn't make a difference. May be this is a bug that by default is enabled even without .RequireClientIdentification()??

@kevinchalet
Copy link
Member

i agree but by default .RequireClientIdentification() is enabled.

Not it's not.

What's the exact exception you're getting?

@rajivcodes
Copy link
Author

rajivcodes commented Dec 13, 2016

This is it from immediate window
?context.Set<OpenIddictApplication< int >>()
'context.Set<OpenIddictApplication< int >>()' threw an exception of type 'System.InvalidOperationException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233079
HelpLink: null
InnerException: null
Message: "Cannot create a DbSet for 'OpenIddictApplication< int >' because this type is not included in the model for the context."
Source: "Microsoft.EntityFrameworkCore"
StackTrace: " at Microsoft.EntityFrameworkCore.DbContext.SetTEntity"

In my code everywhere int is present wherever required.
in startup.cs i have this
services.AddOpenIddict< int >()
// Register the Entity Framework stores.
.AddEntityFrameworkCoreStores< ApplicationDbContext, int >()

var applications = context.Set<OpenIddictApplication< int >>();

in my dbcontext i have this
protected override void OnModelCreating(ModelBuilder builder)
{

        builder.UseOpenIddict<    int     >();
        base.OnModelCreating(builder);
        
        // Customize the ASP.NET Identity model and override the defaults if needed.
        // For example, you can rename the ASP.NET Identity table names and more.
        // Add your customizations after calling base.OnModelCreating(builder);


        var usersTable = builder.Entity<ApplicationUser>().ToTable("Users");
        usersTable.Property(p => p.AccessFailedCount).HasColumnName("LoginFailureCount");
        usersTable.Property(p => p.PasswordHash).HasColumnName("Password");
                 

        var rolesTable = builder.Entity<ApplicationRole>().ToTable("Roles");
        rolesTable.Property(p => p.Id).HasColumnName("Role_Id");
        rolesTable.Property(p => p.Name).HasColumnName("Role_Name");
 
        //ApplicationUserRole has one more column called Id

        builder.Entity<IdentityUserToken<int>>().ToTable("UserTokens");
        builder.Entity<IdentityUserRole<int>>().ToTable("UserRoles");

        var userLoginTable = builder.Entity<IdentityUserLogin<int>>().ToTable("UserLogins");
        userLoginTable.Property(p => p.UserId).HasColumnName("UserKey");
 
        builder.Entity<IdentityUserClaim<int>>().ToTable("UserClaims");
        builder.Entity<IdentityRoleClaim<int>>().ToTable("RoleClaims");
    }

@kevinchalet
Copy link
Member

Read my first message, you missed something...

@rajivcodes
Copy link
Author

rajivcodes commented Dec 13, 2016

the comment removed the < int > so i had to add space after and before lessthan/greater than sign.. sorry please see the above comment again. I know we need int everywhere as thats my tkey.. but it doesnt work.

@kevinchalet kevinchalet added bug and removed question labels Dec 13, 2016
@kevinchalet
Copy link
Member

Alright, I see where the problem is. I'll fix it later today.

@rajivcodes
Copy link
Author

ok cool. atleast i am sure now that it wasnt something i was doing wrong.. thank you. I will look forward to get an update, if possible let me know too what was it or may be I will check the git checkin comment.

@rajivcodes
Copy link
Author

and one more thing back to the .RequireClientIdentification() problem. I still think its enabled by default coz when you run the password flow sample, and dont passin client_id for token/connect, and even when you do not have .RequireClientIdentification() then too it throws an error saying that client_id was not passed. However, I will test it again tomorrow after your fix regarding the type error.

@kevinchalet
Copy link
Member

FYI, this issue was fixed as part of #294.

Concerning client identification, I just tried the password flow and it worked fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants