/// <summary>Gets the URL where the user should be redirect to.</summary>
        /// <param name="context">The <see cref="ReturnEndpointContext"/> for the current authentication session.</param>
        /// <returns>The URL where the user should be redirect to.</returns>
        private static string GetRedirectLocation(ReturnEndpointContext context)
        {
            var location = context.RedirectUri;

            if (context.Identity == null)
            {
                location =
                    WebUtilities.AddQueryString(
                        location,
                        ImgurAuthenticationDefaults.ErrorParameter,
                        ImgurAuthenticationDefaults.AccessDeniedErrorMessage);
            }

            return(location);
        }
        /// <summary>Adds authentication information to the OWIN context to let the appropriate <see cref="AuthenticationMiddleware{TOptions}"/> authenticate the user.</summary>
        /// <param name="context">The <see cref="ReturnEndpointContext"/> for the current authentication session.</param>
        private void SignIn(ReturnEndpointContext context)
        {
            if (context.SignInAsAuthenticationType == null || context.Identity == null)
            {
                return;
            }

            var identity = context.Identity;

            if (!identity.AuthenticationType.Equals(context.SignInAsAuthenticationType, StringComparison.OrdinalIgnoreCase))
            {
                identity =
                    new ClaimsIdentity(
                        identity.Claims,
                        context.SignInAsAuthenticationType,
                        identity.NameClaimType,
                        identity.RoleClaimType);
            }

            this.Context.Authentication.SignIn(context.Properties, identity);
        }