How do I REconfigure Meteor's accounts-facebook, or where is Meteor's Facebook configuration?

后端 未结 6 1562
灰色年华
灰色年华 2021-01-30 14:59

Meteor\'s accounts-facebook package was very easy to set up. To input the Facebook app ID and secret token, I loaded my meteor web app in a browser, and clicked on

相关标签:
6条回答
  • 2021-01-30 15:36

    This will simply delete all services at startup and reinsert them based upon your settings.json (meteor --settings settings.json) Coffee-script equivalent:

    @privateSettings = Meteor.settings.private
    
    for s in privateSettings.services
      ServiceConfiguration.configurations.remove service: s.service
      ServiceConfiguration.configurations.insert s
    

    Settings stored in settings.json:

    {
      "private": {
        "services": [{
            "service": "google",
            "clientId": "yourappid.apps.googleusercontent.com",
            "secret": "yoursecret"
        },{ 
            "service": "twitter",
            "consumerKey": "yourconsumerkey",
            "secret": "yoursecret"
        },{
            "service": "facebook",
            "appId": "yourappid",
            "secret": "yoursecret"
        }],
      }
    }
    
    0 讨论(0)
  • 2021-01-30 15:37

    If you don't already have much data in your application, just run:

    meteor reset
    

    This will wipe out all of Mongo's data for the app.

    0 讨论(0)
  • 2021-01-30 15:42

    The configuration data is stored in mongodb.

    If you load up

    meteor mongo
    

    Then use db.meteor_accounts_loginServiceConfiguration.find() you should see your config data

    You can update it too! If you got back

    { "service" : "x", "appId" : "x", "secret" : "x", "_id" : "abc" }`
    

    Within the same mongo shell:

    db.meteor_accounts_loginServiceConfiguration.update({_id:'abc'},
        {$set:{"appId" : <new app id>, "secret" : <new secret>}});
    

    (Using the _id field from the service configuration that you want to edit.

    Within Meteor you can use this instead:

    ServiceConfiguration.configurations.update({
        service:"facebook"
    }, {
        $set: {
            <new params>
        }
    });
    

    Note to do this within meteor you need to add this package in with :

    meteor add service-configuration
    
    0 讨论(0)
  • 2021-01-30 15:55

    How about this:

    Accounts.loginServiceConfiguration.insert({
      service: "facebook",
      appId: "1292962797",
      secret: "75a730b58f5691de5522789070c319bc"
    });
    

    Found here: http://docs.meteor.com/#meteor_loginwithexternalservice

    0 讨论(0)
  • 2021-01-30 15:55

    [NOTE: for Meteor >= 1.2.2]

    The official Meteor documentation here explains how to do it.

    Add the service-configuration package (otherwise you can't use ServiceConfiguration):

    $ meteor add service-configuration
    

    Then you can put this in Meteor.startup:

    Meteor.startup(function () {
    
      // Set Facebook app configurations
      ServiceConfiguration.configurations.upsert({ 
        service: "facebook" 
      }, {
        $set: {
          appId: 'YOUR_APP_ID',
          secret: 'YOUR_APP_SECRET'
        }
      });
    
      return;
    });
    

    Externalize Facebook configurations in settings.json

    Perhaps the final solution is to put Facebook app's configurations in a setting file

    /settings.json
    

    Like this:

    {
      "facebook" : {
        "appId": "APP_ID",
        "secret": "APP_SECRET"
      }
    }
    

    Then you have to start your Meteor application with

    $ meteor --settings settings.json
    

    in order to load the settings file.

    Finally you can load Facebook configurations inside Meteor.startup from the settings file:

    Meteor.startup(function () {
    
      // Load and set Facebook app configurations
      var facebookConfig = Meteor.settings.facebook;
      ServiceConfiguration.configurations.upsert({ 
        service: "facebook" 
      }, {
        $set: {
          appId: facebookConfig.appId,
          secret: facebookConfig.secret
        }
      });
    
      return;
    });
    
    0 讨论(0)
  • 2021-01-30 16:00

    To elaborate on Kristoffer's answer, here is how to configure an app at runtime

    /server/boot.js

    configureFacebook = function(config) {
        // first, remove configuration entry in case service is already configured
        ServiceConfiguration.configurations.remove({
            service: "facebook"
        });
    
       ServiceConfiguration.configurations.insert({
            service: "facebook",
            appId: config.clientId,
            secret: config.secret
        });
    };
    
    // set the settings object with meteor --settings private/settings-local.json
    var facebookConfig = Meteor.settings.facebook;
    if(facebookConfig) {
        console.log('Got settings for facebook', facebookConfig)
        configureFacebook(facebookConfig);
    }
    

    This is used in conjunction with some settings files that are used locally and for production:

    /private/local-settings.json

    {
        "facebook" : {
            "clientId": "330foobar",
            "secret": "52e1e247a5a1234klasdf087vasdff07"
        }
    }
    

    To develop locally I just do meteor --settings private/local-settings.json and to deploy the production settings for facebook to the production server I do meteor deploy --settings private/prod-settings.json.

    0 讨论(0)
提交回复
热议问题