Vinit Bodhwani
Vinit Bodhwani

Reputation: 435

Facebook oauth error=access_denied in asp.net

Facebook is giving me error=access_denied, while using facebook oauth in my project Here is ,my code :

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);

and 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);
    }
  }
}

Can anyone help?

Upvotes: 1

Views: 646

Answers (1)

Abhishek Jaiswal
Abhishek Jaiswal

Reputation: 253

You don't need to use back channel handler anymore. Install Microsoft.Owin.Security.Facebook -Version 4.0.0 (latest till date)

In Startup.Auth.cs,

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

That's it, you don't need other infos, and delete BackChannelHandler class file

Upvotes: 1

Related Questions