4

I have a very simple web app consisting of the default ASP.NET Core web application to which I've added the Facebook OAuth provider and an Sqlite database.

Got it working locally without any trouble but when I deploy to Azure, I started getting errors.

After a while I got to an error stating:

An error occurred while starting the application 

After searching the internet for a couple of hours and trying various ways to actually see the error, I stumbled upon the answer here.

Now I could see the error details:

ArgumentException: The 'ClientId' option must be provided.
Microsoft.AspNetCore.Authentication.OAuth.OAuthMiddleware..ctor(RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, UrlEncoder encoder, IOptions<SharedAuthenticationOptions> sharedOptions, IOptions<TOptions> options)
Microsoft.AspNetCore.Authentication.Facebook.FacebookMiddleware..ctor(RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, UrlEncoder encoder, IOptions<SharedAuthenticationOptions> sharedOptions, IOptions<FacebookOptions> options)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.Extensions.Internal.ActivatorUtilities+ConstructorMatcher.CreateInstance(IServiceProvider provider)
Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+<>c__DisplayClass3_0.<UseMiddleware>b__0(RequestDelegate next)
Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

This is weird because all the documentation I can find online says you should only need AppId and AppSecret for Facebook. I followed the Microsoft guide to get this configured. Here is the relevant bit of Startup.cs:

    app.UseFacebookAuthentication(new FacebookOptions()
    {
        AppId = Configuration["Authentication:Facebook:AppId"],
        AppSecret = Configuration["Authentication:Facebook:AppSecret"]
    });

I've found examples showing ClientId being used for the Google and Microsoft providers but not Facebook. (it's a big page but just search for 'ClientId') I've tried adding ClientId but just get the same error.

1
  • It says client id because that's what app id maps to on the base class and in the protocol. Facebook uses a non standard name in their docs for some reason. You could file a bug for a more specific error message. Commented Jan 31, 2018 at 14:16

4 Answers 4

5

You're getting this error because the key Authentication:Facebook:AppId can't be found in your Configuration object. On a typical ASP.NET Core application, that object is filled from the appsettings.json file.

You're saying that it works locally, but not on Azure, which probably means that you configured your Facebook auth in appsettings.Development.json, which is used on your Dev box but not when deploying to Azure.

So to sum up, your appsettings.json file should look like this:

{
  "Authentication": {
    "Facebook": {
      "Id": "1943349465943333",
      "AppSecret": "4bbc86c773aa1df91d52b421e129433"
    }
  }
}

You can see https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration for more information.

Sign up to request clarification or add additional context in comments.

1 Comment

That sounds like a reasonable explanation. I didn't end up needing Facebook authentication for this project and I'm no longer working on it but will try to remember to try it out when I get a minute.
1

i have the same problem and when i hard code the values it works

app.UseFacebookAuthentication(new FacebookOptions()
            {
                //AppId = Configuration["Authentication:Facebook:Id"],
                //AppSecret = Configuration["Authentication:Facebook:AppSecret"]

                AppId = "1943349465943333",
                AppSecret = "4bbc86c773aa1df91d52b421e129433"


            });

try hard coding your values and see. unless you found the answer and then please share

1 Comment

Thanks, will try that.
0

ERROR: ArgumentException: The 'AppId' option must be provided. (Parameter 'AppId') Microsoft.AspNetCore.Authentication.Facebook.FacebookOptions.Validate()

This worked for me in .net 6 facebook login error. Just removed configuration[] and that was it.

var builder = WebApplication.CreateBuilder(args);

var services = builder.Services;
var configuration = builder.Configuration;

services.AddAuthentication().AddFacebook(facebookOptions =>
    {
        facebookOptions.AppId = "Authentication:Facebook:AppId";
        facebookOptions.AppSecret = "Authentication:Facebook:AppSecret";
    });

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
-1

Just remove the tag ... Configuration[

...and it should work

instead of this,

app.UseFacebookAuthentication(new FacebookOptions()
{
    AppId = Configuration["Authentication:Facebook:AppId"],
    AppSecret = Configuration["Authentication:Facebook:AppSecret"]
});

use this

app.UseFacebookAuthentication(new FacebookOptions()
{
    AppId ="Authentication:Facebook:AppId"],
    AppSecret = "Authentication:Facebook:AppSecret"]
});

2 Comments

Removing Configuration[ will simply prevent the information from being retrieved from the configuration, and will just hardcode the Id and AppSecret (like @yvanstack suggested).
And doesn't compile due to the trailing ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.