Skip to content

Instantly share code, notes, and snippets.

@frazelamont
frazelamont / launchSettings.json
Created August 30, 2017 16:55
.netCore - storing facebook api keys in app launch settings
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iis": {
"applicationUrl": "https://localhost:44301",
"sslPort": 0
},
"iisExpress": {
"applicationUrl": "http://localhost:44357/",
@frazelamont
frazelamont / startup.cs
Created August 30, 2017 12:12
.netCore - using secret store &/or azure for facebook app settings retrieval
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// add facebook login
services.AddAuthentication()
.AddFacebook(facebookOptions =>
{
facebookOptions.AppId = Configuration["Authentication:Facebook:AppId"];
facebookOptions.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
});
@frazelamont
frazelamont / startup.cs
Created August 30, 2017 12:03
.netCore - accessing user secrets in development environment
public Startup(IConfiguration configuration, IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// For more details on using the user secret store
@frazelamont
frazelamont / facebookSecretStore.ps
Created August 30, 2017 11:54
PowerShell - add values to secret store
# run one line at a time
dotnet user-secrets set Authentication:Facebook:AppId blah
dotnet user-secrets set Authentication:Facebook:AppSecret bleh
@frazelamont
frazelamont / yourProject.csproj
Created August 30, 2017 11:42
.netCore - adding secret manager
<Project Sdk="Microsoft.NET.Sdk.Web">
<!--
the tools for console usage & powershell
-->
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
@frazelamont
frazelamont / launchSettings.json
Created August 27, 2017 19:45
.netCore - launchSettings for local dev https
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iis": {
"applicationUrl": "https://localhost:44301",
"sslPort": 0
},
"iisExpress": {
"applicationUrl": "http://localhost:44357/",
@frazelamont
frazelamont / startup.cs
Created August 27, 2017 19:36
.netCore - ensure all pages are redirected for https
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
/*
* to ensure redirection for HTTPS
*/
var options = new RewriteOptions()
.AddRedirect("redirect-rule/(.*)", "redirected/$1")
.AddRewrite(@"^rewrite-rule/(\d+)/(\d+)",
"rewritten?var1=$1&var2=$2", skipRemainingRules: true);
@frazelamont
frazelamont / startup.cs
Created August 27, 2017 19:14
.netCore - tell webapp to use ssl
public void ConfigureServices(IServiceCollection services)
{
// use HTTPS for everything, we've gone secure like a bank (allegedly)
services.Configure<MvcOptions>(options =>
{
options.Filters.Add(new RequireHttpsAttribute());
});
}
@frazelamont
frazelamont / appSettings.Development.json
Last active August 27, 2017 20:41
.netCore - adjust appSettings.developent.json for local ssl cert
"Certificates": {
"HTTPS": {
"Source": "Store",
"StoreLocation": "LocalMachine",
"StoreName": "My",
"Subject": "CN=localhost",
"AllowInvalid": true
}
}
@frazelamont
frazelamont / createDevSslCert.ps
Created August 27, 2017 18:56
PowerShell create local development ssl certificate
$cert = New-SelfSignedCertificate -Subject localhost -DnsName localhost -FriendlyName "ASP.NET Core Development" -KeyUsage DigitalSignature -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")
Export-Certificate -Cert $cert -FilePath cert.cer
Import-Certificate -FilePath cert.cer -CertStoreLocation cert:/CurrentUser/Root