Skip to content
This repository was archived by the owner on Dec 13, 2025. It is now read-only.

Commit 7c439ee

Browse files
committed
Initial Commit of v0.1.0
0 parents  commit 7c439ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+5568
-0
lines changed

.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.md
2+
.DS_Store
3+
.git*
4+
Makefile
5+
docs/
6+
examples/
7+
support/
8+
test/

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: "node_js"
2+
node_js:
3+
- 0.4
4+
- 0.6
5+
- 0.8

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(The MIT License)
2+
3+
Copyright (c) 2012 Ningsuhen Waikhom
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Passport-LinkedIn-Token
2+
3+
[Passport](http://passportjs.org/) strategy for authenticating with [LinkedIn](http://linkedin.com/) tokens
4+
using the OAuth 1.0a API.
5+
6+
This module lets you authenticate using LinkedIn in your Node.js applications.
7+
By plugging into Passport, LinkedIn authentication can be easily and
8+
unobtrusively integrated into any application or framework that supports
9+
[Connect](http://www.senchalabs.org/connect/)-style middleware, including
10+
[Express](http://expressjs.com/).
11+
12+
## Installation
13+
14+
$ npm install passport-linkedin-token
15+
16+
## Usage
17+
18+
#### Configure Strategy
19+
20+
The LinkedIn authentication strategy authenticates users using a LinkedIn account
21+
and OAuth tokens. The strategy requires a `verify` callback, which receives the
22+
access token and corresponding secret as arguments, as well as `profile` which
23+
contains the authenticated user's LinkedIn profile. The `verify` callback must
24+
call `done` providing a user to complete authentication.
25+
26+
In order to identify your application to LinkedIn, specify the consumer key,
27+
consumer secret, and callback URL within `options`. The consumer key and secret
28+
are obtained by [creating an application](https://dev.linkedin.com/apps) at
29+
LinkedIn's [developer](https://dev.linkedin.com/) site.
30+
31+
```javascript
32+
passport.use(new LinkedInTokenStrategy({
33+
consumerKey: LINKEDIN_CONSUMER_KEY,
34+
consumerSecret: LINKEDIN_CONSUMER_SECRET
35+
},
36+
function(token, tokenSecret, profile, done) {
37+
User.findOrCreate({ linkedinId: profile.id }, function (err, user) {
38+
return done(err, user);
39+
});
40+
}
41+
));
42+
```
43+
#### Authenticate Requests
44+
45+
Use `passport.authenticate()`, specifying the `'linkedin-token'` strategy, to
46+
authenticate requests.
47+
48+
For example, as route middleware in an [Express](http://expressjs.com/)
49+
application:
50+
51+
```javascript
52+
app.post('/auth/linkedin/token',
53+
passport.authenticate('linkedin-token'),
54+
function (req, res) {
55+
// do something with req.user
56+
res.send(req.user? 200 : 401);
57+
}
58+
);
59+
```
60+
61+
## Credits
62+
63+
- [Ningsuhen Waikhom](http://github.com/ningsuhen)
64+
- [Nicholas Penree](https://github.com/drudge/passport-twitter-token)
65+
- [Jared Hanson](http://github.com/jaredhanson)
66+
67+
## License
68+
69+
(The MIT License)
70+
71+
Copyright (c) 2012 Nicholas Penree
72+
73+
Permission is hereby granted, free of charge, to any person obtaining a copy of
74+
this software and associated documentation files (the "Software"), to deal in
75+
the Software without restriction, including without limitation the rights to
76+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
77+
the Software, and to permit persons to whom the Software is furnished to do so,
78+
subject to the following conditions:
79+
80+
The above copyright notice and this permission notice shall be included in all
81+
copies or substantial portions of the Software.
82+
83+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
84+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
85+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
86+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
87+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
88+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Module dependencies.
3+
*/
4+
var Strategy = require('./strategy');
5+
6+
7+
/**
8+
* Framework version.
9+
*/
10+
require('pkginfo')(module, 'version');
11+
12+
/**
13+
* Expose constructors.
14+
*/
15+
exports.Strategy = Strategy;
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/**
2+
* Module dependencies.
3+
*/
4+
var util = require('util')
5+
, OAuthStrategy = require('passport-oauth').OAuthStrategy
6+
, InternalOAuthError = require('passport-oauth').InternalOAuthError;
7+
8+
9+
/**
10+
* `LinkedInTokenStrategy` constructor.
11+
*
12+
* The LinkedIn authentication strategy authenticates requests by delegating to
13+
* LinkedIn using the OAuth protocol.
14+
*
15+
* Applications must supply a `verify` callback which accepts a `token`,
16+
* `tokenSecret` and service-specific `profile`, and then calls the `done`
17+
* callback supplying a `user`, which should be set to `false` if the
18+
* credentials are not valid. If an exception occured, `err` should be set.
19+
*
20+
* Options:
21+
* - `consumerKey` identifies client to LinkedIn
22+
* - `consumerSecret` secret used to establish ownership of the consumer key
23+
*
24+
* Examples:
25+
*
26+
* passport.use(new LinkedInTokenStrategy({
27+
* consumerKey: '123-456-789',
28+
* consumerSecret: 'shhh-its-a-secret'
29+
* },
30+
* function(token, tokenSecret, profile, done) {
31+
* User.findOrCreate(..., function (err, user) {
32+
* done(err, user);
33+
* });
34+
* }
35+
* ));
36+
*
37+
* @param {Object} options
38+
* @param {Function} verify
39+
* @api public
40+
*/
41+
function LinkedInTokenStrategy(options, verify) {
42+
options = options || {};
43+
options.requestTokenURL = options.requestTokenURL || 'https://api.linkedin.com/uas/oauth/requestToken';
44+
options.accessTokenURL = options.accessTokenURL || 'https://api.linkedin.com/uas/oauth/accessToken';
45+
options.userAuthorizationURL = options.userAuthorizationURL || 'https://www.linkedin.com/uas/oauth/authenticate';
46+
options.sessionKey = options.sessionKey || 'oauth:linkedin';
47+
48+
OAuthStrategy.call(this, options, verify);
49+
this.name = 'linkedin-token';
50+
51+
this._skipExtendedUserProfile = (options.skipExtendedUserProfile === undefined) ? false : options.skipExtendedUserProfile;
52+
}
53+
54+
/**
55+
* Inherit from `OAuthLinkedInTokenStrategy`.
56+
*/
57+
util.inherits(LinkedInTokenStrategy, OAuthStrategy);
58+
59+
60+
/**
61+
* Authenticate request by delegating to LinkedIn using OAuth.
62+
*
63+
* @param {Object} req
64+
* @api protected
65+
*/
66+
LinkedInTokenStrategy.prototype.authenticate = function(req, options) {
67+
// When a user denies authorization on LinkedIn, they are presented with a link
68+
// to return to the application in the following format (where xxx is the
69+
// value of the request token):
70+
//
71+
// http://www.example.com/auth/linkedin/callback?denied=xxx
72+
//
73+
// Following the link back to the application is interpreted as an
74+
// authentication failure.
75+
if (req.query && req.query.denied) {
76+
return this.fail();
77+
}
78+
79+
var self = this;
80+
var token = req.body.oauth_token || req.query.oauth_token;
81+
var tokenSecret = req.body.oauth_token_secret || req.query.oauth_token_secret;
82+
83+
var params = { };
84+
85+
self._loadUserProfile(token, tokenSecret, params, function(err, profile) {
86+
if (err) { return self.error(err); };
87+
88+
function verified(err, user, info) {
89+
if (err) { return self.error(err); }
90+
if (!user) { return self.fail(info); }
91+
self.success(user, info);
92+
}
93+
94+
if (self._passReqToCallback) {
95+
var arity = self._verify.length;
96+
if (arity == 6) {
97+
self._verify(req, token, tokenSecret, params, profile, verified);
98+
} else { // arity == 5
99+
self._verify(req, token, tokenSecret, profile, verified);
100+
}
101+
} else {
102+
var arity = self._verify.length;
103+
if (arity == 5) {
104+
self._verify(token, tokenSecret, params, profile, verified);
105+
} else { // arity == 4
106+
self._verify(token, tokenSecret, profile, verified);
107+
}
108+
}
109+
});
110+
}
111+
112+
/**
113+
* Retrieve user profile from LinkedIn.
114+
*
115+
* This function constructs a normalized profile, with the following properties:
116+
*
117+
* - `id` (equivalent to `user_id`)
118+
* - `username` (equivalent to `screen_name`)
119+
*
120+
* Note that because LinkedIn supplies basic profile information in query
121+
* parameters when redirecting back to the application, loading of LinkedIn
122+
* profiles *does not* result in an additional HTTP request, when the
123+
* `skipExtendedUserProfile` is enabled.
124+
*
125+
* @param {String} token
126+
* @param {String} tokenSecret
127+
* @param {Object} params
128+
* @param {Function} done
129+
* @api protected
130+
*/
131+
LinkedInTokenStrategy.prototype.userProfile = function(token, tokenSecret, params, done) {
132+
var url = 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name,public-profile-url)?format=json';
133+
if (this._profileFields) {
134+
var fields = this._convertProfileFields(this._profileFields);
135+
url = 'https://api.linkedin.com/v1/people/~:(' + fields + ')?format=json';
136+
}
137+
138+
this._oauth.get(url, token, tokenSecret, function (err, body, res) {
139+
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }
140+
141+
try {
142+
var json = JSON.parse(body);
143+
144+
var profile = { provider: 'linkedin' };
145+
profile.id = json.id;
146+
profile.displayName = json.firstName + ' ' + json.lastName;
147+
profile.name = { familyName: json.lastName,
148+
givenName: json.firstName };
149+
if (json.emailAddress) { profile.emails = [{ value: json.emailAddress }]; }
150+
151+
profile._raw = body;
152+
profile._json = json;
153+
154+
done(null, profile);
155+
} catch(e) {
156+
done(e);
157+
}
158+
});
159+
}
160+
161+
/**
162+
* Return extra LinkedIn-specific parameters to be included in the user
163+
* authorization request.
164+
*
165+
* @param {Object} options
166+
* @return {Object}
167+
* @api protected
168+
*/
169+
LinkedInTokenStrategy.prototype.userAuthorizationParams = function(options) {
170+
var params = {};
171+
if (options.forceLogin) {
172+
params['force_login'] = options.forceLogin;
173+
}
174+
if (options.screenName) {
175+
params['screen_name'] = options.screenName;
176+
}
177+
return params;
178+
}
179+
180+
181+
/**
182+
* Expose `LinkedInTokenStrategy`.
183+
*/
184+
module.exports = LinkedInTokenStrategy;

node_modules/passport-oauth/.travis.yml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/passport-oauth/LICENSE

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)