protected override Task ApplyResponseChallengeAsync()
        {
            if (Response.StatusCode != 401)
            {
                return(Task.FromResult <object>(null));
            }

            AuthenticationResponseChallenge challenge = Helper.LookupChallenge(Options.AuthenticationType, Options.AuthenticationMode);

            if (challenge != null)
            {
                string baseUri     = Request.Scheme + Uri.SchemeDelimiter + Request.Host + Request.PathBase;
                string currentUri  = baseUri + Request.Path + Request.QueryString;
                string redirectUri = baseUri + Options.CallbackPath;

                AuthenticationProperties properties = challenge.Properties;
                if (string.IsNullOrEmpty(properties.RedirectUri))
                {
                    properties.RedirectUri = currentUri;
                }

                // OAuth2 10.12 CSRF
                GenerateCorrelationId(properties);

                // OAuth2 3.3 space separated
                string scope = string.Join(" ", Options.Scope); // Note, the BioID server does not require a scope string, it uses 'basic' by default.
                string state = Options.StateDataFormat.Protect(properties);

                // OAuth2 4.1.1 Authorization Request
                string authorizationEndpoint = AuthorizationEndpoint +
                                               "?client_id=" + Uri.EscapeDataString(Options.ClientId) +
                                               "&scope=" + Uri.EscapeDataString(scope) +
                                               "&response_type=code" +
                                               "&redirect_uri=" + Uri.EscapeDataString(redirectUri) +
                                               "&state=" + Uri.EscapeDataString(state);

                var redirectContext = new BioIDApplyRedirectContext(Context, Options, properties, authorizationEndpoint);
                Options.Provider.ApplyRedirect(redirectContext);
            }

            return(Task.FromResult <object>(null));
        }
 /// <summary>
 /// Called when a Challenge causes a redirect to authorize endpoint in the BioID account middleware
 /// </summary>
 /// <param name="context">Contains redirect URI and <see cref="AuthenticationProperties"/> of the challenge </param>
 public virtual void ApplyRedirect(BioIDApplyRedirectContext context)
 {
     OnApplyRedirect(context);
 }