//Thismethodgetscalledbytheruntime.Usethismethodtoaddservicestothecontainer.
publicvoidConfigureServices(IServiceCollectionservices)
{
//-----------<ConfigureServices()>-----------
services.AddDbContext<ApplicationDbContext>(options=>options.UseSqlServer(Website_Constants.Connectionstring));
//--<FacebookApi>--
//--<Identity>--
services.AddIdentity<ApplicationUser,IdentityRole>(config=>
{
//<sendRegisterEmail>
//*preventsregisteredusersfromlogginginuntiltheiremailisconfirmed.
config.SignIn.RequireConfirmedEmail=true;
//</sendRegisterEmail>
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
//--</Identity>--
//----<JWT-Token>----
//*reference:www.blinkingcaret.com
services.AddAuthentication(options=>
{
options.DefaultAuthenticateScheme="JwtBearer";
options.DefaultChallengeScheme="JwtBearer";
})
.AddJwtBearer("JwtBearer",jwtBearerOptions=>
{
jwtBearerOptions.TokenValidationParameters=newTokenValidationParameters
{
ValidateIssuerSigningKey=true,
IssuerSigningKey=Website_Constants._secretKey,
ValidateIssuer=true,
ValidIssuer="website_x",
ValidateAudience=true,
ValidAudience="webclients_x",
ValidateLifetime=true,//validatetheexpirationandnotbeforevaluesinthetoken
ClockSkew=TimeSpan.FromMinutes(5)//5minutetolerancefortheexpirationdate
};
});
//----</JWT-Token>----
services.AddAuthentication().AddFacebook(facebookOptions=>
{
facebookOptions.AppId=Website_Constants.fp_appID;
facebookOptions.AppSecret=Website_Constants.fp_secret;
});
//--</FacebookApi>--
//Addapplicationservices.
services.AddTransient<IEmailSender,EmailSender>();
varoptRewrite=newRewriteOptions()
.AddRedirectToHttpsPermanent();
services.AddMvc();
//-----------</ConfigureServices()>-----------
}
|