Skip to content

Commit 52decbc

Browse files
committed
Don't register external login providers if key/secrets were not defined
Fix kriasoft#9
1 parent 96a82e9 commit 52decbc

File tree

6 files changed

+50
-18
lines changed

6 files changed

+50
-18
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
"postcss-selector-not": "^2.0.0",
5959
"react-hot-loader": "^3.0.0-beta.2",
6060
"style-loader": "^0.13.1",
61-
"stylelint": "^6.5.1",
62-
"stylelint-config-standard": "^8.0.0",
61+
"stylelint": "^6.6.0",
62+
"stylelint-config-standard": "^9.0.0",
6363
"url-loader": "^0.5.7",
6464
"webpack": "^2.1.0-beta.13",
6565
"webpack-dev-middleware": "^1.6.1",

server/Controllers/AccountController.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// This source code is licensed under the MIT license found in the
33
// LICENSE.txt file in the root directory of this source tree.
44

5+
using System.Collections.Generic;
6+
57
using Microsoft.AspNetCore.Authorization;
68
using Microsoft.AspNetCore.Identity;
79
using Microsoft.AspNetCore.Mvc;
@@ -15,21 +17,27 @@ public class AccountController : Controller
1517
{
1618
private readonly SignInManager<User> _signInManager;
1719
private readonly ILogger _logger;
20+
private readonly SortedList<string, string> _providers;
1821

1922
public AccountController(SignInManager<User> signInManager, ILoggerFactory loggerFactory)
2023
{
2124
_signInManager = signInManager;
2225
_logger = loggerFactory.CreateLogger<AccountController>();
26+
_providers = new SortedList<string, string>
27+
{
28+
{ "facebook", "Facebook" }
29+
};
2330
}
2431

2532
[HttpGet("login/{provider}")]
2633
[AllowAnonymous]
2734
public IActionResult ExternalLogin(string provider, string returnUrl = null)
2835
{
2936
// Request a redirect to the external login provider.
37+
var providerName = _providers.ContainsKey(provider) ? _providers[provider] : provider;
3038
var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl });
31-
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
32-
return Challenge(properties, provider);
39+
var properties = _signInManager.ConfigureExternalAuthenticationProperties(providerName, redirectUrl);
40+
return Challenge(properties, providerName);
3341
}
3442

3543
[HttpGet("auth")]

server/Startup.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,19 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
6868

6969
// Enable external authentication provider(s)
7070
// https://docs.asp.net/en/latest/security/authentication/sociallogins.html
71-
app.UseIdentity()
71+
app.UseIdentity();
7272

73-
.UseFacebookAuthentication(new FacebookOptions
73+
if (!string.IsNullOrEmpty(Configuration["Authentication:Facebook:AppId"]))
74+
{
75+
app.UseFacebookAuthentication(new FacebookOptions
7476
{
7577
AppId = Configuration["Authentication:Facebook:AppId"],
7678
AppSecret = Configuration["Authentication:Facebook:AppSecret"],
7779
Scope = { "email" },
7880
Fields = { "name", "email" },
7981
SaveTokens = true,
8082
});
83+
}
8184

8285
// Configure ASP.NET MVC
8386
// https://docs.asp.net/en/latest/mvc/index.html

tools/appsettings.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* ASP.NET Core Starter Kit
3+
*
4+
* Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE.txt file in the root directory of this source tree.
8+
*/
9+
10+
const fs = require('fs');
11+
const path = require('path');
12+
const task = require('./lib/task');
13+
14+
const environments = ['Production', 'Development'];
15+
16+
// Create Production/Development configuration files if they don't exist
17+
module.exports = task('appsettings', () => new Promise(resolve => {
18+
let count = environments.length;
19+
const appSettings = require('../server/appsettings.json'); // use it as a template
20+
delete appSettings.Logging;
21+
environments.forEach(env => {
22+
const filename = path.resolve(__dirname, `../server/appsettings.${env}.json`);
23+
fs.writeFile(filename, JSON.stringify(appSettings, null, ' '), { flag: 'wx' }, () => {
24+
if (--count === 0) resolve();
25+
});
26+
});
27+
}));

tools/build.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,7 @@ module.exports = task('build', () => Promise.resolve()
2020
.then(() => require('./clean'))
2121

2222
// Create Production/Development configuration files if they don't exist
23-
.then(() => new Promise(resolve => {
24-
let count = 2;
25-
const appSettings = require('../server/appsettings.json'); // use it as a template
26-
delete appSettings.Logging;
27-
['Production', 'Development'].forEach(env => {
28-
const filename = path.resolve(__dirname, `../server/appsettings.${env}.json`);
29-
fs.writeFile(filename, JSON.stringify(appSettings, null, ' '), { flag: 'wx' }, () => {
30-
if (--count === 0) resolve();
31-
});
32-
});
33-
}))
23+
.then(() => require('./appsettings'))
3424

3525
// Compile the ASP.NET Core app
3626
.then(() => cp.spawn(

tools/start.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const webpackConfig = require('./webpack.config');
1414
const task = require('./lib/task');
1515

1616
module.exports = task('start', () => Promise.resolve()
17+
// Clean up the output directory
18+
.then(() => require('./clean'))
19+
20+
// Create Production/Development configuration files if they don't exist
21+
.then(() => require('./appsettings'))
1722

1823
// Launch Webpack compiler in watch mode
1924
.then(() => new Promise((resolve, reject) => {
@@ -44,5 +49,4 @@ module.exports = task('start', () => Promise.resolve()
4449
}
4550
});
4651
}))
47-
4852
);

0 commit comments

Comments
 (0)