This repository was archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 598
Port Facebook middleware from Katana. #34
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"dependencies": { | ||
"Microsoft.AspNet.Hosting": "1.0.0-*", | ||
"Microsoft.AspNet.Http": "1.0.0-*", | ||
"Microsoft.AspNet.Diagnostics": "1.0.0-*", | ||
"Microsoft.AspNet.Security": "1.0.0-*", | ||
"Microsoft.AspNet.Security.Cookies": "1.0.0-*", | ||
"Microsoft.AspNet.Security.Facebook": "1.0.0-*", | ||
"Microsoft.AspNet.Server.WebListener": "1.0.0-*", | ||
"Microsoft.Framework.DependencyInjection": "1.0.0-*" | ||
}, | ||
"commands": { "web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:12345" }, | ||
"frameworks": { | ||
"net45": { | ||
}, | ||
"k10": { | ||
"dependencies": { | ||
"System.Collections": "4.0.10.0", | ||
"System.Console": "4.0.0.0", | ||
"System.Diagnostics.Debug": "4.0.10.0", | ||
"System.Diagnostics.Tools": "4.0.0.0", | ||
"System.Globalization": "4.0.10.0", | ||
"System.IO": "4.0.0.0", | ||
"System.Linq": "4.0.0.0", | ||
"System.Resources.ResourceManager": "4.0.0.0", | ||
"System.Runtime": "4.0.20.0", | ||
"System.Runtime.Extensions": "4.0.10.0", | ||
"System.Runtime.InteropServices": "4.0.20.0", | ||
"System.Threading.Tasks": "4.0.10.0" | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="__ToolsVersion__" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>8c73d216-332d-41d8-bfd0-45bc4bc36552</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$(OutputType) == 'Console'"> | ||
<DebuggerFlavor>ConsoleDebugger</DebuggerFlavor> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$(OutputType) == 'Web'"> | ||
<DebuggerFlavor>WebDebugger</DebuggerFlavor> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'" Label="Configuration"> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" Label="Configuration"> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Content Include="Project.json" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Startup.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.Http; | ||
using Microsoft.AspNet.Security.Cookies; | ||
using Microsoft.AspNet.Security.Facebook; | ||
|
||
namespace CookieSample | ||
{ | ||
public class Startup | ||
{ | ||
public void Configure(IBuilder app) | ||
{ | ||
app.UseErrorPage(); | ||
|
||
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); | ||
|
||
app.UseCookieAuthentication(new CookieAuthenticationOptions() | ||
{ | ||
}); | ||
|
||
app.UseFacebookAuthentication(new FacebookAuthenticationOptions() | ||
{ | ||
AppId = "569522623154478", | ||
AppSecret = "a124463c4719c94b4228d9a240e5dc1a", | ||
}); | ||
|
||
app.Run(async context => | ||
{ | ||
if (!context.User.Identity.IsAuthenticated) | ||
{ | ||
context.Response.Challenge("Facebook"); | ||
return; | ||
} | ||
|
||
context.Response.ContentType = "text/plain"; | ||
await context.Response.WriteAsync("Hello " + context.User.Identity.Name); | ||
}); | ||
} | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationDefaults.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNet.Security.Facebook | ||
{ | ||
public static class FacebookAuthenticationDefaults | ||
{ | ||
public const string AuthenticationType = "Facebook"; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Microsoft.AspNet.Security.Facebook/FacebookAuthenticationExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.AspNet.Security.Facebook; | ||
|
||
namespace Microsoft.AspNet.Builder | ||
{ | ||
/// <summary> | ||
/// Extension methods for using <see cref="FacebookAuthenticationMiddleware"/> | ||
/// </summary> | ||
public static class FacebookAuthenticationExtensions | ||
{ | ||
/// <summary> | ||
/// Authenticate users using Facebook | ||
/// </summary> | ||
/// <param name="app">The <see cref="IBuilder"/> passed to the configure method</param> | ||
/// <param name="appId">The appId assigned by Facebook</param> | ||
/// <param name="appSecret">The appSecret assigned by Facebook</param> | ||
/// <returns>The updated <see cref="IBuilder"/></returns> | ||
public static IBuilder UseFacebookAuthentication([NotNull] this IBuilder app, [NotNull] string appId, [NotNull] string appSecret) | ||
{ | ||
return app.UseFacebookAuthentication(new FacebookAuthenticationOptions() | ||
{ | ||
AppId = appId, | ||
AppSecret = appSecret, | ||
}); | ||
} | ||
|
||
/// <summary> | ||
/// Authenticate users using Facebook | ||
/// </summary> | ||
/// <param name="app">The <see cref="IBuilder"/> passed to the configure method</param> | ||
/// <param name="options">Middleware configuration options</param> | ||
/// <returns>The updated <see cref="IBuilder"/></returns> | ||
public static IBuilder UseFacebookAuthentication([NotNull] this IBuilder app, [NotNull] FacebookAuthenticationOptions options) | ||
{ | ||
if (string.IsNullOrEmpty(options.SignInAsAuthenticationType)) | ||
{ | ||
options.SignInAsAuthenticationType = app.GetDefaultSignInAsAuthenticationType(); | ||
} | ||
return app.UseMiddleware<FacebookAuthenticationMiddleware>(options); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
um?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are for at test app that's limited to
http://localhost:12345/
. We do the same thing in Katana.