/// <summary>
        /// Adds the <see cref="EasyAuthAuthenticationHandler"/> for authentication.
        /// </summary>
        /// <param name="builder"><inheritdoc/></param>
        /// <param name="configuration">The configuration object of the application.</param>
        /// <param name="authenticationScheme">The schema for the Easy Auth handler.</param>
        /// <param name="displayName">The display name for the Easy Auth handler.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static AuthenticationBuilder AddEasyAuth(
            this AuthenticationBuilder builder,
            IConfiguration configuration,
            string authenticationScheme,
            string displayName)
        {
            var options = new EasyAuthAuthenticationOptions
            {
                ProviderOptions = configuration
                                  .GetSection("easyAuthOptions:providerOptions")
                                  .GetChildren()
                                  .Select(d =>
                {
                    var name            = d.GetValue <string>("ProviderName");
                    var providerOptions = new ProviderOptions(name);
                    d.Bind(providerOptions);
                    return(providerOptions);
                }).ToList(),
                LocalProviderOption = configuration
                                      .GetSection("easyAuthOptions:localProviderOption")
                                      .Get <LocalProviderOption>()
            };

            return(builder.AddEasyAuth(authenticationScheme, displayName, o =>
            {
                o.LocalProviderOption = options.LocalProviderOption;
                o.ProviderOptions = options.ProviderOptions;
            }));
        }
        /// <summary>
        /// Build a `AuthenticationTicket` from the given payload, the principal name and the provider name.
        /// </summary>
        /// <param name="claimsPayload">A array of JObjects that have a `type` and a `val` property.</param>
        /// <param name="providerName">The provider name of the current auth provider.</param>
        /// <param name="options">The <c>EasyAuthAuthenticationOptions</c> to use.</param>
        /// <returns>A `AuthenticationTicket`.</returns>
        public static AuthenticationTicket Build(IEnumerable <JObject> claimsPayload, string providerName, EasyAuthAuthenticationOptions options)
        {
            // setting ClaimsIdentity.AuthenticationType to value that Azure AD non-EasyAuth setups use
            var identity = new ClaimsIdentity(
                CreateClaims(claimsPayload),
                AuthenticationTypesNames.Federation,
                options.NameClaimType,
                options.RoleClaimType
                );

            AddScopeClaim(identity);
            AddProviderNameClaim(identity, providerName);
            var genericPrincipal = new ClaimsPrincipal(identity);

            return(new AuthenticationTicket(genericPrincipal, EasyAuthAuthenticationDefaults.AuthenticationScheme));
        }