Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #302 from hstove/master

added provider for dailycred.com
  • Loading branch information...
commit dee15f4b21f208265f6d5cdb9d01114277983114 2 parents 9f2c438 + 7ce6393
@bnoguchi authored
View
13 README.md
@@ -60,6 +60,7 @@ So far, `everyauth` enables you to login via:
<tr> <td> <img src="https://github.com/bnoguchi/everyauth/raw/master/media/openid.ico" style="vertical-align:middle" width="16px" height="16px"> OpenId <td> <a href="https://github.com/rocketlabsdev">RocketLabs Development</a>, <a href="https://github.com/starfishmod">Andrew Mee, <a href="https://github.com/bnoguchi">Brian Noguchi</a>
<tr> <td> LDAP (experimental; not production-tested) <td>
<tr> <td> Windows Azure Access Control Service (ACS)<td> <a href="https://github.com/darrenzully">Dario Renzulli</a>, <a href="https://github.com/jpgarcia">Juan Pablo Garcia</a>, <a href="https://github.com/woloski">Matias Woloski</a> from <a href="http://blogs.southworks.net/">Southworks</a>
+ <tr><td><img src='https://www.dailycred.com/public/img/favicon.ico' style="vertical-align:middle">Dailycred <td> <a href='https://github.com/hstove'>Hank Stoever</a> at <a href='https://dailycred.com'>Dailycred.com</a>
</tbody>
</table>
@@ -2377,6 +2378,18 @@ object whose parameter name keys map to description values:
everyauth.box.configurable();
```
+### Dailycred OAuth
+
+```javascript
+everyauth.dailycred
+ .appId(conf.dc.appId)
+ .findOrCreateUser( function (session, accessToken, accessTokenExtra, dcUserMetadata) {
+ return usersByDcId[dcUserMetadata.id] ||
+ (usersByDcId[dcUserMetadata.id] = addUser('dailycred', dcUserMetadata));
+ })
+ .redirectPath('/');
+```
+
## Configuring a Module
everyauth was built with powerful configuration needs in mind.
View
6 example/conf.js
@@ -1,5 +1,9 @@
module.exports = {
- fb: {
+ dc: {
+ appId: '7ab1a53d-9d0e-4eeb-af62-76a5e1a83af9',
+ appSecret: '88bee747-c1ef-4851-be60-84d53dd474ad-88495db2-5db0-47c8-ad77-9e92db7e308c',
+ }
+ , fb: {
appId: '111565172259433'
, appSecret: '85f7e0a0cc804886180b887c1f04a3c1'
}
View
3,091 example/npm-debug.log
3,091 additions, 0 deletions not shown
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
4 example/views/home.jade
@@ -91,6 +91,8 @@
label(for='openid_identifier') OpenID Identifier: &nbsp;
input(type='text', name='openid_identifier')
input(type='submit') Login
+ #dailycred-login
+ a(href='/auth/dailycred') Login with Dailycred
- else
h2 Authenticated
- if (everyauth.facebook)
@@ -177,5 +179,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://www.dailycred.com')
+ .oauthHost('https://www.dailycred.com')
+
+ .authPath('https://www.dailycred.com/oauth/authorize')
+ .accessTokenPath('/oauth/api/token.json')
+ .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/api/me.json', 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');
+ }
+ });
+
Please sign in to comment.
Something went wrong with that request. Please try again.