Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had also problems generating a matching signature and finally found the solution.</p> <ol> <li><p>As you already suspected, you have to add the values from the <code>openid.ax</code> namespace applying the same rule of adding the key/value pair without the <code>openid.</code> prefix. If there are no <code>openid.ax</code> keys, then something is wrong.</p></li> <li><p>Yes, the last key/value pair is followed by a newline (attention: only an <code>\n</code>). This could have been mentioned more clearly in the OpenID specification.</p></li> <li><p>You are wrong about the URL encoding, it's exactly the other way around: The values must be <strong>URL-decoded</strong>. Also this is not explicitly told in the spec. Don't confuse colons and semicolons, you are not allowed to have <em>colons</em>, but only in the key part, so there is no problem about this.</p></li> </ol> <p>So if you try with this string and add the missing key/value pairs, it should work:</p> <pre> ns:http://specs.openid.net/auth/2.0 op_endpoint:https://www.google.com/accounts/o8/ud claimed_id:https://www.google.com/accounts/o8/id?id=AItOawlvj7acGYj-NH1kKKl3RswJlLCKpl9LIwk identity:https://www.google.com/accounts/o8/id?id=AItOawlvj7acGYj-NH1kKKl3RswJlLCKpl9LIwk return_to:http://mysite.com/Account/Login.aspx response_nonce:2011-05-12T03:56:09ZoeDC9WFOgOBaAQ assoc_handle:AOQobUdHugprvbsK2-8NCtS2uBomRDGJQGOKDmqEwxco8Rny47rdZlBp ns.ext1:http://openid.net/srv/ax/1.0 ext1.mode:fetch_response ext1.type.firstname:http://axschema.org/namePerson/first ext1.value.firstname:First ext1.type.email:http://schema.openid.net/contact/email ext1.value.email:myemail@gmail.com ext1.type.lastname:http://axschema.org/namePerson/last ext1.value.lastname:Name </pre> <p>This little console application re-generates the signature (using HMAC-SHA256), it needs two parameters:</p> <ul> <li>the complete redirect URL after the successful OpenID authentication (containing the positive assertion keys), can be copied from the web browser's address bar</li> <li>the Base64-encoded MAC key, as returned in the prior association response</li> </ul> <p>Code:</p> <pre><code>using System; public class OpenIdSignatureVerification { public static void Main(string[] args) { if (args.Length != 2) { Console.Error.WriteLine("Usage: assertion_url mac_key"); Environment.Exit(1); } string url = args[0]; int pos = url.IndexOf('?'); if (pos == -1) { Console.Error.WriteLine("No query string found"); Environment.Exit(1); } url = url.Substring(pos + 1); Console.WriteLine(String.Format("Query string: {0}", url)); System.Collections.Generic.Dictionary&lt;string, string&gt; dict = new System.Collections.Generic.Dictionary&lt;string, string&gt;(); foreach (string part in url.Split('&amp;')) { string[] keyValue = part.Split('='); if (keyValue.Length != 2) continue; dict[keyValue[0]] = System.Web.HttpUtility.UrlDecode(keyValue[1]); } string hashInput = String.Empty; string[] signed = dict["openid.signed"].Replace("%2C", ",").Split(','); foreach (string key in signed) hashInput += key + ":" + dict["openid." + key] + "\n"; string macKey = args[1]; Console.WriteLine(String.Format("Hash input: {0}\n", hashInput)); Console.WriteLine(String.Format("MAC Key: {0}", macKey)); byte[] encodedHashInput = System.Text.Encoding.UTF8.GetBytes(hashInput); System.Security.Cryptography.HMACSHA256 signer = new System.Security.Cryptography.HMACSHA256(Convert.FromBase64String(macKey)); string hashOutput = Convert.ToBase64String(signer.ComputeHash(encodedHashInput)); Console.WriteLine(String.Format("Signature hash (expected) : {0}", dict["openid.sig"])); Console.WriteLine(String.Format("Signature hash (calculated): {0}", hashOutput)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload