user5911118
user5911118

Reputation:

Asp.NET MVC 5 IdentityServer4 External Provider

With IdentityServer3 one approach to configure external authentication provider was add to the Startup method of the application

    internal class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var microsoft = new MicrosoftAccountAuthenticationOptions()
            {
                AuthenticationType = "Microsoft",
                ClientId = "********",
                ClientSecret = "********"
            };
            app.UseMicrosoftAccountAuthentication(microsoft);
            ....
        }
    }

In IdentityServer4 everything is designed around IApplicationBuilder interface, which doesn't have the methods above.

    public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
    {
       ....
    }

Does this means that in V4 external providers authentication is not supported yet?

I tried unsuccessfully to inject the IAppBuilder in the Configure method, but it would be a pretty messy solution...

Any thoughts? Thank you

Upvotes: 2

Views: 1116

Answers (1)

user5911118
user5911118

Reputation:

Thanks everyone,

I think I made some significant progresses. The problem was that I was trying to add the old OWIN references to my solution instead of adopting the new AspNet Authentication.

"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-rc1-final"

I found a solution here.

Event with IApplicationBuilder it is possible to register external providers as detailed below

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
    {
        ...
        app.UseMicrosoftAccountAuthentication(options =>
        {
            options.ClientId = Configuration["AppSettings:AzureClientId"];
            options.ClientSecret = Configuration["AppSettings:AzureClientSecret"];
            options.AuthenticationScheme = "Microsoft";
            options.SignInScheme = "Cookies";
            options.CallbackPath = new PathString("/signin-microsoft");
            options.AuthorizationEndpoint = MicrosoftAccountDefaults.AuthorizationEndpoint;
            options.TokenEndpoint = MicrosoftAccountDefaults.TokenEndpoint;
        });
    }

Upvotes: 3

Related Questions