Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are Authentication type names registered in asp.net vnext

So I am updating an Open Source asp.net Identity provider for MongoDB to work with Asp.Net Identity 3.0 (aka vnext). So far I have been able to register the provider and create users but when using the SignInManager if a correct UserName/Pass is provided I get the error

InvalidOperationException: The following authentication types were not accepted: Microsoft.AspNet.Identity.Application

I have tracked down the error to here https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponse.cs

but I can't seem to see where the SignInContext.Accepted name is getting added to the SignInContext.

I am using the Alpha-2 versions of all of the vnext libraries that are being used in VS14 CTP2

Below is my Startup.cs

public void Configure(IBuilder app)
    {
        try {
            // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
            var configuration = new Configuration();
            configuration.AddJsonFile("config.json");
            configuration.AddEnvironmentVariables();

         //   app.UseLogRequests("try");
            app.UseErrorPage(ErrorPageOptions.ShowAll);
            app.UseServices(services =>
            {

                services.AddIdentity<MyUser>()
                .AddMongoDB<MyUser>(configuration.Get("Data:MongoIdentity:ConnectionString"), configuration.Get("Data:MongoIdentity:DBName"))
                .AddHttpSignIn<MyUser>();


                // Add MVC services to the services container
                services.AddMvc();
            });

            // Add static files to the request pipeline
            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(
                    name: "api",
                    template: "api/{controller}/{action}",
                    defaults: new { action = "Index" });
            });

            // Add cookie-based authentication to the request pipeline
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
            });
        }
        catch (Exception ex)
        {
            Console.Write(ex.ToString());
            throw;
        }
    }
like image 587
runxc1 Bret Ferrier Avatar asked Jul 11 '14 03:07

runxc1 Bret Ferrier


People also ask

How does authentication work in asp net?

Authentication is knowing the identity of the user. For example, Alice logs in with her username and password, and the server uses the password to authenticate Alice. Authorization is deciding whether a user is allowed to perform an action. For example, Alice has permission to get a resource but not create a resource.

What is authentication type in asp net core?

Authentication is the process of determining a user's identity. Authorization is the process of determining whether a user has access to a resource. In ASP.NET Core, authentication is handled by the authentication service, IAuthenticationService, which is used by authentication middleware.

What is the default type of authentication for ASP NET core MVC?

The windows Authentication provider lets you authenticates users based on their windows accounts. This provider uses IIS to perform the authentication and then passes the authenticated identity to your code. This is the default provided for ASP.net.

What is ASP NET authenticate authentication?

Authentication in ASP.NET. There are two closely interlinked concepts at the heart of security for distributed applications - authentication and authorization. Authentication is the process of obtaining some sort of credentials from the users and using those credentials to verify the user's identity.

What is authorization in ASP NET Core?

Authorization is the process of determining whether a user has access to a resource. In ASP.NET Core, authentication is handled by the IAuthenticationService, which is used by authentication middleware.

What is the forms authentication provider?

The forms authentication provider uses custom HTML forms to collect authentication information and lets you use your own logic to authenticate users. The user's credentials are stored in a cookie for use during the session.

How do I authenticate an anonymous user in a form?

Insert the <Forms> tag, and fill the appropriate attributes. Copy the following code, and then select Paste as HTML on the Edit menu to paste the code in the <authentication> section of the file: Deny access to the anonymous user in the <authorization> section as follows:


1 Answers

Turns out I had setup MVC before the CookieAuthentication so the AuthenticationType was not registered in MVC when it tried to authenticate the user. As MVC depends upon the authentication I just had to bump it up and register it before MVC.

like image 79
runxc1 Bret Ferrier Avatar answered Sep 18 '22 14:09

runxc1 Bret Ferrier