patternjavascriptMinor
node.js Passport Wrapper 2
Viewed 0 times
nodewrapperpassport
Problem
First attempt was done here:
My second attempt (now using jslint to make sure the spacing is correct and have incorporate the majority of the feedback from previous attempt).
```
/*
* Export single function that creates the passportControl object
* The function has two parameters:
* app: The nodejs/express service object.
* This is used to register the end points
* this authentication object listens too.
* register: See https://codereview.stackexchange.com/questions/36940/local-user-registration
* For an example implementation. This is still being worked on.
*
* It also uses an external module for configuration (ie holding all the secrets)
* This file is not in source control (but in a key repository nice and safe).
* config: Expected fields:
* config.app The URL of the site.
* config.passport An object containing the secrets for each service
* The values will depend on the service and the
* implementation of passport- module
* See the passport code for more detail
* Example:
* passport: {
* facebook: {
* clientID: 'FACEBOOK_CLIENT_ID',
* clientSecret: 'FACEBOOK_CLIENT_SECRET',
* },
* twitter: {
* consumerKey: 'TWITTER_CONSUMER_KEY',
* consumerSecret: 'TWITTER_CONSUMER_SECRET',
* }
* }
*
* The passport control object is supposed to be a wrapper for
* nodejs/express/passport authentication.
*
* When the object is created it adds three end points to the server
My second attempt (now using jslint to make sure the spacing is correct and have incorporate the majority of the feedback from previous attempt).
```
/*
* Export single function that creates the passportControl object
* The function has two parameters:
* app: The nodejs/express service object.
* This is used to register the end points
* this authentication object listens too.
* register: See https://codereview.stackexchange.com/questions/36940/local-user-registration
* For an example implementation. This is still being worked on.
*
* It also uses an external module for configuration (ie holding all the secrets)
* This file is not in source control (but in a key repository nice and safe).
* config: Expected fields:
* config.app The URL of the site.
* config.passport An object containing the secrets for each service
* The values will depend on the service and the
* implementation of passport- module
* See the passport code for more detail
* Example:
* passport: {
* facebook: {
* clientID: 'FACEBOOK_CLIENT_ID',
* clientSecret: 'FACEBOOK_CLIENT_SECRET',
* },
* twitter: {
* consumerKey: 'TWITTER_CONSUMER_KEY',
* consumerSecret: 'TWITTER_CONSUMER_SECRET',
* }
* }
*
* The passport control object is supposed to be a wrapper for
* nodejs/express/passport authentication.
*
* When the object is created it adds three end points to the server
Solution
I really like this code, I only have a few minor observations:
Other than that, very cool, something I would consider using for my own Node projects.
'http://'
(request.status === 200)
- The fact that
result.auth.defaultandresult.auth.callbackare so similar bugs me (DRY), but I could not find a neater way to do it
- Spelling:
logedin->loggedIn
Other than that, very cool, something I would consider using for my own Node projects.
Context
StackExchange Code Review Q#40159, answer score: 4
Revisions (0)
No revisions yet.