Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static string HandleRequest(HttpListenerContext context)
- {
- try
- {
- // Check whether we got a successful response:
- string code = context.Request.QueryString["code"];
- if (!string.IsNullOrEmpty(code))
- {
- return code;
- }
- // Check whether we got an error response:
- string error = context.Request.QueryString["error"];
- if (!string.IsNullOrEmpty(error))
- {
- return null; // Request cancelled by user.
- }
- // The response is unknown to us. Choose a different authentication flow.
- throw new NotSupportedException(
- "Received an unknown response: " + Environment.NewLine + context.Request.RawUrl);
- }
- finally
- {
- // Write a response.
- using (var writer = new StreamWriter(context.Response.OutputStream))
- {
- string response =
- "<head><title>{APP} - OAuth Authentication</title></head><body><h1>Authorization for {APP}</h1>" +
- "<p>The application has received your response. You can close this window now.</p>" +
- "<script type='text/javascript'>window.setTimeout(function() { window.open('', '_self', ''); window.close(); " +
- "}, 100); if (window.opener) { window.opener.checkToken(); } </script> </body> </html>";
- writer.WriteLine(response);
- writer.Flush();
- }
- context.Response.OutputStream.Close();
- context.Response.Close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement