Skip to content

Commit

Permalink
Merge branch 'rest-api'
Browse files Browse the repository at this point in the history
# Conflicts:
#	examples/login/app.js
  • Loading branch information
ludoo0d0a committed Jul 9, 2019
2 parents fe463b2 + d7f415b commit e8b3b0f
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 81 deletions.
24 changes: 0 additions & 24 deletions Makefile

This file was deleted.

27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Geocaching authentication strategy for Passport and Node.js.

[Passport](http://passportjs.org/) strategy for authenticating with [Geocaching](http://www.geocaching.com/)
using the OAuth 1.0a API.
using the OAuth 2 API.

This module lets you authenticate using Tumblr in your Node.js applications.
By plugging into Passport, Tumblr authentication can be easily and
This module lets you authenticate using Geocaching in your Node.js applications.
By plugging into Passport, Geocaching 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/).
Expand All @@ -24,9 +24,9 @@ these credentials and calls `done` providing a user, as well as `options`
specifying a consumer key, consumer secret, and callback URL.

passport.use(new GeocachingStrategy({
consumerKey: GEOCACHING_CONSUMER_KEY,
consumerSecret: GEOCACHING_SECRET_KEY,
callbackURL: "http://127.0.0.1:3000/auth/geocaching/callback"
clientID: GEOCACHING_CONSUMER_KEY,
clientSecret: GEOCACHING_SECRET_KEY,
callbackURL: "http://127.0.0.1:3000/auth/callback"
},
function(token, tokenSecret, profile, done) {
User.findOrCreate({ geocachingId: profile.id, geocachingUsername: profile.username }, function (err, user) {
Expand All @@ -35,6 +35,12 @@ specifying a consumer key, consumer secret, and callback URL.
}
));

#### Groundspeak registration

You need API key to access [geocaching API](https://apidevelopers.geocaching.com/).
And you need to register the callback urls, including in local mode with localhost. Please contact support to add them.


#### Authenticate Requests

Use `passport.authenticate()`, specifying the `'geocaching'` strategy, to
Expand All @@ -46,7 +52,7 @@ application:
app.get('/auth/geocaching',
passport.authenticate('geocaching'));

app.get('/auth/geocaching/callback',
app.get('/auth/callback',
passport.authenticate('geocaching', { failureRedirect: '/login' }),
function(req, res) {
// Successful authentication, redirect home.
Expand All @@ -61,8 +67,9 @@ For a complete integration of this stratgy, look at [geocaching-api](https://git

## Tests

$ npm install --dev
$ make test
$ cd examples/login
$ npm install
$ npm start


## Credits
Expand All @@ -73,4 +80,4 @@ For a complete integration of this stratgy, look at [geocaching-api](https://git

[The ISC License](http://opensource.org/licenses/ISC)

Copyright (c) 2015 Ludovic Valente <[http://www.pitaso.com/](http://www.pitaso.com)>
Copyright (c) 2019 Ludovic Valente <[http://www.geoking.fr/](http://www.geoking.fr)>
10 changes: 6 additions & 4 deletions default-config-api.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module.exports = {
consumerKey: '123456789-ABCD-123456789-ABCD',
consumerSecret: '123456789-ABCD-123456789-ABCD',
callbackURL: 'https://localhost:3000/auth/geocaching/callback',
clientID: '123456789-ABCD-123456789-ABCD',
clientSecret: '123456789-ABCD-123456789-ABCD',
// consumerKey: '123456789-ABCD-123456789-ABCD',
// consumerSecret: '123456789-ABCD-123456789-ABCD',
callbackURL: 'https://localhost:3000/auth/callback',

env: 'staging'
//env: 'live'
//env: 'prod'
};
25 changes: 15 additions & 10 deletions examples/login/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ var port = process.env.PORT || 3000;
var GEOCACHING_APP_ID = "--insert-geocaching-app-id-here--"
var GEOCACHING_APP_SECRET = "--insert-geocaching-app-secret-here--";

var callbackURL = 'http://localhost:'+port+'/auth/geocaching/callback';
var callbackURL = 'http://localhost:'+port+'/auth/callback';

if (config){
GEOCACHING_APP_ID = config.consumerKey;
GEOCACHING_APP_SECRET = config.consumerSecret ;
GEOCACHING_APP_ID = config.clientID;
GEOCACHING_APP_SECRET = config.clientSecret ;
callbackURL = config.callbackURL;
}
// Passport session setup.
Expand All @@ -43,9 +43,10 @@ passport.deserializeUser(function(obj, done) {
// credentials (in this case, an accessToken, refreshToken, and Facebook
// profile), and invoke a callback with a user object.
passport.use(new GeocachingStrategy({
consumerKey: GEOCACHING_APP_ID,
consumerSecret: GEOCACHING_APP_SECRET,
env: config && config.env,
clientID: GEOCACHING_APP_ID,
clientSecret: GEOCACHING_APP_SECRET,
// clientID: GEOCACHING_APP_ID,
// consumerSecret: GEOCACHING_APP_SECRET,

//You can skip profile request access
//skipUserProfile: true,
Expand Down Expand Up @@ -108,20 +109,24 @@ app.get('/login', function(req, res){
// Use passport.authenticate() as route middleware to authenticate the
// request. The first step in Facebook authentication will involve
// redirecting the user to geocaching.com. After authorization, Facebook will
// redirect the user back to this application at /auth/geocaching/callback
// redirect the user back to this application at /auth/callback
app.get('/auth/geocaching',
passport.authenticate('geocaching'),
function(req, res){
// The request will be redirected to Facebook for authentication, so this
// function will not be called.
});

// GET /auth/geocaching/callback
// GET /auth/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/geocaching/callback',
//
// Be ware tht this url should now be prooperl registered by Groundspeak. Please contact support to add this url.
// A error message will occured if not properly set : The partner application did not give a secure redirect_uri. Please verify with the application the redirect uri is set up correctly and securely.
//
app.get('/auth/callback',
passport.authenticate('geocaching', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
Expand All @@ -133,7 +138,7 @@ app.get('/logout', function(req, res){
});

app.listen(port, function () {
console.log('Example app for passport-geocaching is listening');
console.log('Example app for passport-geocaching is listening on http://localhost:%d', port);
});


Expand Down
25 changes: 14 additions & 11 deletions examples/login/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"name": "passport-geocaching-examples-login",
"version": "0.0.0",
"version": "0.0.2",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"body-parser": ">= 1.4.3",
"cookie-parser": ">= 1.3.2",
"ejs": ">= 0.0.0",
"express": ">= 4.4.5",
"express-ejs-layouts": "^1.1.0",
"express-session": ">= 1.6.1",
"method-override": ">= 2.0.2",
"morgan": ">= 1.1.1",
"passport": ">= 0.0.0",
"passport-geocaching": ">= 0.0.0"
"body-parser": "1.19.0",
"cookie-parser": "1.4.4",
"ejs": "2.6.2",
"express": "4.17.1",
"express-ejs-layouts": "^2.5.0",
"express-session": "1.16.2",
"method-override": "3.0.0",
"morgan": "1.9.1",
"passport": "0.4.0",
"passport-geocaching": "0.1.7"
}
}
6 changes: 5 additions & 1 deletion examples/login/views/index.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<% if (!user) { %>
<h2>Welcome! Please <a href="login">log in</a>.</h2>
<% } else { %>
<h2>Hello, <%= user.username %>.</h2>
<h2>Hello, <%= user.username %> (<%= user.id %>) !!</h2>
<p><img src="<%= user.avatarUrl %>"></img></p>
<p>You found <%= user.findCount %> caches and hide <%= user.hideCount %>.</p>
<p>Favorite points : <%= user.favoritePoints %></p>
<%- user.profileText %>
<% } %>
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Module dependencies.
*/
var Strategy = require('./strategy');

//var Strategy = require('./strategy-oauth');
var Strategy = require('./strategy-oauth2');

/**
* Expose `Strategy` directly from package.
Expand Down
17 changes: 9 additions & 8 deletions lib/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ exports.parse = function(json) {
}

var profile = { };
if (json.Profile && json.Profile.User){
profile.id = json.Profile.User.Id;
profile.username = json.Profile.User.UserName;
profile.MemberType = json.Profile.User.MemberType.MemberTypeName;
profile.AvatarUrl = json.Profile.User.AvatarUrl;
profile.FindCount = json.Profile.User.FindCount;
profile.HideCount = json.Profile.User.HideCount;
profile.PublicGuid = json.Profile.User.PublicGuid;
if (json){
profile.id = json.referenceCode;
profile.username = json.username;
profile.membershipLevelId = json.membershipLevelId;
profile.avatarUrl = json.avatarUrl;
profile.findCount = json.findCount;
profile.hideCount = json.hideCount;
profile.favoritePoints = json.favoritePoints;
profile.profileText = json.profileText;
}

return profile;
Expand Down
2 changes: 1 addition & 1 deletion lib/strategy.js → lib/strategy-oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var urls = {
* passport.use(new geocachingStrategy({
* consumerKey: '123-456-789',
* consumerSecret: 'shhh-its-a-secret'
* callbackURL: 'https://www.example.net/auth/geocaching/callback'
* callbackURL: 'https://www.example.net/auth/callback'
* },
* function(token, tokenSecret, profile, done) {
* User.findOrCreate(..., function (err, user) {
Expand Down
Loading

0 comments on commit e8b3b0f

Please sign in to comment.