Exemplo n.º 1
0
	function checkLocation() {
		if(!w.location) {
			clearInterval(interval)
			return cb(new Error('oauth dialog closed'))
		}

		if(w.location.hostname === window.location.hostname) {
			clearInterval(interval)

			var search = w.location.search.substr(1) // remove ? on beginning
			var query = qs.decode(search)

			var err = []

			if(query.state !== state) {
				err.push('mismatching state ('+state+' != '+query.state+')')
			}
			if(query.error) {
				err.push(query.error)
			}
			if(err.length > 0) {
				return cb(new Error(err.join()))
			}

			w.close()

			auth.tradeCode(res.meta, res.auth, query.code, onToken)
		}
	}
Exemplo n.º 2
0
  db.getTempAuthStoreById(req.params.id, function(tAuth) {
    // check state
    var store = tAuth.store;
    if(store.state !== req.query.state) {
      return res.send('mismatching state') //it's an existing user?
    } else if(req.query.error) {
       return res.send('Error during auth, please try again or contact your tent provider');
    } else {
      var entityName = tAuth.entity;
 
      // make the final request, to trade the code for permanent credentials
      auth.tradeCode(store.meta.post.content, store.tempCreds, req.query.code,
        function(err, permaCreds) {

          if(err) {
            console.log("err:" + err);
            return res.send(err);
          } else {
                       
            db.updateTempAuthStoreCredsByEntity(entityName, permaCreds, function() {

                req.session.entityStore = tAuth;
                req.session.entityStore.store.creds = permaCreds;
              
                if(typeof(tAuth.email) !== 'undefined') {
                  console.log("log in successful, going to inbox!");
                  return res.redirect('/');
                } else {
                  console.log("new user, let's get them a tentmail address!");
                  return res.redirect('/registration');
                }
            });
       
          }
        });
    }
  });