Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 919fa0c

Browse files
committed
Port Facebook middleware from Katana.
1 parent fabdb3b commit 919fa0c

26 files changed

+1373
-17
lines changed

Security.sln

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.21916.0
4+
VisualStudioVersion = 14.0.22013.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4D2B6A51-2F9F-44F5-8131-EA5CAC053652}"
77
EndProject
@@ -22,6 +22,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2222
global.json = global.json
2323
EndProjectSection
2424
EndProject
25+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Security.Facebook", "src\Microsoft.AspNet.Security.Facebook\Microsoft.AspNet.Security.Facebook.kproj", "{3984651C-FD44-4394-8793-3D14EE348C04}"
26+
EndProject
27+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "SocialSample", "samples\SocialSample\SocialSample.kproj", "{8C73D216-332D-41D8-BFD0-45BC4BC36552}"
2528
EndProject
2629
Global
2730
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -73,6 +76,26 @@ Global
7376
{8DA26CD1-1302-4CFD-9270-9FA1B7C6138B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
7477
{8DA26CD1-1302-4CFD-9270-9FA1B7C6138B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
7578
{8DA26CD1-1302-4CFD-9270-9FA1B7C6138B}.Release|x86.ActiveCfg = Release|Any CPU
79+
{3984651C-FD44-4394-8793-3D14EE348C04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
80+
{3984651C-FD44-4394-8793-3D14EE348C04}.Debug|Any CPU.Build.0 = Debug|Any CPU
81+
{3984651C-FD44-4394-8793-3D14EE348C04}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
82+
{3984651C-FD44-4394-8793-3D14EE348C04}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
83+
{3984651C-FD44-4394-8793-3D14EE348C04}.Debug|x86.ActiveCfg = Debug|Any CPU
84+
{3984651C-FD44-4394-8793-3D14EE348C04}.Release|Any CPU.ActiveCfg = Release|Any CPU
85+
{3984651C-FD44-4394-8793-3D14EE348C04}.Release|Any CPU.Build.0 = Release|Any CPU
86+
{3984651C-FD44-4394-8793-3D14EE348C04}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
87+
{3984651C-FD44-4394-8793-3D14EE348C04}.Release|Mixed Platforms.Build.0 = Release|Any CPU
88+
{3984651C-FD44-4394-8793-3D14EE348C04}.Release|x86.ActiveCfg = Release|Any CPU
89+
{8C73D216-332D-41D8-BFD0-45BC4BC36552}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
90+
{8C73D216-332D-41D8-BFD0-45BC4BC36552}.Debug|Any CPU.Build.0 = Debug|Any CPU
91+
{8C73D216-332D-41D8-BFD0-45BC4BC36552}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
92+
{8C73D216-332D-41D8-BFD0-45BC4BC36552}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
93+
{8C73D216-332D-41D8-BFD0-45BC4BC36552}.Debug|x86.ActiveCfg = Debug|Any CPU
94+
{8C73D216-332D-41D8-BFD0-45BC4BC36552}.Release|Any CPU.ActiveCfg = Release|Any CPU
95+
{8C73D216-332D-41D8-BFD0-45BC4BC36552}.Release|Any CPU.Build.0 = Release|Any CPU
96+
{8C73D216-332D-41D8-BFD0-45BC4BC36552}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
97+
{8C73D216-332D-41D8-BFD0-45BC4BC36552}.Release|Mixed Platforms.Build.0 = Release|Any CPU
98+
{8C73D216-332D-41D8-BFD0-45BC4BC36552}.Release|x86.ActiveCfg = Release|Any CPU
7699
EndGlobalSection
77100
GlobalSection(SolutionProperties) = preSolution
78101
HideSolutionNode = FALSE
@@ -82,5 +105,7 @@ Global
82105
{15F1211B-B695-4A1C-B730-1AC58FC91090} = {4D2B6A51-2F9F-44F5-8131-EA5CAC053652}
83106
{558C2C2A-AED8-49DE-BB60-D5F8AE06C714} = {F8C0AA27-F3FB-4286-8E4C-47EF86B539FF}
84107
{8DA26CD1-1302-4CFD-9270-9FA1B7C6138B} = {7BF11F3A-60B6-4796-B504-579C67FFBA34}
108+
{3984651C-FD44-4394-8793-3D14EE348C04} = {4D2B6A51-2F9F-44F5-8131-EA5CAC053652}
109+
{8C73D216-332D-41D8-BFD0-45BC4BC36552} = {F8C0AA27-F3FB-4286-8E4C-47EF86B539FF}
85110
EndGlobalSection
86111
EndGlobal

samples/SocialSample/Project.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"dependencies": {
3+
"Microsoft.AspNet.Hosting": "1.0.0-*",
4+
"Microsoft.AspNet.Http": "1.0.0-*",
5+
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
6+
"Microsoft.AspNet.Security": "1.0.0-*",
7+
"Microsoft.AspNet.Security.Cookies": "1.0.0-*",
8+
"Microsoft.AspNet.Security.Facebook": "1.0.0-*",
9+
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
10+
"Microsoft.Framework.DependencyInjection": "1.0.0-*"
11+
},
12+
"commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:12345" },
13+
"frameworks": {
14+
"net45": {
15+
},
16+
"k10": {
17+
"dependencies": {
18+
"System.Collections": "4.0.10.0",
19+
"System.Console": "4.0.0.0",
20+
"System.Diagnostics.Debug": "4.0.10.0",
21+
"System.Diagnostics.Tools": "4.0.0.0",
22+
"System.Globalization": "4.0.10.0",
23+
"System.IO": "4.0.0.0",
24+
"System.Linq": "4.0.0.0",
25+
"System.Resources.ResourceManager": "4.0.0.0",
26+
"System.Runtime": "4.0.20.0",
27+
"System.Runtime.Extensions": "4.0.10.0",
28+
"System.Runtime.InteropServices": "4.0.20.0",
29+
"System.Threading.Tasks": "4.0.10.0"
30+
}
31+
}
32+
}
33+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="__ToolsVersion__" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.Props" Condition="'$(VSToolsPath)' != ''" />
8+
<PropertyGroup Label="Globals">
9+
<ProjectGuid>8c73d216-332d-41d8-bfd0-45bc4bc36552</ProjectGuid>
10+
<OutputType>Library</OutputType>
11+
</PropertyGroup>
12+
<PropertyGroup Condition="$(OutputType) == 'Console'">
13+
<DebuggerFlavor>ConsoleDebugger</DebuggerFlavor>
14+
</PropertyGroup>
15+
<PropertyGroup Condition="$(OutputType) == 'Web'">
16+
<DebuggerFlavor>WebDebugger</DebuggerFlavor>
17+
</PropertyGroup>
18+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'" Label="Configuration">
19+
</PropertyGroup>
20+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" Label="Configuration">
21+
</PropertyGroup>
22+
<PropertyGroup>
23+
<SchemaVersion>2.0</SchemaVersion>
24+
</PropertyGroup>
25+
<ItemGroup>
26+
<Content Include="Project.json" />
27+
</ItemGroup>
28+
<ItemGroup>
29+
<Compile Include="Startup.cs" />
30+
</ItemGroup>
31+
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
32+
</Project>

samples/SocialSample/Startup.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Microsoft.AspNet.Builder;
2+
using Microsoft.AspNet.Http;
3+
using Microsoft.AspNet.Security.Cookies;
4+
using Microsoft.AspNet.Security.Facebook;
5+
6+
namespace CookieSample
7+
{
8+
public class Startup
9+
{
10+
public void Configure(IBuilder app)
11+
{
12+
app.UseErrorPage();
13+
14+
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
15+
16+
app.UseCookieAuthentication(new CookieAuthenticationOptions()
17+
{
18+
});
19+
20+
app.UseFacebookAuthentication(new FacebookAuthenticationOptions()
21+
{
22+
AppId = "569522623154478",
23+
AppSecret = "a124463c4719c94b4228d9a240e5dc1a",
24+
});
25+
26+
app.Run(async context =>
27+
{
28+
if (!context.User.Identity.IsAuthenticated)
29+
{
30+
context.Response.Challenge("Facebook");
31+
return;
32+
}
33+
34+
context.Response.ContentType = "text/plain";
35+
await context.Response.WriteAsync("Hello " + context.User.Identity.Name);
36+
});
37+
}
38+
}
39+
}

src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationExtensions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
5-
using Microsoft.AspNet.Http;
64
using Microsoft.AspNet.Security.Cookies;
7-
using Microsoft.AspNet.Security.DataProtection;
8-
using Microsoft.Framework.DependencyInjection;
9-
using Microsoft.Framework.Logging;
105

116
namespace Microsoft.AspNet.Builder
127
{

src/Microsoft.AspNet.Security.Cookies/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"Microsoft.AspNet.HttpFeature": "1.0.0-*",
77
"Microsoft.AspNet.PipelineCore": "1.0.0-*",
88
"Microsoft.AspNet.RequestContainer": "1.0.0-*",
9-
"Microsoft.AspNet.Security": "",
9+
"Microsoft.AspNet.Security": "1.0.0-*",
1010
"Microsoft.AspNet.Security.DataProtection": "1.0.0-*",
1111
"Microsoft.Framework.DependencyInjection": "1.0.0-*",
1212
"Microsoft.Framework.Logging": "1.0.0-*",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace Microsoft.AspNet.Security.Facebook
5+
{
6+
public static class FacebookAuthenticationDefaults
7+
{
8+
public const string AuthenticationType = "Facebook";
9+
}
10+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNet.Security.Facebook;
5+
6+
namespace Microsoft.AspNet.Builder
7+
{
8+
/// <summary>
9+
/// Extension methods for using <see cref="FacebookAuthenticationMiddleware"/>
10+
/// </summary>
11+
public static class FacebookAuthenticationExtensions
12+
{
13+
/// <summary>
14+
/// Authenticate users using Facebook
15+
/// </summary>
16+
/// <param name="app">The <see cref="IBuilder"/> passed to the configure method</param>
17+
/// <param name="appId">The appId assigned by Facebook</param>
18+
/// <param name="appSecret">The appSecret assigned by Facebook</param>
19+
/// <returns>The updated <see cref="IBuilder"/></returns>
20+
public static IBuilder UseFacebookAuthentication([NotNull] this IBuilder app, [NotNull] string appId, [NotNull] string appSecret)
21+
{
22+
return app.UseFacebookAuthentication(new FacebookAuthenticationOptions()
23+
{
24+
AppId = appId,
25+
AppSecret = appSecret,
26+
});
27+
}
28+
29+
/// <summary>
30+
/// Authenticate users using Facebook
31+
/// </summary>
32+
/// <param name="app">The <see cref="IBuilder"/> passed to the configure method</param>
33+
/// <param name="options">Middleware configuration options</param>
34+
/// <returns>The updated <see cref="IBuilder"/></returns>
35+
public static IBuilder UseFacebookAuthentication([NotNull] this IBuilder app, [NotNull] FacebookAuthenticationOptions options)
36+
{
37+
if (string.IsNullOrEmpty(options.SignInAsAuthenticationType))
38+
{
39+
options.SignInAsAuthenticationType = app.GetDefaultSignInAsAuthenticationType();
40+
}
41+
return app.UseMiddleware<FacebookAuthenticationMiddleware>(options);
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)