Skip to content
This repository was archived by the owner on Nov 25, 2019. It is now read-only.

Commit 85576de

Browse files
author
yaohuang
committed
Facebook Template Updates:
* removed more unused packages * fixed an issue where using the default FacebookAuthorizeAttribute causes error * made the facebook app URL configurable * removed the unnecessary app.config
1 parent 19d6987 commit 85576de

File tree

5 files changed

+34
-27
lines changed

5 files changed

+34
-27
lines changed

src/Microsoft.AspNet.Mvc.Facebook/App.config

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Microsoft.AspNet.Mvc.Facebook/Attributes/FacebookAuthorizeAttribute.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
22

33
using System;
4+
using System.Collections.Generic;
5+
using System.Globalization;
46
using System.Linq;
57
using System.Web;
68
using System.Web.Mvc;
@@ -37,9 +39,9 @@ public void OnAuthorization(AuthorizationContext filterContext)
3739
// https://developers.facebook.com/docs/reference/dialogs/oauth/#parameters
3840

3941
FacebookAuthorizationInfo authInfo;
40-
if (!String.IsNullOrWhiteSpace(this.Permissions))
42+
if (!String.IsNullOrWhiteSpace(Permissions))
4143
{
42-
var permissions = this.Permissions.Split(',').Select((s) => s.Trim()).ToArray();
44+
var permissions = Permissions.Split(',').Select(s => s.Trim()).ToArray();
4345
authInfo = _facebookService.Authorize(filterContext.HttpContext, permissions);
4446
}
4547
else
@@ -64,13 +66,23 @@ public void OnAuthorization(AuthorizationContext filterContext)
6466
{
6567
appPath = FacebookSettings.AppId;
6668
}
67-
var redirectUri = "https://apps.facebook.com/" + appPath + filterContext.HttpContext.Request.Url.PathAndQuery;
68-
var loginUrl = client.GetLoginUrl(new
69+
70+
var redirectUri = String.Format(CultureInfo.InvariantCulture,
71+
"{0}/{1}{2}",
72+
FacebookSettings.FacebookAppUrl.TrimEnd('/'),
73+
appPath,
74+
filterContext.HttpContext.Request.Url.PathAndQuery);
75+
76+
Dictionary<string, object> loginUrlParameters = new Dictionary<string, object>();
77+
loginUrlParameters["redirect_uri"] = redirectUri;
78+
loginUrlParameters["client_id"] = FacebookSettings.AppId;
79+
if (!String.IsNullOrWhiteSpace(Permissions))
6980
{
70-
scope = this.Permissions,
71-
redirect_uri = redirectUri,
72-
client_id = FacebookSettings.AppId
73-
});
81+
loginUrlParameters["scope"] = Permissions;
82+
}
83+
84+
var loginUrl = client.GetLoginUrl(loginUrlParameters);
85+
7486
var facebookAuthResult = new ContentResult();
7587
facebookAuthResult.ContentType = "text/html";
7688
facebookAuthResult.Content = String.Format("<script>window.top.location = '{0}';</script>", loginUrl.AbsoluteUri);

src/Microsoft.AspNet.Mvc.Facebook/Microsoft.AspNet.Mvc.Facebook.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@
128128
</Compile>
129129
</ItemGroup>
130130
<ItemGroup>
131-
<None Include="App.config">
132-
<SubType>Designer</SubType>
133-
</None>
134131
<None Include="packages.config">
135132
<SubType>Designer</SubType>
136133
</None>

src/Microsoft.AspNet.Mvc.Facebook/Services/FacebookSettings.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace Microsoft.AspNet.Mvc.Facebook.Services
66
{
77
public static class FacebookSettings
88
{
9+
private static string _facebookAppUrl = "https://apps.facebook.com";
10+
911
static FacebookSettings()
1012
{
1113
DefaultUserStorageService = DefaultFacebookUserStorageService.Instance;
@@ -21,13 +23,25 @@ static FacebookSettings()
2123

2224
public static IFacebookUserStorageService DefaultUserStorageService { get; set; }
2325
public static IFacebookObjectStorageService DefaultObjectStorageService { get; set; }
26+
public static string FacebookAppUrl
27+
{
28+
get
29+
{
30+
return _facebookAppUrl;
31+
}
32+
set
33+
{
34+
_facebookAppUrl = value;
35+
}
36+
}
2437

2538
public static void LoadFromConfig()
2639
{
2740
AppId = ConfigurationManager.AppSettings["Facebook.AppId"];
2841
AppSecret = ConfigurationManager.AppSettings["Facebook.AppSecret"];
2942
AppNamespace = ConfigurationManager.AppSettings["Facebook.AppNamespace"];
3043
RealtimeCallbackUrl = ConfigurationManager.AppSettings["Facebook.RealtimeCallbackUrl"];
44+
FacebookAppUrl = ConfigurationManager.AppSettings["Facebook.FacebookAppUrl"] ?? _facebookAppUrl;
3145
}
3246
}
3347
}

src/Microsoft.AspNet.Mvc.Facebook/packages.config

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="AspNetMvc" version="4.0.20710.0" targetFramework="net40" />
4-
<package id="AspNetWebApi" version="4.0.20710.0" targetFramework="net40" />
53
<package id="EntityFramework" version="5.0.0" targetFramework="net40" />
64
<package id="Facebook" version="6.0.24" targetFramework="net40" />
75
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net40" />

0 commit comments

Comments
 (0)