protected virtual async Task <AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens)
        {
            using (var user = JsonDocument.Parse("{}"))
            {
                var context = new OAuthCreatingTicketContext(new ClaimsPrincipal(identity), properties, Context, Scheme, Options, Backchannel, tokens, user.RootElement);
                await Events.CreatingTicket(context);

                return(new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name));
            }
        }
        /// <summary>
        /// Initializes a new <see cref="OAuthCreatingTicketContext"/>.
        /// </summary>
        /// <param name="ticket">The <see cref="AuthenticationTicket"/>.</param>
        /// <param name="context">The HTTP environment.</param>
        /// <param name="options">The options used by the authentication middleware.</param>
        /// <param name="backchannel">The HTTP client used by the authentication middleware</param>
        /// <param name="tokens">The tokens returned from the token endpoint.</param>
        /// <param name="user">The JSON-serialized user.</param>
        public OAuthCreatingTicketContext(
            AuthenticationTicket ticket,
            HttpContext context,
            OAuthOptions options,
            HttpClient backchannel,
            OAuthTokenResponse tokens,
            JObject user)
            : base(context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (backchannel == null)
            {
                throw new ArgumentNullException(nameof(backchannel));
            }

            if (tokens == null)
            {
                throw new ArgumentNullException(nameof(tokens));
            }

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            TokenResponse = tokens;
            Backchannel = backchannel;
            User = user;
            Options = options;
            Ticket = ticket;
        }
 /// <summary>
 /// Initializes a new <see cref="OAuthCreatingTicketContext"/>.
 /// </summary>
 /// <param name="ticket">The <see cref="AuthenticationTicket"/>.</param>
 /// <param name="context">The HTTP environment.</param>
 /// <param name="options">The options used by the authentication middleware.</param>
 /// <param name="backchannel">The HTTP client used by the authentication middleware</param>
 /// <param name="tokens">The tokens returned from the token endpoint.</param>
 public OAuthCreatingTicketContext(
     AuthenticationTicket ticket,
     HttpContext context,
     OAuthOptions options,
     HttpClient backchannel,
     OAuthTokenResponse tokens)
     : this(ticket, context, options, backchannel, tokens, user: new JObject())
 {
 }