【问题标题】:Cannot find definition when trying to use Authentication Builder's AddTwitter()尝试使用身份验证生成器的 AddTwitter() 时找不到定义
【发布时间】:2020-03-21 14:34:42
【问题描述】:

当尝试按照documentation. 向我的 SPA ASP.NET 应用程序添加 Twitter 外部登录时,我遇到了一个错误:

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

这是指我的 Startup.cs 的第 36 行:

public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(
                Configuration.GetConnectionString("DefaultConnection")));

        services.AddDefaultIdentity<ApplicationUser>()
            .AddEntityFrameworkStores<ApplicationDbContext>();

        services.AddAuthentication().AddTwitter(twitterOptions =>
        {
            twitterOptions.ConsumerKey = Configuration["Authentication:Twitter:ConsumerAPIKey"];
            twitterOptions.ConsumerSecret = Configuration["Authentication:Twitter:ConsumerSecret"];
        });

        services.AddIdentityServer()
            .AddApiAuthorization<ApplicationUser, ApplicationDbContext>();

        services.AddAuthentication()
            .AddIdentityServerJwt();

        services.AddControllersWithViews();
        services.AddRazorPages();

        // In production, the React files will be served from this directory
        services.AddSpaStaticFiles(configuration =>
        {
            configuration.RootPath = "ClientApp/build";
        });
    }

我该如何解决这个问题? 谢谢。

【问题讨论】:

    标签: c# asp.net .net twitter oauth-2.0


    【解决方案1】:

    Microsoft.AspNetCore.Authentication.Twitter NuGet 包添加到项目中。

    他们忘记将其放入文档中。他们为 Facebook 做的。

    【讨论】:

      猜你喜欢
      • 2017-10-20
      • 1970-01-01
      • 2021-01-01
      • 2019-07-01
      • 1970-01-01
      • 2019-07-04
      • 1970-01-01
      • 1970-01-01
      • 2019-10-28
      相关资源
      最近更新 更多