BitId JSON test (Mycelium)

This commit is contained in:
Rick Falkvinge
2014-11-05 22:12:56 +01:00
parent deb357d1e6
commit ced3c8aac1
7 changed files with 37 additions and 11 deletions
+22 -1
View File
@@ -1,7 +1,28 @@
using System.IO;
using System.Globalization;
using System.IO;
namespace System.Web.ExtensionMethods
{
/// <summary>
/// Extension methods for HTTP Response.
/// </summary>
public static class HttpResponseExtensions
{
/// <summary>
/// Set the response to be JSON format, and add appropriate headers.
/// </summary>
/// <param name="response">None.</param>
public static void SetJson(this HttpResponse response)
{
response.ContentType = "application/json";
response.CacheControl = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"; // IE dumbfixes
response.AddHeader("Last-Modified", DateTime.UtcNow.ToString(CultureInfo.InvariantCulture));
response.AddHeader("Pragma", "no-cache");
}
}
/// <summary>
/// Extension methods for HTTP Request.
/// <remarks>
-1
View File
@@ -1 +0,0 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BitId.aspx.cs" Inherits="Swarmops.Security.BitId" %>
+1
View File
@@ -0,0 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FinalizeLogin.aspx.cs" Inherits="Swarmops.Security.FinalizeLogin" %>
@@ -13,7 +13,7 @@ using Swarmops.Logic.Support;
namespace Swarmops.Security
{
public partial class BitId : System.Web.UI.Page
public partial class FinalizeLogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
+6 -3
View File
@@ -52,7 +52,7 @@
success: function (msg) {
if (msg.d) {
// Login confirmed, fetch auth cookie from nonce in-context
document.location = "/Security/BitId.aspx?Nonce=" + bitIdNonce;
document.location = "/Security/FinalizeLogin.aspx?Nonce=" + bitIdNonce;
} else {
// Retry twice per second
setTimeout(function () {
@@ -112,8 +112,11 @@
<div class="box">
<div class="content" style="line-height:24px">
<div style="float:left">User<br/>Pass</div><div style="float:right"><input type="text" />&nbsp;<br/><input type="text"/></div>
<div style="clear:both"></div>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr><td>User&nbsp;&nbsp;</td><td><input type="text" /></td></tr>
<tr><td>Pass&nbsp;&nbsp;</td><td><input type="text" /></td></tr>
<tr><td>2FA&nbsp;&nbsp;</td><td><input type="text" /></td></tr>
</table>
</div>
</div>
+6 -4
View File
@@ -42,6 +42,8 @@ namespace Swarmops.Pages.Security
{
// We should ONLY get here if we're getting a BitId by Webform submission.
Persistence.Key["BitId_RawData"] = Request.ToRaw();
if (Request.Params["address"] != null)
{
// yes, indeed looks like it
@@ -138,10 +140,10 @@ namespace Swarmops.Pages.Security
GuidCache.Set(bitIdUri + "-Logon", "Unauth");
// TODO: need to NOT FUCKING USE GOOGLE CHARTS for this but bring home a free QR package
// TODO: need to NOT USE GOOGLE CHARTS for this but bring home a free QR package
this.ImageBitIdQr.ImageUrl =
"http://chart.apis.google.com/chart?cht=qr&chs=400x400&chl=" + HttpUtility.UrlEncode(bitIdUri);
"https://chart.googleapis.com/chart?cht=qr&chs=400x400&chl=" + HttpUtility.UrlEncode(bitIdUri);
}
@@ -188,13 +190,13 @@ namespace Swarmops.Pages.Security
// TODO: Error codes
response.StatusCode = 200;
response.ContentType = "application/json";
response.SetJson();
response.Write("{\"address\":\"" + credentials.address + "\",\"signature\":\"" + credentials.signature + "\"}");
response.End();
}
else
{
// TODO: return fuckoff code (technical term)
response.StatusCode = 401; // Be a bit more friendly in your return codes
}
}