2017-12-14 4 views
2

ユーザーが登録してパスワードを回復するときに電子メールを送信するために.netコア2.0 Webアプリケーションをセットアップしようとしています。私はこのチュートリアルに従いました:https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?tabs=visual-studio.NETコア2.0がユーザーの秘密にアクセスする

しかし、コメントセクションを読むと、チュートリアルはCore 2.0用に更新されていないようです。私の質問は、「スタートアップメソッドにユーザーシークレット設定ソースを追加すると、スタートアップファイルが表示されたものとは異なるので、スタートアップファイルの外観はわかりません。スタートアップファイルの外観を教えてもらえますか?ありがとう。

これが私の現在のスタートアップファイルである:ここで

public class Startup 
{ 
    string _testSecret = null; 

    public Startup(IConfiguration configuration) 
    { 
     Configuration = configuration; 
    } 

    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) 
    { 
     _testSecret = Configuration["MySecret"]; 
     services.AddDbContext<ApplicationDbContext>(options => 
      options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 

     services.AddIdentity<ApplicationUser, IdentityRole>(config => 
     { 
      config.SignIn.RequireConfirmedEmail = true; 
     }) 
     .AddEntityFrameworkStores<ApplicationDbContext>() 
     .AddDefaultTokenProviders(); 

     // Add application services. 
     services.AddTransient<IEmailSender, EmailSender>(); 

     services.AddMvc(); 
     services.Configure<AuthMessageSenderOptions>(Configuration); 
    } 

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 
    public void Configure(IApplicationBuilder app, IHostingEnvironment env) 
    { 
     var builder = new ConfigurationBuilder(); 

     if (env.IsDevelopment()) 
     { 
      app.UseDeveloperExceptionPage(); 
      app.UseBrowserLink(); 
      app.UseDatabaseErrorPage(); 
      builder.AddUserSecrets<Startup>(); 
     } 
     else 
     { 
      app.UseExceptionHandler("/Home/Error"); 
     } 

     app.UseStaticFiles(); 

     app.UseAuthentication(); 

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

答えて

0

私が認証することを起動 注意を設定しているかされています。グーグル:ClientIdをと認証:グーグル:ClientSecret値は秘密のファイルです。設定方法は

は、私は例のコードskyped:

 if (env.IsDevelopment()) 
     { 
      builder.AddUserSecrets<Startup>(); 
     } 

をそして私はConfigureServices

public void ConfigureServices(IServiceCollection services) 
{ 
    services.AddMvc(); 
    services.AddIdentity<ApplicationUser, IdentityRole>() 
      //.AddEntityFrameworkStores<ApplicationDbContext>() 
      .AddDefaultTokenProviders(); 

    services.AddAuthentication().AddGoogle(googleOptions => 
    { 
     googleOptions.ClientId = Configuration["Authentication:Google:ClientId"]; 
     googleOptions.ClientSecret = Configuration["Authentication:Google:ClientSecret"]; 
    }); 
} 

    public void Configure(IApplicationBuilder app, IHostingEnvironment env) { 
    if (env.IsDevelopment()) { 
     app.UseDeveloperExceptionPage(); 
    } 
    app.UseAuthentication(); 
    app.UseMvc(); 
    } 
から秘密の値にアクセスすることができます
関連する問題