Code Monkey home page Code Monkey logo

Comments (8)

sahat avatar sahat commented on May 10, 2024

I just tried creating a new Tumblr application and generate new consumer key and consumer secret. Works fine here.

Also, note that I am not using Tumblr strategy for authentication. The whole reason behind:

passport.use('tumblr', new OAuthStrategy({
    requestTokenURL: 'http://www.tumblr.com/oauth/request_token',
    accessTokenURL: 'http://www.tumblr.com/oauth/access_token',
    userAuthorizationURL: 'http://www.tumblr.com/oauth/authorize',
    consumerKey: secrets.tumblr.consumerKey,
    consumerSecret: secrets.tumblr.consumerSecret,
    callbackURL: secrets.tumblr.callbackURL,
    passReqToCallback: true
  },
  function(req, token, tokenSecret, profile, done) {
    User.findById(req.user._id, function(err, user) {
      user.tokens.push({ kind: 'tumblr', accessToken: token, tokenSecret: tokenSecret });
      user.save(function(err) {
        done(err, user);
      });
    });
  }
));

is so obtain accessToken and tokenSecret so I can use it with the Tumblr API library.

And since you didn't provide a full error stack I assume 500 TypeError: Cannot read property '_id' of undefined refers to this line:

User.findById(req.user._id, function(err, user) {

I am surprised that req.user is undefined. Before you can see Tumblr page it will ask you to first sign-in, at which point req.user should be defined.

from hackathon-starter.

sahat avatar sahat commented on May 10, 2024

@brianyang For passport-tumblr, of course you will get oauth_consumer_key not recognized if you're just trying to run their examples without inputting your own consumerKey and consumerSecret.

Did you follow Tubmlr instructions on Obtaining API Keys in README?

from hackathon-starter.

brianyang avatar brianyang commented on May 10, 2024

@sahat what's the difference between authenticating with tumblr, vs fb, twitter, instagram? i'm wondering why the login view doesn't show that the user is logged in with tumblr. i see the key and secret coming back, that's all that's needed to authenticate requests from the tumblr API. i was just wondering what's the difference between tumblr passport and the other passports i've tried, fb, twitter, instagram, fitbit. with these other ones it shows 'logout' after authorizing the app.

do you know why this is?

from hackathon-starter.

sahat avatar sahat commented on May 10, 2024

I am using passport plugins for Facebook, Twitter, Google, GitHub to do authentication. In other words you can use those providers to sign in, create account, logout. In addition to authentication you can also access those APIs, because when you login you also get an access token.

Tumblr, Venmo, Foursquare on the other hand are not used for authentication, only for API requests.

To be honest you can use anything for authentication, but most people won’t need more than 3 - Twitter, Google, Facebook. Imagine if I made every OAuth provider to be used for authentication; they wouldn’t fit on the login screen!

I use passport-facebook, passport-twitter, passport-google-oauth, passport-github, passport-whatever, when I know I will be using it for user authentication. I use plain passport-oauth when I need to obtain accessToken and I don’t plan on using that service for user authentication.

If you want to sign in with Tumblr or Instagram find passport-tumblr and passport-instagram. You might be able to use custom-defined Tumblr strategy via passport-oauth, but I am not exactly sure how that would work.

// Using it for sign-in
app.get('/auth/facebook', passport.authenticate('facebook', { scope: ['email', 'user_location'] }));
app.get('/auth/facebook/callback', passport.authenticate('facebook', { successRedirect: '/', failureRedirect: '/login' }));
// Not used for sign-in, only for obtaining an access_token to get user’s checkins.
app.get('/auth/foursquare', passport.authorize('foursquare'));
app.get('/auth/foursquare/callback', passport.authorize('foursquare', { failureRedirect: '/api' }), function(req, res) {
  res.redirect('/api/foursquare');
});

from hackathon-starter.

sahat avatar sahat commented on May 10, 2024

@brianyang were you able to resolve your issue?

from hackathon-starter.

brianyang avatar brianyang commented on May 10, 2024

@sahat, app.js authorizes with tumblr:

app.get('/auth/tumblr', passport.authorize('tumblr'));

then it invokes this function:

    User.findById(req.user._id, function(err, user) {
      user.tokens.push({ kind: 'tumblr', accessToken: token, tokenSecret: tokenSecret });
      ... 
    });

what is findById() doing here? after authorizing the Tumblr app, req.user is undefined. this will always return undefined and the tokens will never be saved. what is the intended interaction?

should we save both of these tokens and use these to authorize the API requests?

Thanks,

from hackathon-starter.

sahat avatar sahat commented on May 10, 2024

@brianyang Yes you need both tokens. Regarding req.user being undefined is because user is not logged in. Being logged in is a pre-requisite for using Tumblr API or any other API that uses accessToken. At least it is in Hackathon Starter.

from hackathon-starter.

brianyang avatar brianyang commented on May 10, 2024

awesome, thanks!

from hackathon-starter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.