Facebook OAuth +随机端口上的 AppHarbor 解决方法

发布于 2024-12-26 20:53:12 字数 1396 浏览 3 评论 0原文

我有一个示例应用程序,托管在 AppHarbor 上,现在想通过 facebook 集成授权。所以我下载了 Facebook.Web.Mvc 包来实现它。

阅读教程后,在控制器中我有方法:

 public ActionResult Login(string returnUrl)
    {
        var oauthClient = new FacebookOAuthClient(FacebookApplication.Current) { RedirectUri = GetFacebookRedirectUri() };


        if (!string.IsNullOrWhiteSpace(returnUrl))
        {
            returnUrl = Url.Action("Index", "Facebook");
        }

        dynamic parameters = new ExpandoObject();
        parameters.scope = ExtendedPermissions;

        var state = new { csrf_token = CalculateMD5Hash(Guid.NewGuid().ToString()), return_url = returnUrl };
        parameters.state = Base64UrlEncode(Encoding.UTF8.GetBytes(JsonSerializer.Current.SerializeObject(state)));
        SetFacebookCsrfToken(state.csrf_token);

        string s = oauthClient.GetLoginUrl(parameters).AbsoluteUri;

        ViewBag.FacebookLoginUrl = s;
        //new LogEvent(s).Raise();

        return View(new AccountModel());
    }

查看:

<a href="@ViewBag.FacebookLoginUrl" id="lUrl">
<div class="fblogin"></div>

在本地主机中,这对我有用。 但是当我将其上传到 appharbor 时,我看到生成的链接指示地址 + 端口 16013(正如支持人员所说的始终是随机端口)。所以点击它会显示 Facebook 登录窗口,而不是空白页面。

我手动将 facebook 中的应用程序设置配置到此端口,但没有帮助。

我还尝试通过这个端口访问我的网站 - 什么也没有。

然后我通过jquery将端口号更改为80,它也没有帮助。

你有过这样的问题吗?

I a have a sample app, hosted on AppHarbor and now want to integrate authorization through facebook. So i downloaded nugget Facebook.Web.Mvc package to implement it.

After reading tutorial, in controller i have method:

 public ActionResult Login(string returnUrl)
    {
        var oauthClient = new FacebookOAuthClient(FacebookApplication.Current) { RedirectUri = GetFacebookRedirectUri() };


        if (!string.IsNullOrWhiteSpace(returnUrl))
        {
            returnUrl = Url.Action("Index", "Facebook");
        }

        dynamic parameters = new ExpandoObject();
        parameters.scope = ExtendedPermissions;

        var state = new { csrf_token = CalculateMD5Hash(Guid.NewGuid().ToString()), return_url = returnUrl };
        parameters.state = Base64UrlEncode(Encoding.UTF8.GetBytes(JsonSerializer.Current.SerializeObject(state)));
        SetFacebookCsrfToken(state.csrf_token);

        string s = oauthClient.GetLoginUrl(parameters).AbsoluteUri;

        ViewBag.FacebookLoginUrl = s;
        //new LogEvent(s).Raise();

        return View(new AccountModel());
    }

View:

<a href="@ViewBag.FacebookLoginUrl" id="lUrl">
<div class="fblogin"></div>

In localhost this works for me.
But when i upload it to appharbor, i see, that generated link indicates to address + port 16013 (as support told always random port). So clicking it shows me facebook login window, than blank page.

I manually configured my app settings in facebook to this port but it did not helped.

Also i tried to access my site through this port - nothing.

Then i changed port number through jquery to 80, its also did not help.

you have had such problems?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

来日方长 2025-01-02 20:53:12

我不熟悉 Facebook api,但我也遇到过类似的问题。
我怀疑传入的 returnUrl 值不正确。它可能包含 AppHarbor 在内部用于负载平衡的端口号。

请参阅这篇文章,了解如何为 AppHarbor 创建公共 url:
http://support.appharbor .com/kb/getting-started/workaround-for-generate-absolute-urls-without-port-number

然后确保 returnUrl 中的值是公开可用的。

I'm not familiar with the Facebook api, but I've had a similar problem.
I suspect that the returnUrl value being passed in is incorrect. It probably contains a port number that AppHarbor uses internally for load balancing.

See this article on how to create a public url for AppHarbor:
http://support.appharbor.com/kb/getting-started/workaround-for-generating-absolute-urls-without-port-number

Then make sure that the value in your returnUrl is publicly available.

断舍离 2025-01-02 20:53:12

现在,您可以将 aspnet:UseHostHeaderForRequestUrl appSetting 设置为 true,从而有效解决此问题。这可以通过使用相应的键和值向应用程序添加配置变量来完成。

AppHarbor 上的来源

You can now set the aspnet:UseHostHeaderForRequestUrl appSetting to true which effectively solves this problem. This can be done by adding a Configuration Variable to your application with the corresponding key and value.

Source on AppHarbor

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文