Permalink
Browse files

Renamed nkConnect to nk;

Added email addresses to basic profile information retrieved during authentication.
  • Loading branch information...
Kamil Kamiński
Kamil Kamiński committed Mar 8, 2012
1 parent da408d1 commit 59dd207c0f24b58ff07390291ed80304c1bcc74d
View
@@ -96,7 +96,7 @@ app.use(connect.static(__dirname + '/public'))
, auth.Openid({callback: openIdCallback})
, auth.Yammer({consumerKey: yammerConsumerKey, yammerSecret: yammerConsumerSecret, callback: yammerCallback})
, auth.Linkedin({consumerKey: linkedinConsumerKey, consumerSecret: linkedinConsumerSecret, callback: linkedinCallback})
, auth.Nkconnect({appId : nkConnectId, appSecret: nkConnectSecret, callback: nkConnectCallbackAddress})],
, auth.Nk({appId : nkConnectId, appSecret: nkConnectSecret, callback: nkConnectCallbackAddress})],
trace: true,
logoutHandler: require('../lib/events').redirectOnLogout("/")}))
.use(example_auth_middleware())
@@ -36,4 +36,4 @@ exports.yammerConsumerSecret= "";
exports.yammerCallback= "http://localhost/auth/yammer_callback";
exports.nkConnectId = "";
exports.nkConnectSecret = "";
exports.nkConnectCallbackAddress = "http://localhost/auth/nkConnect_callback";
exports.nkConnectCallbackAddress = "http://localhost/auth/nk_callback";
@@ -169,7 +169,7 @@ <h2>OAuth 2</h2>
</tr>
<tr class="row-a">
<td class="first">nkConnect</td>
<td><a href="?login_with=nkConnect">Try It!</a></td>
<td><a href="?login_with=nk">Try It!</a></td>
</tr>
<tr class="row-b">
<td class="first">Janrain</td>
@@ -21,19 +21,21 @@ module.exports= function(options, server) {
my._rest_oAuth= new OAuth1('http://opensocial.nk-net.pl/v09/rest/', 'http://opensocial.nk-net.pl/v09/token/get/', options.appId, options.appSecret, '1.0', null, 'HMAC-SHA1', null, {"Accept" : "*/*",
"Connection" : "close",
"User-Agent" : "Node authentication",
"Content-Type" : "application/json"});
"Content-Type" : "application/json"});
my._redirectUri= options.callback;
my.scope= options.scope || "BASIC_PROFILE_ROLE";
my.scope= options.scope || "BASIC_PROFILE_ROLE,EMAIL_PROFILE_ROLE";
my.display =options.display || "page";
// Give the strategy a name
that.name = options.name || "nkConnect";
that.name = options.name || "nk";
// Build the authentication routes required
that.setupRoutes= function(app) {
app.use('/auth/nkConnect_callback', function(req, res){
app.use('/auth/nk_callback', function(req, res){
req.authenticate([that.name], function(error, authenticated) {
res.writeHead(303, { 'Location': req.session.nkConnect_redirect_url });
console.dir(authenticated);
console.dir(error);
res.writeHead(303, { 'Location': req.session.nk_redirect_url });
res.end('');
});
});
@@ -44,22 +46,22 @@ module.exports= function(options, server) {
//todo: makw the call timeout ....
var parsedUrl= url.parse(request.originalUrl, true);
var self= this;
this._nkConnect_fail= function(callback) {
request.getAuthDetails()['nkConnect_login_attempt_failed'] = true;
this._nk_fail= function(callback) {
request.getAuthDetails()['nk_login_attempt_failed'] = true;
this.fail(callback);
};
if( request.getAuthDetails()['nkConnect_login_attempt_failed'] === true ) {
if( request.getAuthDetails()['nk_login_attempt_failed'] === true ) {
// Because we bounce through authentication calls across multiple requests
// we use this to keep track of the fact we *Really* have failed to authenticate
// so that we don't keep re-trying to authenticate forever.
delete request.getAuthDetails()['nkConnect_login_attempt_failed'];
delete request.getAuthDetails()['nk_login_attempt_failed'];
self.fail( callback );
}
else {
if( parsedUrl.query && ( parsedUrl.query.code || parsedUrl.query.error_reason === 'user_denied' ) ) {
if( parsedUrl.query.error_reason == 'user_denied' ) {
self._nkConnect_fail(callback);
self._nk_fail(callback);
} else {
my._oAuth.getOAuthAccessToken(parsedUrl.query && parsedUrl.query.code ,
{redirect_uri: my._redirectUri,grant_type: 'authorization_code'}, function( error, access_token, refresh_token ){
@@ -68,9 +70,9 @@ module.exports= function(options, server) {
request.session["access_token"]= access_token;
if( refresh_token ) request.session["refresh_token"]= refresh_token;
my._rest_oAuth._performSecureRequest(null, '', 'GET', "http://opensocial.nk-net.pl/v09/social/rest/people/@me?fields=id,displayName,thumbnailUrl&nk_token="+request.session['access_token'], {}, '', 'application/json', function(error, data, response) {
my._rest_oAuth._performSecureRequest(null, '', 'GET', "http://opensocial.nk-net.pl/v09/social/rest/people/@me?fields=id,displayName,thumbnailUrl,emails&nk_token="+request.session['access_token'], {}, '', 'application/json', function(error, data, response) {
if( error ) {
self._nkConnect_fail(callback);
self._nk_fail(callback);
}else {
self.success(JSON.parse(data).entry, callback);
}
@@ -80,7 +82,7 @@ module.exports= function(options, server) {
}
}
else {
request.session['nkConnect_redirect_url']= request.originalUrl;
request.session['nk_redirect_url']= request.originalUrl;
var redirectUrl= my._oAuth.getAuthorizeUrl({redirect_uri : my._redirectUri, scope: my.scope, display:my.display, response_type: 'code'});
self.redirect(response, redirectUrl, callback);
}

0 comments on commit 59dd207

Please sign in to comment.