Skip to content
Browse files

added dailycred

  • Loading branch information...
1 parent 9f2c438 commit fafc486dd3a084723b6dafbfff8406b5f7b4de19 @hstove hstove committed Jul 9, 2012
Showing with 3,169 additions and 2 deletions.
  1. +5 −1 example/conf.js
  2. +3,091 −0 example/npm-debug.log
  3. +10 −1 example/server.js
  4. +2 −0 example/views/home.jade
  5. +61 −0 lib/modules/dailycred.js
View
6 example/conf.js
@@ -1,5 +1,9 @@
module.exports = {
- fb: {
+ dc: {
+ appId: '97929309-8716-4daf-a2b1-10c621c4380f',
+ appSecret: '50ff0e1a-e737-4932-b2de-d0a6898cf1c6-4b747134-ed6c-435f-8dad-c1261e72666a',
+ }
+ , fb: {
appId: '111565172259433'
, appSecret: '85f7e0a0cc804886180b887c1f04a3c1'
}
View
3,091 example/npm-debug.log
3,091 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
11 example/server.js
@@ -51,6 +51,7 @@ var usersBySoundCloudId = {};
var usersByMailchimpId = {};
var usersMailruId = {};
var usersByMendeleyId = {};
+var usersByDcId = {};
var usersByLogin = {
'brian@example.com': addUser({ login: 'brian@example.com', password: 'password'})
};
@@ -59,7 +60,15 @@ everyauth.everymodule
.findUserById( function (id, callback) {
callback(null, usersById[id]);
});
-
+
+everyauth.dailycred
+ .appId(conf.dc.appId)
+ .findOrCreateUser( function (session, accessToken, accessTokenExtra, dcUserMetadata) {
+ return usersByDcId[dcUserMetadata.id] ||
+ (usersByDcId[dcUserMetadata.id] = addUser('dailycred', dcUserMetadata));
+ })
+ .redirectPath('/');
+
everyauth.azureacs
.identityProviderUrl('https://acssample1.accesscontrol.windows.net/v2/wsfederation/')
.entryPath('/auth/azureacs')
View
2 example/views/home.jade
@@ -177,5 +177,7 @@
- if (everyauth.mendeley)
h3 Mendeley User Data
p= JSON.stringify(everyauth.mendeley.user)
+ - if (everyauth['dailycred'])
+ p= JSON.stringify(everyauth.dailycred.user.email)
h3
a(href='/logout') Logout
View
61 lib/modules/dailycred.js
@@ -0,0 +1,61 @@
+var oauthModule = require('./oauth2')
+ , url = require('url');
+
+var dc = module.exports =
+oauthModule.submodule('dailycred')
+
+ .apiHost('https://auth.dailycred.com')
+ .oauthHost('https://auth.dailycred.com')
+
+ .authPath('https://auth.dailycred.com/oauth/authorize')
+ .accessTokenPath('/oauth/tokeninfo')
+ .entryPath('/auth/dailycred')
+ .callbackPath('/auth/dailycred/callback')
+
+ .authCallbackDidErr( function (req) {
+ var parsedUrl = url.parse(req.url, true);
+ return parsedUrl.query && !!parsedUrl.query.error;
+ })
+ .handleAuthCallbackError( function (req, res) {
+ var parsedUrl = url.parse(req.url, true)
+ , errorDesc = parsedUrl.query.error_description;
+ if (res.render) {
+ res.render(__dirname + '/../views/auth-fail.jade', {
+ errorDescription: errorDesc
+ });
+ } else {
+ // TODO Replace this with a nice fallback
+ throw new Error("You must configure handleAuthCallbackError if you are not using express");
+ }
+ })
+
+ .fetchOAuthUser( function (accessToken) {
+ var p = this.Promise();
+ this.oauth.get(this.apiHost() + '/oauth/me', accessToken, function (err, data) {
+ if (err) return p.fail(err);
+ var oauthUser = JSON.parse(data);
+ p.fulfill(oauthUser);
+ })
+ return p;
+ })
+ .moduleErrback( function (err, seqValues) {
+ if (err instanceof Error) {
+ var next = seqValues.next;
+ return next(err);
+ } else if (err.extra) {
+ var facebookResponse = err.extra.res
+ , serverResponse = seqValues.res;
+ serverResponse.writeHead(
+ facebookResponse.statusCode
+ , facebookResponse.headers);
+ serverResponse.end(err.extra.data);
+ } else if (err.statusCode) {
+ var serverResponse = seqValues.res;
+ serverResponse.writeHead(err.statusCode);
+ serverResponse.end(err.data);
+ } else {
+ console.error(err);
+ throw new Error('Unsupported error type');
+ }
+ });
+

0 comments on commit fafc486

Please sign in to comment.
Something went wrong with that request. Please try again.