emonney / QuickApp

ASP.NET Core / Angular startup project template with complete login, user and role management. Plus other useful services for Quick Application Development
https://www.ebenmonney.com/quickapp
MIT License
1.26k stars 594 forks source link

Error - Unable to Login #44

Closed sp00ky closed 6 years ago

sp00ky commented 6 years ago

I'm getting the following exception when I login. The OpenIddictAuthorizations only has the colums Id, ApplicationId, Scope, Status, and Subject. Could there have been some version changes in OpenIddict?

  Activated Event   Time    Duration    Thread
Program Output: Microsoft.EntityFrameworkCore.Database.Command:Error: Failed executing DbCommand (90ms) [Parameters=[@p0='?' (Size = 450), @p1='?' (Size = 450), @p2='?' (Size = 4000), @p3='?' (Size = 4000), @p4='?' (Size = 4000), @p5='?' (Size = 4000)], CommandType='Text', CommandTimeout='30']

SET NOCOUNT ON; INSERT INTO [OpenIddictAuthorizations] ([Id], [ApplicationId], [Scopes], [Status], [Subject], [Type]) VALUES (@p0, @p1, @p2, @p3, @p4, @p5); SELECT [Timestamp] FROM [OpenIddictAuthorizations] WHERE @@ROWCOUNT = 1 AND [Id] = @p0;

System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'Scopes'. Invalid column name 'Type'. Invalid column name 'Timestamp'. at System.Data.SqlClient.SqlCommand.<>c.b__108_0(Task1 result) at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke() at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.d__17.MoveNext() ClientConnectionId:4563d889-c9bd-4b61-a2e2-dcec43c20bd6 Error Number:207,State:1,Class:16 63.55s

CybrZr00 commented 6 years ago

Same problems here, and some other weird things happening when I try to publish. Whilst in debug the app starts, when trying to publish via cli I get errors:

error CS1061: 'AuthenticationBuilder' does not contain a definition for 'AddOAuthValidation' and no extension method 'AddOAuthValidation' accepting a first argument of type 'AuthenticationBuilder' could be found (are you missing a using directive or an assembly reference?)

rafsanulhasan commented 6 years ago

Install AspNet.Security.OAth.Valivation 2.0.0-rc1-0286 (final) NuGet Package to resolve this issue @CybrZr00

CybrZr00 commented 6 years ago

thanks, seems I had 2 entries in my csproj removing the ref to the old version has fixed it.

garyhoff1 commented 6 years ago

I'm also getting the error Invalid column name 'Scopes', 'Type', 'Timestamp' on table OpenIddictAuthorizations. I uninstalled and installed Install AspNet.Security.OAth.Valivation 2.0.0-rc1-0286 (final), Changed DAL.cspfoj:

PackageReference Include="OpenIddict" Version="2.0.0-rc1-final"
PackageReference Include="OpenIddict.EntityFrameworkCore" Version="2.0.0-rc1-final"

Still get error. I drop the database after each try so it rebuilds the tables.

Code in Migrations\20170913022214_Initial.cs:
            migrationBuilder.CreateTable(
                name: "OpenIddictAuthorizations",
                columns: table => new
                {
                    Id = table.Column(type: "nvarchar(450)", nullable: false),
                    ApplicationId = table.Column(type: "nvarchar(450)", nullable: true),
                    Scope = table.Column(type: "nvarchar(max)", nullable: true),
                    Status = table.Column(type: "nvarchar(max)", nullable: true),
                    Subject = table.Column(type: "nvarchar(max)", nullable: true)
                },

Does this need to be changed to include the new columns?

speddi commented 6 years ago

I am trying to host the application in IIS and I getting the following error in the chrome console when I try to login. I deployed the application to a folder name Sample and created a IIS application with name Sample. Not sure why it is trying to access from C:\Inetpub\wwwroot.

How do I fix it? Thank you

Error:

HTTP Error 404.0 - Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Most likely causes:

  • The directory or file specified does not exist on the Web server.
  • The URL contains a typographical error.
  • A custom filter or module, such as URLScan, restricts access to the file.

Things you can try:

  • Create the content on the Web server.
  • Review the browser URL.
  • Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click here.

Detailed Error Information:

Module   IIS Web Core
Notification   MapRequestHandler
Handler   StaticFile
Error Code   0x80070002
Requested URL   http://localhost:8080/connect/token
Physical Path   C:\inetpub\wwwroot\connect\token
Logon Method   Anonymous
Logon User   Anonymous

More Information:

This error means that the file or directory does not exist on the server. Create the file or directory and try the request again.

View more information »

After Troubleshooting:

window.location.origin is coming as "http://localhost:8080/" and path as "sample/login" instead of http://localhost:8080/sample as the baseUrl.

Utiliites.ts public static baseUrl() { if (window.location.origin) return window.location.origin

    return window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
}

Am I missing any setting that lets me get the baseUrl correctly?

Thank you

CybrZr00 commented 6 years ago

@speddi Looks like an IIS setup issue. This isn't really the place for help with that.

CybrZr00 commented 6 years ago

@garyhoff1 I was thinking that, I tried adding the columns manually, but couldn't get the Timestamp column to work, I only tried DateTime and timestamp types and gave up.

speddi commented 6 years ago

@CybrZr00 This might be an IIS issue but it will be a problem anytime we create an application in IIS and deploy the code to that application. Does this not support deploying the app to a application under Default Web Site like 'Default Web Site/MyApp'

CybrZr00 commented 6 years ago

This issue is for what spooky has pointed out in the OP. Maybe open a new issue?

speddi commented 6 years ago

@CybrZr00 got it. I opened a new ticket. Thank you.

CybrZr00 commented 6 years ago

As a horrible hack, I added the missing columns manually (changed scope to scopes) I set all the data types to NVARCHAR(MAX) also added Timestamp to OpeniddictTokens also as NVARCHAR.

I have noticed that entries into the tables are missing an ApplicationId and Timestamp so despite this hack appearing to work, there is data missing.

garyhoff1 commented 6 years ago

To fix the OpenIddict database errors I changed the following in Migrations 20170913022214_Initial.cs. It fixed the issue, I can now login. Not sure if there are any other attributes (nullable or not) that I might have wrong.

                name: "OpenIddictAuthorizations",
                columns: table => new
                {
                    Id = table.Column(type: "nvarchar(450)", nullable: false),
                    ApplicationId = table.Column(type: "nvarchar(450)", nullable: true),
                    Scopes = table.Column(type: "nvarchar(max)", nullable: true),
                    Status = table.Column(type: "nvarchar(max)", nullable: true),
                    Subject = table.Column(type: "nvarchar(max)", nullable: true),
                    Type = table.Column(type: "nvarchar(max)", nullable: true),
                    Timestamp = table.Column(type: "timestamp", nullable: false),
                },

                name: "OpenIddictTokens",
                columns: table => new
                {
                    Id = table.Column(type: "nvarchar(450)", nullable: false),
                    ApplicationId = table.Column(type: "nvarchar(450)", nullable: true),
                    AuthorizationId = table.Column(type: "nvarchar(450)", nullable: true),
                    Ciphertext = table.Column(type: "nvarchar(max)", nullable: true),
                    End = table.Column(type: "datetimeoffset", nullable: true),
                    Hash = table.Column(type: "nvarchar(450)", nullable: true),
                    Start = table.Column(type: "datetimeoffset", nullable: true),
                    Status = table.Column(type: "nvarchar(max)", nullable: true),
                    Subject = table.Column(type: "nvarchar(max)", nullable: true),
                    Type = table.Column(type: "nvarchar(max)", nullable: true),
                    CreationDate = table.Column(type: "datetime2", nullable: false),
                    ExpirationDate = table.Column(type: "datetime2", nullable: true),
                    Timestamp = table.Column(type: "timestamp", nullable: false)
                },
HansHammel commented 6 years ago

@garyhoff1: Confirmed!

At OpenIddictAuthorizations it has to be

Scopes = table.Column(type: "nvarchar(max)", nullable: true),

the s was missing and the other additions are also necessary ^^

NotEvolved commented 6 years ago

I'm sure this is an embarrassingly newbie question...but I made the changes to the migration, but they don't seem to be having any effect. Do I have to do something to drop the tables for the migration to recreate them? Any insight would be greatly appreciated.

garyhoff1 commented 6 years ago

I went into Microsoft SQL Server Management Studio and deleted the entire database, and added back a new empty database with the same name (using right mouse click options). That should do it.

Svakinn commented 6 years ago

There is currently open pull request from HansHammel that should resolve this issue

nicocomumu commented 6 years ago

This is a misunderstood on the origin of your problem. I think if you have this error it's because you have updated the version of OpenIddict, and this library has a different database schema that the oldest version included in QuickApp. Remember that QuickApp is using EF code first, this means that the code is updating the database. To solve this, you have to create a new EF migration and absolutely not change the existing migration! Open NuGet Package Manager Console and enter Add-Migration "OpenIddictV2" This will generate a new migration step, and the next execution of your application will use it to update your database. "OpenIddictV2" is just the name of your migration. Each time you change your EF models, you should ask for a new corresponding migration

emonney commented 6 years ago

It appears you're using a newer/different version of OpenIddict that has different database schema. Like @nicocomumu suggested, you'll need to apply a new EF migrations to update the database properly. Manually updating the db is not the right way.

Closing this thread. If this is still an issue please reopen.

KhaledSMQ commented 6 years ago

I think the problem related to https://github.com/openiddict/openiddict-core/pull/504/commits/37e24a5e76e46addf2cc103e47bf119e4c2c87fb still not solved