Linkedin login through owin.security.OpenIdConnect in .net4.7.2 and MVC5 based webapplicaiton

95 Views Asked by At

Currently I am working on a website developed using .Net 4.7.2 and MVC5. Received a requirement to implement Linkedin authentication using "OpenIdConnectAuthentication" from owin.security.OpenIdConnect.

I have added below code in my startup.cs

 app.SetDefaultSignInAsAuthenticationType(OpenIdConnectAuthenticationDefaults.AuthenticationType);
 app.UseCookieAuthentication(new CookieAuthenticationOptions()
            {
                AuthenticationType = OpenIdConnectAuthenticationDefaults.AuthenticationType,
                CookieSecure = CookieSecureOption.Always,
                CookieHttpOnly = true
            });
 app.UseCookieAuthentication(new CookieAuthenticationOptions());
 app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {

                ClientId = "12g898j17neon",
                ClientSecret = "m9MrK5ccYz3twpTB",
                Authority = "https://www.linkedin.com/oauth/v2/authorization",
                RedirectUri = "https://localhost:44319",
                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    SecurityTokenReceived = Tokenreceived,
                    RedirectToIdentityProvider = Redirect,
                    AuthenticationFailed = AuthencationFailed,
                    AuthorizationCodeReceived = AuthorizationCodeReceived,
                }
            }
        );

added below code in AccountController -> Login in method.

HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties 
    { RedirectUri = "https://localhost:44319/Account/SuccessfullLogin" 
    },OpenIdConnectAuthenticationDefaults.AuthenticationType);

When I run the application and click on login button I am getting this error, But was expecting to take user to linkedin login page and take username and password and provide authorization tickect and access token. Error

Is there anything that I am missing here?

0

There are 0 best solutions below