protected void Page_Load(object sender, EventArgs e) { if (!Request.IsSecureConnection) { throw new HttpException((int)HttpStatusCode.Forbidden, "Authorization requests MUST be on a secure channel"); } if (String.IsNullOrEmpty(Request.PathInfo)) { AuthorizationServer authorizationServer = new AuthorizationServer(new OAuth2AuthorizationServer()); OutgoingWebResponse wr = authorizationServer.HandleTokenRequest(); Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; Response.Write(wr.Body); Response.End(); } else { using (OAuthServiceCall service = new OAuthServiceCall(Request)) { Response.Clear(); Response.ContentType = service.ContentType; service.Execute(Response.OutputStream); Response.End(); } } }
protected void Page_Load(object sender, EventArgs e) { try { if (!Request.IsSecureConnection) { throw new HttpException((int)HttpStatusCode.Forbidden, "Authorization requests MUST be on a secure channel"); } if (String.IsNullOrEmpty(Request.PathInfo)) { AuthorizationServer authorizationServer = new AuthorizationServer(new OAuth2AuthorizationServer()); OutgoingWebResponse wr = authorizationServer.HandleTokenRequest(); Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; Response.Write(wr.Body); Response.End(); } else { using (OAuthServiceCall service = new OAuthServiceCall(Request)) { Response.Clear(); Response.ContentType = service.ContentType; service.Execute(Response.OutputStream); Response.End(); } } } catch (Exception ex) { var o = Request.Params["dbg"]; if (o != null) { Response.Clear(); Response.ContentType = "text/plain"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Write("Error: " + ex.Message + "\r\n"); Response.Write(ex.ToStringDescriptive() + "\r\n"); Response.Flush(); Response.End(); } else { throw; } } }
protected void Page_Load(object sender, EventArgs e) { try { if (!Request.IsSecureConnection) { throw new HttpException((int)HttpStatusCode.Forbidden, "Authorization requests MUST be on a secure channel"); } if (String.IsNullOrEmpty(Request.PathInfo)) { AuthorizationServer authorizationServer = new AuthorizationServer(new OAuth2AuthorizationServer()); OutgoingWebResponse wr = authorizationServer.HandleTokenRequest(); Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; Response.Write(wr.Body); HttpContext.Current.Response.Flush(); // Sends all currently buffered output to the client. HttpContext.Current.Response.SuppressContent = true; // Gets or sets a value indicating whether to send HTTP content to the client. HttpContext.Current.ApplicationInstance.CompleteRequest(); // Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event. } else { using (OAuthServiceCall service = new OAuthServiceCall(Request)) { Response.Clear(); Response.ContentType = service.ContentType; service.Execute(Response.OutputStream); HttpContext.Current.Response.Flush(); // Sends all currently buffered output to the client. HttpContext.Current.Response.SuppressContent = true; // Gets or sets a value indicating whether to send HTTP content to the client. HttpContext.Current.ApplicationInstance.CompleteRequest(); // Causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event. } } } catch (Exception ex) { Response.Clear(); Response.ContentType = "text/plain"; Response.StatusCode = (int)HttpStatusCode.InternalServerError; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Write("Error: " + ex.Message + "\r\n"); Response.Write(ex.ToStringDescriptive() + "\r\n"); Response.Flush(); Response.End(); } }