internal static void BadRequest(this IOwinContext context, AuthenticationRequestException exception, string contentType = "")
        {
            var state = GetState(context);
            var redirect_uri = GetRedirectUri(context);

            var response = new AuthenticationErrorResponse(exception.error, exception.error_description, state);

            context.Response.StatusCode = 400;
            context.Response.ReasonPhrase = $"Bad Request";

            if (string.IsNullOrEmpty(redirect_uri))
            {
                context.Response.ContentType = "application/json";
                context.Response.Write(response.Json());
            }
            else
            {
                context.Response.Redirect(response.UrlEncoded(redirect_uri));
            }
        }
        internal static void Unauthorized(this IOwinContext context, OAuthOptions options, UnauthorizedException ex)
        {
            context.Response.StatusCode = 403;
            context.Response.ReasonPhrase = "Forbidden";

            if (ex.prompt.Equals("login"))
            {
                var url = $"{options.AuthorizationUri.Value}{context.Request.QueryString}";
                context.Response.Redirect(url);
            }
            else if (ex.prompt.Equals("none"))
            {
                var state = GetState(context);
                var response = new AuthenticationErrorResponse(ex.error, ex.error_description, state);

                context.Response.ContentType = "application/json";
                context.Response.Write(response.Json());
            }
        }