Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

So I wrote a bunch of code for trying to use multiple SSO #1

Open
janat08 opened this issue Jun 27, 2017 · 1 comment
Open

So I wrote a bunch of code for trying to use multiple SSO #1

janat08 opened this issue Jun 27, 2017 · 1 comment

Comments

@janat08
Copy link

janat08 commented Jun 27, 2017

tmikoss/accounts-eveonline#4
Currently I'm stuck providing currently logged in user, since you want that if person first created account with passwords and then is adding chars. The accounts.js is outdated.


// import Accounts from 'accounts-base'
var Ap = Accounts.updateOrCreateUserFromExternalService
Meteor.startup(function(){
Accounts.updateOrCreateUserFromExternalService = function (
  serviceName,
  serviceData,
  options
) {

  if (serviceName == "eveonline") {
    var selector = {}
    var serviceIdKey = "services.eveonline.list.name"

    selector[serviceIdKey] = serviceData.name;

    var user = this.users.findOne(selector);

// if (serviceData.serviceData.name == "list") {
//   throw new Error("You're black sheep")
// }

//check that user on record is not previoius owner
    if (!!user && user.services.eveonline[serviceData.name].eveAccount != serviceData.eveAccount){
        EveonlineHelpers.changeOwnerShip(user._id, serviceData.name)
// XXX would ideally conduct these operations within update operation instead of js
        delete user.services.eveonline[serviceData.name]
        user.services.eveonline.list.filter((x)=>{
          return x.name == serviceData.name
        })
        this.users.update(user._id, {
          $set: {
            "services.eveonline": user.services.eveonline
          }
        })
        user = false
    }
    var abc = user()
    console.log(abc)
    //make sure that if previous owner exists, new user is created
    if (!!abc && user != false) {
      user = abc
    }

    if (user) {
      console.log("UPDATING USER")
      pinEncryptedFieldsToUser(serviceData, user._id);

      // We *don't* process options (eg, profile) for update, but we do replace
      // the serviceData (eg, so that we keep an unexpired access token and
      // don't cache old email addresses in serviceData.email).
      // XXX provide an onUpdateUser hook which would let apps update
      //     the profile too
      var setAttrs = {};
      _.each(serviceData, function (value, key) {
        setAttrs["services.eveonline."+ serviceData.name +"."+ key] = value;
      });

      // XXX Maybe we should re-use the selector above and notice if the update
      //     touches nothing?
      if(serviceName=="eveonline") {
        this.users.update(user._id, {
          $set: setAttrs,
          $addToSet: {"services.eveonline.list": {name: serviceData.name, id: serviceData.id}}
        });
      }

      return {
        type: serviceName,
        userId: user._id
      };

    } else {
      console.log("CREATING USER", abc)
      // Create a new user with the service data. Pass other options through to
      // insertUserDoc.
      user = {services: {}};
      user.services[serviceName] = {list: [{name: serviceData.name, id: serviceData.id}]};
      user.services[serviceName][serviceData.name] = serviceData
      return {
        type: serviceName,
        userId: this.insertUserDoc(options, user)
      };
    }

    /// XXX beginning of common/original SSO
  } else {
    Ap(
      serviceName,
      serviceData,
      options
    )
  }
};
})
function pinEncryptedFieldsToUser(serviceData, userId) {
  _.each(_.keys(serviceData), function (key) {
    var value = serviceData[key];
    if (OAuthEncryption && OAuthEncryption.isSealed(value))
      value = OAuthEncryption.seal(OAuthEncryption.open(value), userId);
    serviceData[key] = value;
  });
}

and ye, I made a couple of mistakes in other files.

@janat08
Copy link
Author

janat08 commented Jun 27, 2017

I'm thinking about just trying to use one of those packages for merging accounts, where they give you hooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant