Facebook oauth error = access_denied in asp.net

时间:2017-05-31 18:50:22

标签: asp.net facebook-oauth

Facebook正在给我一个错误= access_denied,同时在我的项目中使用facebook oauth 这是我的代码:

var facebookOptions = new FacebookAuthenticationOptions()
        {
            AppId = "---",
            AppSecret = "---",
            BackchannelHttpHandler = new FacebookBackChannelHandler(),
            UserInformationEndpoint = "https://graph.facebook.com/v2.4/me?fields=id,email"
        };


        facebookOptions.Scope.Add("email");
        app.UseFacebookAuthentication(facebookOptions);

和FacebookBackChannelHandler.js:

namespace naah2.Facebook
 {
 public class FacebookBackChannelHandler : HttpClientHandler
 {
    protected override async Task<HttpResponseMessage>
        SendAsync(HttpRequestMessage request,
                  CancellationToken cancellationToken)
    {
        if (!request.RequestUri.AbsolutePath.Contains("/oauth"))
        {
            request.RequestUri = new Uri(
                request.RequestUri.AbsoluteUri.Replace("?access_token", "&access_token"));
        }
        return await base.SendAsync(request, cancellationToken);
    }
  }
}

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

您不再需要使用反向通道处理程序。 安装Microsoft.Owin.Security.Facebook-4.0.0版(最新)

Startup.Auth.cs中,

app.UseFacebookAuthentication(
            appId: "xxxxxxxxxx",
            appSecret: "xxxxxxxxxxxxxxxxxxxxxxxxx"
        );

就是这样,您不需要其他信息,并删除BackChannelHandler类文件