Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
openid.loadAssociation(params['openid.assoc_handle'], function(error, association)
{
if(error)
{
return callback({ message: 'Error loading association' }, { authenticated: false });
}
if(!association)
{
return callback({ message:'Invalid association handle' }, { authenticated: false });
}
if(association.provider.version.indexOf('2.0') !== -1 && association.provider.endpoint !== params['openid.op_endpoint'])
{
return callback({ message:'Association handle does not match provided endpoint' }, {authenticated: false});
}
var message = '';
var signedParams = params['openid.signed'].split(',');
for(var i = 0; i < signedParams.length; i++)
{
var param = signedParams[i];
var value = params['openid.' + param];
if(!_isDef(value))
{
return callback({ message: 'At least one parameter referred in signature is not present in response' }, { authenticated: false });
}
message += param + ':' + value + '\n';
}
openid.loadAssociation(params['openid.assoc_handle'], function(error, association)
{
if(error)
{
return callback({ message: 'Error loading association' }, { authenticated: false });
}
if(!association)
{
return callback({ message:'Invalid association handle' }, { authenticated: false });
}
if(association.provider.version.indexOf('2.0') !== -1 && association.provider.endpoint !== params['openid.op_endpoint'])
{
return callback({ message:'Association handle does not match provided endpoint' }, {authenticated: false});
}
var message = '';
var signedParams = params['openid.signed'].split(',');
for(var i = 0; i < signedParams.length; i++)
{
var param = signedParams[i];
var value = params['openid.' + param];
if(!_isDef(value))
{
return callback({ message: 'At least one parameter referred in signature is not present in response' }, { authenticated: false });
}
message += param + ':' + value + '\n';
}
var _checkSignatureUsingProvider = function(params, provider, callback)
{
var requestParams =
{
'openid.mode' : 'check_authentication'
};
for(var key in params)
{
if(hasOwnProperty(params, key) && key != 'openid.mode')
{
requestParams[key] = params[key];
}
}
_post(_isDef(params['openid.ns']) ? (params['openid.op_endpoint'] || provider.endpoint) : provider.endpoint, requestParams, function(data, headers, statusCode)
{
if(statusCode != 200 || data == null)
{
return callback({ message: 'Invalid assertion response from provider' }, { authenticated: false });
}
else
{
data = _decodePostData(data);
if(data['is_valid'] == 'true')
{
return callback(null, { authenticated: true, claimedIdentifier: provider.version.indexOf('2.0') !== -1 ? params['openid.claimed_id'] : params['openid.identity'] });
}
else
{
return callback({ message: 'Invalid signature' }, { authenticated: false });
}
var _checkSignatureUsingProvider = function(params, provider, callback)
{
var requestParams =
{
'openid.mode' : 'check_authentication'
};
for(var key in params)
{
if(params.hasOwnProperty(key) && key != 'openid.mode')
{
requestParams[key] = params[key];
}
}
_post(_isDef(params['openid.ns']) ? (params['openid.op_endpoint'] || provider.endpoint) : provider.endpoint, requestParams, function(data, headers, statusCode)
{
if(statusCode != 200 || data == null)
{
return callback({ message: 'Invalid assertion response from provider' }, { authenticated: false });
}
else
{
data = _decodePostData(data);
if(data['is_valid'] == 'true')
{
return callback(null, { authenticated: true, claimedIdentifier: provider.version.indexOf('2.0') !== -1 ? params['openid.claimed_id'] : params['openid.identity'] });
}
else
{
return callback({ message: 'Invalid signature' }, { authenticated: false });
var _verifyAssertionAgainstProvider = function(provider, params, stateless, extensions, callback)
{
if(provider.version.indexOf('2.0') !== -1)
{
var endpoint = params['openid.op_endpoint'];
if (endpoint) {
var qsIndex = endpoint.indexOf('?');
if (qsIndex !== -1) {
endpoint = endpoint.substring(0, qsIndex);
}
}
if (provider.endpoint != endpoint)
{
return callback({ message: 'OpenID provider endpoint in assertion response does not match discovered OpenID provider endpoint' });
}
if(provider.claimedIdentifier) {
var claimedIdentifier = _getCanonicalClaimedIdentifier(params['openid.claimed_id']);
if(provider.claimedIdentifier != claimedIdentifier) {
return callback({ message: 'Claimed identifier in assertion response does not match discovered claimed identifier' });
}
}
var _verifyAssertionAgainstProviders = function(providers, params, stateless, extensions, callback)
{
for(var i = 0; i < providers.length; ++i)
{
var provider = providers[i];
if(!!params['openid.ns'] && (!provider.version || provider.version.indexOf(params['openid.ns']) !== 0))
{
continue;
}
if(!!provider.version && provider.version.indexOf('2.0') !== -1)
{
var endpoint = params['openid.op_endpoint'];
if (provider.endpoint != endpoint)
{
continue;
}
if(provider.claimedIdentifier) {
var claimedIdentifier = _getCanonicalClaimedIdentifier(params['openid.claimed_id']);
if(provider.claimedIdentifier != claimedIdentifier) {
return callback({ message: 'Claimed identifier in assertion response does not match discovered claimed identifier' });
}
}
}
if(!!provider.localIdentifier && provider.localIdentifier != params['openid.identity'])
{
return callback({ message: 'Identity in assertion response does not match discovered local identifier' });
}
relyingParty.verifyAssertion(request, function(error, result) {
var isGood = !error && result.authenticated ? '<h1>Success!</h1>' : '<h1>Failed</h1>';
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.write(isGood);
res.write('<p>' + query['openid.assoc_handle'] + '</p>');
res.write('<p>' + query['openid.claimed_id'] + '</p>');
res.write('<p>' + query['openid.identity'] + '</p>');
res.write('<p>' + query['openid.mode'] + '</p>');
res.write('<p>' + query['openid.ns'] + '</p>');
res.write('<p>' + query['openid.op_endpoint'] + '</p>');
res.write('<p>' + query['openid.response_nonce'] + '</p>');
res.write('<p>' + query['openid.return_to'] + '</p>');
res.write('<p>' + query['openid.sig'] + '</p>');
res.write('<p>' + query['openid.signed'] + '</p>');
res.end('bye');
});
});