Search code examples
asp.netasp.net-coreasp.net-core-mvcasp.net-identity-2

Where to specify consumerKey and consumerSecret for Twitter login in MVC 6?


Every time there is a new version of .NET Framework, the framework for authentication using external logins is overhauled!

The external login documentation link for MVC 6, http://go.microsoft.com/fwlink/?LinkID=532715, is missing.

The initialization now uses IApplicationBuilder instead of IAppBuilder in the previous version. The useTwitterAuthentication method now does not take consumerKey and consumerSecret parameters. How do I specify these?


Solution

  • In your project.json file, in the dependencies section:

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

    Then, in Startup.cs:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        // Other code here
    
        app.UseTwitterAuthentication(options =>
        {
            options.ConsumerKey = "";
            options.ConsumerSecret = "";
        });
    
        app.UseMvc();
    }