Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

node.js - Google OAuth 2.0 doesn't call the callback function

I've tested this passport google strategy locally and it works well, the callback function is called successfully and I can login using the google account. However when I push this code to the production server I see that the callback function is not being called. From the user perspective when they click on the link to use the google strategy they are presented with the google 'pick an account' screen, and then it loads for a bit before dumping them back on the page they were on before. I don't see where the problem is. Thank you in advance for your help!

passport.use('google', new GoogleStrategy({
    clientID: "redacted",
    clientSecret: "redacted",
    callbackURL: "/google/callback"
  },
    function(accessToken, refreshToken, profile, done) {
          const userQueryString = `
            SELECT firstName, lastName, AgentReference, agent_number, website_password, account_type, status, state, BIN(Flags) as flags 
            FROM compass.agent 
            WHERE googleID = ?`;
          console.log("google profile: 
", profile);
          //pull the user data for the agent with the same googleID as the selected accoutn at login.
          db.query(userQueryString,[profile.id],(err, response, fields)=>{
            if(err) {
              done(err);
            } else if(response.length === 0) {
              done(null, false);
            } else if(response[0].status === 'Terminated') {
              console.log('account is terminated.');
              done(null, false);
            } else {
              let user = {
                id: response[0].AgentReference
                , accountType: response[0].account_type
                , agent_number:response[0].agent_number
                , name:response[0].firstName + ' ' + response[0].lastName
                , state: response[0].state
                , flags: response[0].flags
              };
              let flagRegex = RegExp('^[0-1]*1[0-1]{9}$');
              if(flagRegex.test(user.flags)){
                console.log(JSON.stringify(user));
                return done(null, user);
              } else {
                return done(null, false, {message: "You do not have access to this feature. Please speak with your manager for more information."})
              }
            }
      });
    }
  )
);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...