Facebook的改变网页REDIRECT_URI API [英] change facebook redirect_uri web api

查看:345
本文介绍了Facebook的改变网页REDIRECT_URI API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果有人能够给我一个手或点我在正确的方向。我设置Facebook社交登入我的网页API 2项目中,它工作正常。然而,当我将其部署到生产我发现,REDIRECT_URI是显示HTTP,而不是HTTPS,这将导致崩溃的服务。

我想知道是REDIRECT_URI首先如何构造以及是否有更新它的任何东西。

这是发生的全部原因是因为我们的负载平衡器。该网站是HTTP协议下运行,但负载均衡器接受HTTPS流量并重定向到HTTP。不幸的是,我无法更新负载平衡器因此需要找到一个解决办法。

我曾尝试拦截 IFacebookAuthenticationProvider ApplyRedirect 方法REDIRECT_URI,这成功地让我改变了从REDIRECT_URI HTTP到HTTPS。然而,当我这样做,一旦我登录到Facebook的我会得到的ACCESS_DENIED平坦的错误,不知道这是为什么发生的。

可能有人请帮助我得到这个实现的?我可以明确地标记为HTTPS?

的REDIRECT_URI和饼干被Facebook设置

这是我的Facebook Provider类

 公共类FacebookAuthProvider:IFacebookAuthenticationProvider
{
    公共无效ApplyRedirect(FacebookApplyRedirectContext上下文)
    {
        字符串REDIRECT_URI = context.RedirectUri;
        REDIRECT_URI = redirect_uri.Replace(REDIRECT_URI = HTTP,REDIRECT_URI = https开头);
        context.Response.Redirect(REDIRECT_URI);
    }    公共任务认证(FacebookAuthenticatedContext上下文)
    {
        context.Identity.AddClaim(新索赔(ExternalAccessToken,context.AccessToken));
        返回Task.FromResult<对象>(NULL);
    }    公共任务ReturnEndpoint(FacebookReturnEndpointContext上下文)
    {
        返回Task.FromResult<对象>(NULL);
    }
}


解决方案

要做到这一点,最好的办法就是在你的应用程序的开始更新请求方案。事情是这样的:

  app.Use((背景下,下一个)=>
{
  context.Request.Scheme =htt​​ps开头;
  返回下一个();
});

I was wondering if someone could give me a hand or point me in the right direction. I've setup facebook social sign in within my web api 2 project and it works correctly. However, when I deploy it to production I have found that the redirect_uri is showing HTTP instead of HTTPS and this causes the service to crash.

What I wanted to know was firstly how the redirect_uri is constructed and whether there was any way of updating it.

The whole reason this is happening is because of our load balancer. The site is running under the HTTP protocol but the loadbalancer accepts HTTPS traffic and redirects it to HTTP. Unfortunately, I cannot update the Loadbalancer so need to find a workaround.

I did try to intercept the redirect_uri in the ApplyRedirect method of IFacebookAuthenticationProvider and this successfully allowed me to change the redirect_uri from HTTP to HTTPS. However, when I did that I would get a flat error of access_denied once I had logged into Facebook and didn't know why this was occurring.

Could someone please help me get this implemented? Can I explicitly mark the redirect_uri and cookie set by facebook to HTTPS?

This is my Facebook Provider class

public class FacebookAuthProvider : IFacebookAuthenticationProvider
{
    public void ApplyRedirect(FacebookApplyRedirectContext context)
    {
        string redirect_uri = context.RedirectUri;
        redirect_uri = redirect_uri.Replace("redirect_uri=http", "redirect_uri=https");
        context.Response.Redirect(redirect_uri);
    }

    public Task Authenticated(FacebookAuthenticatedContext context)
    {
        context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken));
        return Task.FromResult<object>(null);
    }

    public Task ReturnEndpoint(FacebookReturnEndpointContext context)
    {
        return Task.FromResult<object>(null);
    }
}

解决方案

The best way to do this is to update the request scheme at the beginning of your app. Something like this:

app.Use((context, next) =>
{
  context.Request.Scheme = "https";
  return next();
});

这篇关于Facebook的改变网页REDIRECT_URI API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆