exports.testVerificationUrl = function(test)
{
  openid.verifyAssertion('http://fu', function(result)
  {
    assert.ok(!result.authenticated);
    test.done();
  });
}
Exemplo n.º 2
0
 function(req, res)
 {
     var parsedUrl = url.parse(req.url);
     if(parsedUrl.pathname == '/verify')
     {
         // Verify identity assertion
         var result = openid.verifyAssertion(req); // or req.url
         var attributes = [];
         var sreg = new openid.SimpleRegistration(result);
         for (var k in sreg)
           attributes.push(k + ": " + sreg[k]);
         var ax = new openid.AttributeExchange(result);
         for (var k in ax)
           attributes.push(k + ": " + ax[k]);
         res.writeHead(200);
         res.end(result.authenticated ? 'Success :)\n' + attributes.join("\n") : 'Failure :(\n' + result.error);
     }
     else if(parsedUrl.pathname == '/authenticate')
     {
         // Resolve identifier, associate, build authentication URL
         openid.authenticate(
             querystring.parse(parsedUrl.query).openid_identifier, // user supplied identifier
             'http://example.com/verify', // our callback URL
             null, // realm (optional)
             false, // attempt immediate authentication first?
             function(authUrl, error)
             {
                 if (error)
                 {
                     res.writeHead(200);
                     res.end(error);
                     return;
                 }
                 res.writeHead(302, { Location: authUrl });
                 res.end();
             }, [new openid.UserInterface(), new openid.SimpleRegistration({
               "nickname" : true, "email" : true, "fullname" : true,
               "dob" : true, "gender" : true, "postcode" : true,
               "country" : true, "language" : true, "timezone" : true}),
               new openid.AttributeExchange({
               "http://axschema.org/contact/email": "required",
               "http://axschema.org/namePerson/friendly": "required",
               "http://axschema.org/namePerson": "required"})]);
     }
     else
     {
         // Deliver an OpenID form on all other URLs
         res.writeHead(200);
         res.end('<!DOCTYPE html><html><body>'
             + '<form method="get" action="/authenticate">'
             + '<p>Login using OpenID</p>'
             + '<input name="openid_identifier" />'
             + '<input type="submit" value="Login" />'
             + '</form></body></html>');
     }
 });
Exemplo n.º 3
0
exports.testVerificationCancel = function(test)
{
  var times = 0;
  openid.verifyAssertion(
      'http://host/?openid.mode=cancel' +
      '&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0',
      function(result)
  {
    assert.ok(!times++);
    assert.ok(!result.authenticated);
    test.done();
  });
}