Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adapt to Xing API

See https://dev.xing.com/ for more details about the API
  • Loading branch information...
commit b1fdeecea268f80aadbfe97b7b3c053239b2ecbb 1 parent 1c68338
@bachp authored
View
8 Makefile
@@ -7,11 +7,11 @@ test:
docs: docs/api.html
-docs/api.html: lib/passport-linkedin/*.js
+docs/api.html: lib/passport-xing/*.js
dox \
- --title Passport-LinkedIn \
- --desc "LinkedIn authentication strategy for Passport" \
- $(shell find lib/passport-linkedin/* -type f) > $@
+ --title Passport-Xing \
+ --desc "Xing authentication strategy for Passport" \
+ $(shell find lib/passport-xing/* -type f) > $@
docclean:
rm -f docs/*.{1,html}
View
40 README.md
@@ -1,34 +1,34 @@
-# Passport-LinkedIn
+# Passport-Xing
-[Passport](http://passportjs.org/) strategy for authenticating with [LinkedIn](http://www.linkedin.com/)
+[Passport](http://passportjs.org/) strategy for authenticating with [Xing](http://www.xing.com/)
using the OAuth 1.0a API.
-This module lets you authenticate using LinkedIn in your Node.js applications.
-By plugging into Passport, LinkedIn authentication can be easily and
+This module lets you authenticate using Xing in your Node.js applications.
+By plugging into Passport, Xing authentication can be easily and
unobtrusively integrated into any application or framework that supports
[Connect](http://www.senchalabs.org/connect/)-style middleware, including
[Express](http://expressjs.com/).
## Installation
- $ npm install passport-linkedin
+ $ npm install passport-xing
## Usage
#### Configure Strategy
-The LinkedIn authentication strategy authenticates users using a LinkedIn
+The Xing authentication strategy authenticates users using a Xing
account and OAuth tokens. The strategy requires a `verify` callback, which
accepts these credentials and calls `done` providing a user, as well as
`options` specifying a consumer key, consumer secret, and callback URL.
- passport.use(new LinkedInStrategy({
- consumerKey: LINKEDIN_API_KEY,
- consumerSecret: LINKEDIN_SECRET_KEY,
- callbackURL: "http://127.0.0.1:3000/auth/linkedin/callback"
+ passport.use(new XingStrategy({
+ consumerKey: XING_API_KEY,
+ consumerSecret: XING_SECRET_KEY,
+ callbackURL: "http://127.0.0.1:3000/auth/xing/callback"
},
function(token, tokenSecret, profile, done) {
- User.findOrCreate({ linkedinId: profile.id }, function (err, user) {
+ User.findOrCreate({ xingId: profile.id }, function (err, user) {
return done(err, user);
});
}
@@ -36,21 +36,21 @@ accepts these credentials and calls `done` providing a user, as well as
#### Authenticate Requests
-Use `passport.authenticate()`, specifying the `'linkedin'` strategy, to
+Use `passport.authenticate()`, specifying the `'xing'` strategy, to
authenticate requests.
For example, as route middleware in an [Express](http://expressjs.com/)
application:
- app.get('/auth/linkedin',
- passport.authenticate('linkedin'),
+ app.get('/auth/xing',
+ passport.authenticate('xing'),
function(req, res){
- // The request will be redirected to LinkedIn for authentication, so
+ // The request will be redirected to Xing for authentication, so
// this function will not be called.
});
- app.get('/auth/linkedin/callback',
- passport.authenticate('linkedin', { failureRedirect: '/login' }),
+ app.get('/auth/xing/callback',
+ passport.authenticate('xing', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
@@ -58,24 +58,26 @@ application:
## Examples
-For a complete, working example, refer to the [login example](https://github.com/jaredhanson/passport-linkedin/tree/master/examples/login).
+For a complete, working example, refer to the [login example](https://github.com/pascal-bach/passport-xing/tree/master/examples/login).
## Tests
$ npm install --dev
$ make test
-[![Build Status](https://secure.travis-ci.org/jaredhanson/passport-linkedin.png)](http://travis-ci.org/jaredhanson/passport-linkedin)
+[![Build Status](https://secure.travis-ci.org/pascal-bach/passport-xing.png)](http://travis-ci.org/pascal-bach/passport-xing)
## Credits
- [Jared Hanson](http://github.com/jaredhanson)
+ - [Pascal Bach](http://github.com/pascal-bach)
## License
(The MIT License)
Copyright (c) 2011 Jared Hanson
+Copyright (c) 2013 Pascal Bach
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
View
44 examples/login/app.js
@@ -1,10 +1,10 @@
var express = require('express')
, passport = require('passport')
, util = require('util')
- , LinkedInStrategy = require('passport-linkedin').Strategy;
+ , XingStrategy = require('passport-xing').Strategy;
-var LINKEDIN_API_KEY = "--insert-linkedin-api-key-here--"
-var LINKEDIN_SECRET_KEY = "--insert-linkedin-secret-key-here--";
+var XING_API_KEY = "--insert-xing-api-key-here--"
+var XING_SECRET_KEY = "--insert-xing-secret-key-here--";
// Passport session setup.
@@ -12,7 +12,7 @@ var LINKEDIN_SECRET_KEY = "--insert-linkedin-secret-key-here--";
// serialize users into and deserialize users out of the session. Typically,
// this will be as simple as storing the user ID when serializing, and finding
// the user by ID when deserializing. However, since this example does not
-// have a database of user records, the complete LinkedIn profile is
+// have a database of user records, the complete Linked profile is
// serialized and deserialized.
passport.serializeUser(function(user, done) {
done(null, user);
@@ -23,22 +23,22 @@ passport.deserializeUser(function(obj, done) {
});
-// Use the LinkedInStrategy within Passport.
+// Use the XingStrategy within Passport.
// Strategies in passport require a `verify` function, which accept
-// credentials (in this case, a token, tokenSecret, and LinkedIn profile), and
+// credentials (in this case, a token, tokenSecret, and Xing profile), and
// invoke a callback with a user object.
-passport.use(new LinkedInStrategy({
- consumerKey: LINKEDIN_API_KEY,
- consumerSecret: LINKEDIN_SECRET_KEY,
- callbackURL: "http://127.0.0.1:3000/auth/linkedin/callback"
+passport.use(new XingStrategy({
+ consumerKey: XING_API_KEY,
+ consumerSecret: XING_SECRET_KEY,
+ callbackURL: "http://127.0.0.1:3000/auth/xing/callback"
},
function(token, tokenSecret, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
- // To keep the example simple, the user's LinkedIn profile is returned to
+ // To keep the example simple, the user's Xing profile is returned to
// represent the logged-in user. In a typical application, you would want
- // to associate the LinkedIn account with a user record in your database,
+ // to associate the Xing account with a user record in your database,
// and return that user instead.
return done(null, profile);
});
@@ -80,25 +80,25 @@ app.get('/login', function(req, res){
res.render('login', { user: req.user });
});
-// GET /auth/linkedin
+// GET /auth/xing
// Use passport.authenticate() as route middleware to authenticate the
-// request. The first step in LinkedIn authentication will involve
-// redirecting the user to linkedin.com. After authorization, LinkedIn will
-// redirect the user back to this application at /auth/linkedin/callback
-app.get('/auth/linkedin',
- passport.authenticate('linkedin'),
+// request. The first step in Xing authentication will involve
+// redirecting the user to xing.com. After authorization, Xing will
+// redirect the user back to this application at /auth/xing/callback
+app.get('/auth/xing',
+ passport.authenticate('xing'),
function(req, res){
- // The request will be redirected to LinkedIn for authentication, so this
+ // The request will be redirected to Xing for authentication, so this
// function will not be called.
});
-// GET /auth/linkedin/callback
+// GET /auth/xing/callback
// Use passport.authenticate() as route middleware to authenticate the
// request. If authentication fails, the user will be redirected back to the
// login page. Otherwise, the primary route function function will be called,
// which, in this example, will redirect the user to the home page.
-app.get('/auth/linkedin/callback',
- passport.authenticate('linkedin', { failureRedirect: '/login' }),
+app.get('/auth/xing/callback',
+ passport.authenticate('xing', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
});
View
4 examples/login/package.json
@@ -1,10 +1,10 @@
{
- "name": "passport-linkedin-examples-login",
+ "name": "passport-xing-examples-login",
"version": "0.0.0",
"dependencies": {
"express": ">= 0.0.0",
"ejs": ">= 0.0.0",
"passport": ">= 0.0.0",
- "passport-linkedin": ">= 0.0.0"
+ "passport-xing": ">= 0.0.0"
}
}
View
2  examples/login/views/layout.ejs
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <title>Passport-LinkedIn Example</title>
+ <title>Passport-Xing Example</title>
</head>
<body>
<% if (!user) { %>
View
2  examples/login/views/login.ejs
@@ -1 +1 @@
-<a href="/auth/linkedin">Login with LinkedIn</a>
+<a href="/auth/xing">Login with Xing</a>
View
0  lib/passport-linkedin/index.js → lib/passport-xing/index.js
File renamed without changes
View
45 lib/passport-linkedin/strategy.js → lib/passport-xing/strategy.js
@@ -9,8 +9,8 @@ var util = require('util')
/**
* `Strategy` constructor.
*
- * The LinkedIn authentication strategy authenticates requests by delegating to
- * LinkedIn using the OAuth protocol.
+ * The Xing authentication strategy authenticates requests by delegating to
+ * Xing using the OAuth protocol.
*
* Applications must supply a `verify` callback which accepts a `token`,
* `tokenSecret` and service-specific `profile`, and then calls the `done`
@@ -18,16 +18,16 @@ var util = require('util')
* credentials are not valid. If an exception occured, `err` should be set.
*
* Options:
- * - `consumerKey` identifies client to LinkedIn
+ * - `consumerKey` identifies client to Xing
* - `consumerSecret` secret used to establish ownership of the consumer key
- * - `callbackURL` URL to which LinkedIn will redirect the user after obtaining authorization
+ * - `callbackURL` URL to which Xing will redirect the user after obtaining authorization
*
* Examples:
*
- * passport.use(new LinkedInStrategy({
+ * passport.use(new XingStrategy({
* consumerKey: '123-456-789',
* consumerSecret: 'shhh-its-a-secret'
- * callbackURL: 'https://www.example.net/auth/linkedin/callback'
+ * callbackURL: 'https://www.example.net/auth/xing/callback'
* },
* function(token, tokenSecret, profile, done) {
* User.findOrCreate(..., function (err, user) {
@@ -42,13 +42,13 @@ var util = require('util')
*/
function Strategy(options, verify) {
options = options || {};
- options.requestTokenURL = options.requestTokenURL || 'https://api.linkedin.com/uas/oauth/requestToken';
- options.accessTokenURL = options.accessTokenURL || 'https://api.linkedin.com/uas/oauth/accessToken';
- options.userAuthorizationURL = options.userAuthorizationURL || 'https://www.linkedin.com/uas/oauth/authenticate';
- options.sessionKey = options.sessionKey || 'oauth:linkedin';
+ options.requestTokenURL = options.requestTokenURL || 'https://api.xing.com/v1/request_token';
+ options.accessTokenURL = options.accessTokenURL || 'https://api.xing.com/v1/access_token';
+ options.userAuthorizationURL = options.userAuthorizationURL || 'https://api.xing.com/v1/authorize';
+ options.sessionKey = options.sessionKey || 'oauth:xing';
OAuthStrategy.call(this, options, verify);
- this.name = 'linkedin';
+ this.name = 'xing';
}
/**
@@ -57,16 +57,16 @@ function Strategy(options, verify) {
util.inherits(Strategy, OAuthStrategy);
/**
- * Authenticate request by delegating to LinkedIn using OAuth.
+ * Authenticate request by delegating to Xing using OAuth.
*
* @param {Object} req
* @api protected
*/
Strategy.prototype.authenticate = function(req) {
- // When a user denies authorization on LinkedIn, they are presented with a
+ // When a user denies authorization on Xing, they are presented with a
// link to return to the application in the following format:
//
- // http://www.example.com/auth/linkedin/callback?oauth_problem=user_refused
+ // http://www.example.com/auth/xing/callback?oauth_problem=user_refused
//
// Following the link back to the application is interpreted as an
// authentication failure.
@@ -79,7 +79,7 @@ Strategy.prototype.authenticate = function(req) {
}
/**
- * Retrieve user profile from LinkedIn.
+ * Retrieve user profile from Xing.
*
* This function constructs a normalized profile, with the following properties:
*
@@ -95,17 +95,18 @@ Strategy.prototype.authenticate = function(req) {
* @api protected
*/
Strategy.prototype.userProfile = function(token, tokenSecret, params, done) {
- this._oauth.get('https://api.linkedin.com/v1/people/~:(id,first-name,last-name)?format=json', token, tokenSecret, function (err, body, res) {
+ this._oauth.get('https://api.xing.com/v1/users/me?fields=id,display_name,first_name,last_name', token, tokenSecret, function (err, body, res) {
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }
try {
var json = JSON.parse(body);
-
- var profile = { provider: 'linkedin' };
- profile.id = json.id;
- profile.displayName = json.firstName + ' ' + json.lastName;
- profile.name = { familyName: json.lastName,
- givenName: json.firstName };
+ var profile = { provider: 'xing' };
+ // Xing returns an array of user, currently only the first is used
+ var user = json.users[0];
+ profile.id = user.id;
+ profile.displayName = user.display_name;
+ profile.name = { familyName: user.last_name,
+ givenName: user.first_name };
profile._raw = body;
profile._json = json;
View
15 package.json
@@ -1,16 +1,17 @@
{
- "name": "passport-linkedin",
+ "name": "passport-xing",
"version": "0.1.2",
- "description": "LinkedIn authentication strategy for Passport.",
- "author": { "name": "Jared Hanson", "email": "jaredhanson@gmail.com", "url": "http://www.jaredhanson.net/" },
+ "description": "Xing authentication strategy for Passport.",
+ "author": { "name": "Pascal Bach", "email": "pascal.bach@nextrem.ch", "url": "http://pascal.nextrem.ch/" },
+ "contributors": [ { "name": "Jared Hanson", "email": "jaredhanson@gmail.com", "url": "http://www.jaredhanson.net/" } ],
"repository": {
"type": "git",
- "url": "git://github.com/jaredhanson/passport-linkedin.git"
+ "url": "git://github.com/pascal-bach/passport-xing.git"
},
"bugs": {
- "url": "http://github.com/jaredhanson/passport-linkedin/issues"
+ "url": "http://github.com/pascal-bach/passport-xing/issues"
},
- "main": "./lib/passport-linkedin",
+ "main": "./lib/passport-xing",
"dependencies": {
"pkginfo": "0.2.x",
"passport-oauth": "0.1.x"
@@ -26,5 +27,5 @@
"type": "MIT",
"url": "http://www.opensource.org/licenses/MIT"
} ],
- "keywords": ["passport", "linkedin", "auth", "authn", "authentication", "identity"]
+ "keywords": ["passport", "xing", "auth", "authn", "authentication", "identity"]
}
View
6 test/index-test.js
@@ -1,14 +1,14 @@
var vows = require('vows');
var assert = require('assert');
var util = require('util');
-var linkedin = require('passport-linkedin');
+var xing = require('passport-xing');
-vows.describe('passport-linkedin').addBatch({
+vows.describe('passport-xing').addBatch({
'module': {
'should report a version': function (x) {
- assert.isString(linkedin.version);
+ assert.isString(xing.version);
},
},
View
18 test/strategy-test.js
@@ -1,28 +1,28 @@
var vows = require('vows');
var assert = require('assert');
var util = require('util');
-var LinkedInStrategy = require('passport-linkedin/strategy');
+var XingStrategy = require('passport-xing/strategy');
-vows.describe('LinkedInStrategy').addBatch({
+vows.describe('XingStrategy').addBatch({
'strategy': {
topic: function() {
- return new LinkedInStrategy({
+ return new XingStrategy({
consumerKey: 'ABC123',
consumerSecret: 'secret'
},
function() {});
},
- 'should be named linkedin': function (strategy) {
- assert.equal(strategy.name, 'linkedin');
+ 'should be named xing': function (strategy) {
+ assert.equal(strategy.name, 'xing');
},
},
'strategy when loading user profile': {
topic: function() {
- var strategy = new LinkedInStrategy({
+ var strategy = new XingStrategy({
consumerKey: 'ABC123',
consumerSecret: 'secret'
},
@@ -54,7 +54,7 @@ vows.describe('LinkedInStrategy').addBatch({
assert.isNull(err);
},
'should load profile' : function(err, profile) {
- assert.equal(profile.provider, 'linkedin');
+ assert.equal(profile.provider, 'xing');
assert.equal(profile.id, '_XX0XXX00X');
assert.equal(profile.displayName, 'Jared Hanson');
assert.equal(profile.name.familyName, 'Hanson');
@@ -71,7 +71,7 @@ vows.describe('LinkedInStrategy').addBatch({
'strategy when loading user profile and encountering an error': {
topic: function() {
- var strategy = new LinkedInStrategy({
+ var strategy = new XingStrategy({
consumerKey: 'ABC123',
consumerSecret: 'secret'
},
@@ -111,7 +111,7 @@ vows.describe('LinkedInStrategy').addBatch({
'strategy handling a request that has been denied': {
topic: function() {
- var strategy = new LinkedInStrategy({
+ var strategy = new XingStrategy({
consumerKey: 'ABC123',
consumerSecret: 'secret'
},
Please sign in to comment.
Something went wrong with that request. Please try again.