This is my custom provider class:

public class Facebook : IdentityProvidersProcessor
    public Facebook(FederatedAuthenticationConfiguration federatedAuthenticationConfiguration,
                    ICookieManager cookieManager,
                    BaseSettings settings)
                    : base(federatedAuthenticationConfiguration, cookieManager, settings)

    protected override string IdentityProviderName => "Facebook";

    protected override void ProcessCore(IdentityProvidersArgs args)
        Assert.ArgumentNotNull(args, nameof(args));

        var identityProvider = this.GetIdentityProvider();
        var authenticationType = this.GetAuthenticationType();

        var options = new FacebookAuthenticationOptions
            Caption = identityProvider.Caption,
            AuthenticationType = authenticationType,
            AuthenticationMode = AuthenticationMode.Passive,
            AppId = Settings.GetSetting("Feature.Accounts.Facebook.AppId"),
            AppSecret = Settings.GetSetting("Feature.Accounts.Facebook.AppSecret"),
            Provider = new FacebookAuthenticationProvider
                OnAuthenticated = context =>
                    context.Identity.ApplyClaimsTransformations(new TransformationContext(this.FederatedAuthenticationConfiguration, identityProvider));
                    AddClaim(context, "full_name", "name");
                    AddClaim(context, "email", "email");
                    return Task.CompletedTask;
            Scope =
            Fields =

        FacebookAuthenticationExtensions.UseFacebookAuthentication(args.App, options);

    private void AddClaim(FacebookAuthenticatedContext context, string claimName, string propertyName)
        var value = context.User[propertyName]?.ToString();
        if (propertyName == "picture")
            value = context.User["picture"]?["data"]?["url"]?.ToString();
            if (value == null)
            context.Identity.AddClaim(new Claim("picture_url", value));
            context.Identity.AddClaim(new Claim("picture_mime", "image/jpg"));

        if (value == null)
        context.Identity.AddClaim(new Claim(claimName, value));

So i am able to login by using facebook successfully but whenever i am changing the page the cache whatever i added at the time of facebook login getting removed.

  • What kind of cache are you talking about here? There is no cache in your examples.
    – GTHvidsten
    Jan 24, 2020 at 20:49

1 Answer 1


You need to login the FB user into Sitecore as a Virtual User. By doing that,you will be able to check from Sitecore.Context.User.IsAuthenticated on other pages ,if user is logged in/not, then show/hide relevant content. Below code block will create and login the virtual user. This can be used on the OnAuthorizationCodeReceived() of your Facebook pipeline

       User virtualUser = Sitecore.Security.Authentication.AuthenticationManager.BuildVirtualUser(userName, false);


        // Optional: Add the user to an existing extranet role

        // set profile properties
        virtualUser.Profile.Email = userName;
        virtualUser.Profile.Name = displayName;
        virtualUser.Profile.FullName = displayName;
        virtualUser.Profile.Comment = "User Created from Facebook";
        foreach (var prop in properties)
            // virtualUser.Profile.SetCustomProperty(prop.Key, prop.Value);
        virtualUser.RuntimeSettings.IsVirtual = true;

        user = virtualUser;
        _res = true;

        // Login the virtual user

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.