2015-06-17 9 views
5

API'm için yardım için Deployd ve kimlik doğrulama için dpd-passport kullanarak bir proje yapıyorum.Geri arama/Yönlendirmeler Google stratejisiyle dpd-pasaporttan nasıl yönetilir?

Oturum anahtarının ardında ve kullanıcıların kimlik doğrulaması Google üzerinden doğrulanması gereken her şey var gibi görünüyor, ancak ben redirectURL s ile sorun yaşıyorum ve geri döndüğüm geri arama sayfasını çeviriyorum.

ben dpd-passport/index.js dosyaya kazdık ve bu ilgili bilgiler olduğuna inanıyorum: başarıyla kimlik doğrulaması sonra

var sendResponse = function(ctx, err, config) { 
var sessionData = ctx.session.data; 
var returnUrl = (ctx.req.cookies && ctx.req.cookies.get('_passportReturnUrl')) || null; 

if(returnUrl) { 
    var redirectURL = url.parse(returnUrl, true); 

    // only append if not disabled 
    if(!config.disableReturnParams) { 
     // delete search so that query is used 
     delete redirectURL.search; 

     // make sure query is inited 
     redirectURL.query = redirectURL.query || {}; 
     if(err) { 
      redirectURL.query.success = false; 
      redirectURL.query.error = err; 
     } else { 
      // append user + session id to the redirect url 
      redirectURL.query.success = true; 

      if(!config.disableSessionId) { 
       redirectURL.query.sid = sessionData.id; 
       redirectURL.query.uid = sessionData.uid; 
      } 
     } 
    } 

    var redirectURLString = ''; 
    try { 
     redirectURLString = url.format(redirectURL); 
    } catch(ex) { 
     console.warn('An error happened while formatting the redirectURL', ex); 
    } 

    // redirect the user 
    ctx.res.setHeader("Location", redirectURLString); 
    ctx.res.statusCode = 302; 

    ctx.done(null, 'This page has moved to ' + redirectURLString); 
    } else { 
     if(err) { 
      ctx.res.statusCode = 401; 
      console.error(err); 
      return ctx.done('bad credentials'); 
     } else { 
      ctx.done(err, { path: sessionData.path, id: sessionData.id, uid: sessionData.uid }); 
     } 
    } 
}; 

, bana verilen ediyorum bir returnUrl ait: Bir ile

http://localhost:3000/auth/google/callback?code=4/l4o-H2F4QKJ5tdKbVbGfWygTGRvhHgr9zrHWImFFKdM#

gövdesi:

{"path":"/users","id":"d03c0faccfe41134c193266afef979c5af33adf935aeff45844b0f9473dee4ab1fbd1114240e13ea9a542785da3845cfec984e3a5b8cb188d6c595b6fc39a726","uid":"747f97a9bcfa9811"}

Bu, sonuçların en üstteki kod bloğundaki son else ifadesine isabet ediyor gibi görünüyor.

Bu doğruysa, returnUrl benim NULL'dur. o takip snippet'indeki kurabiye bu kapma olmalıdır gibi dpd-pasaport dosyasındaki returnUrl kodunu geri izleme

, görünüşe:

if(ctx.query.redirectURL && this.config.allowedRedirectURLs) { 
    try { 
     this.regEx = this.regEx || new RegExp(this.config.allowedRedirectURLs, 'i'); 

     if(ctx.query.redirectURL.match(this.regEx)) { 
      // save this info into the users session, so that we can access it later (even if the user was redirected to facebook) 
      if (ctx.res.cookies) ctx.res.cookies.set('_passportReturnUrl', ctx.query.redirectURL); 
     } else { 
      debug(ctx.query.redirectURL, 'did not match', this.config.allowedRedirectURLs); 
     } 
    } catch(ex) { 
     debug('Error parsing RedirectURL Regex!', ex); 
    } 
} 

Bu eklemek için, ben benim allowedRedirectUrls config olarak:

Kaybettim ve eksik olduğum belli olan bir şey olduğunu umuyorum.

Ben aşağıdakine benzer pasaport yolları ve kimlik doğrulama stratejileri gördük, ama dpd-pasaport içine bu uygulamada başarısız olmuştur

: Ben ui-yönlendirici kullanıyorum

app.get('/auth/google/callback', 
    passport.authenticate('google', { failureRedirect: '/login' }), 
    function(req, res) { 
    // Successful authentication, redirect home. 
    res.redirect('/'); 
    }); 

Bütün bunlara eklemek için/angularjs.

cevap

2

Sen oauth prosedürünü başlatır bağlantı yoluyla dpd-pasaport için redirectURL sağlaması gerekir:

http://localhost:2403/auth/google?redirectURL=http://localhost 
İlgili konular