如何在settings.json中将Amazon凭据与Facebook凭据相结合

时间:2016-11-29 21:53:25

标签: meteor amazon-s3 facebook-login

我正在尝试以正确的方式设置我的settings.json文件,但我似乎无法让它工作。

我目前在文件中保存了我的Amazon S3凭据,但是当我想添加微博或FB凭据时,我的应用程序一直在崩溃。

添加多项服务的正确方法是什么?

目前它看起来像这样:

{
	"AWSAccessKeyId": "Amazon key",
	"AWSSecretAccessKey": "Amazon secret"
}

我需要添加以下内容:

ServiceConfiguration.configurations.upsert(
  { service: "weibo" },
  {
    $set: {
      clientId: "1292962797",
      loginStyle: "popup",
      secret: "75a730b58f5691de5522789070c319bc"
    }
  }
);

FB凭证也是如此。在1个文件中组合所有这些的正确方法是什么?

当我按照以下建议设置我的文件时出现此错误:错误:匹配错误:缺少密钥'AWSAccessKeyId'

这是我的settings.json设置:

{
  "public": {

  },
  "private": {
    "facebook": {
      "appId": "FBId",
      "secret": "FBsecret"
    },
    "weibo": {
      "clientId": "WeiboId",
      "secret": "WeiboSecret"
    },
    "aws": {
      "bucket": "ec2016",
      "AWSAccessKeyId": "S3Id",
      "AWSSecretAccessKey": "S3Secret",
      "region": "eu-central-1"
    }
  }
}

更新:

在我收到的帮助之后,我设置了我的setting.json文件和服务器上另一个名为configure-services的文件。看起来像这样。修好拼写错误(Duh ......)后现在一切正常!非常感谢!

const p = Meteor.settings.private;

const faceAppId = p.facebook.appId;
const faceSecret = p.facebook.secret;

const S3KeyId = p.aws.key;
const S3AccessKey = p.aws.secret;

ServiceConfiguration.configurations.upsert({
  service: 'facebook'
}, {
  $set: {
    service: 'facebook',
    appId: faceAppId,
    secret: faceSecret,
  },
});

Slingshot.fileRestrictions("myImageUpload", {
  allowedFileTypes: ["image/png", "image/jpeg", "image/gif", "video/mp4", "video/avi", ],
  maxSize: 10 * 1024 * 1024, // 10 MB (use null for unlimited)
});

Slingshot.createDirective('myImageUpload', Slingshot.S3Storage, {
  bucket: p.aws.bucket,
  region: p.aws.region,
  AWSAccessKeyId: S3KeyId,
  AWSSecretAccessKey: S3AccessKey,
  acl: 'public-read',

  authorize: function () {
    //Deny uploads if user is not logged in.
    if (!this.userId) {
      var message = "Please login before posting files";
      throw new Meteor.Error("Login Required", message);
    }
    return true;
  },

  key: function (file) {
    //Store file into a directory by the user's username.
    var user = Meteor.users.findOne(this.userId);
    return user.username + "/" + file.name;
  }
});

1 个答案:

答案 0 :(得分:1)

这是我settings.json文件的格式:

{
  "public": {

  },
  "private": {
    "facebook": {
      "namespace": "",
      "appId": "",
      "secret": ""
    },
    "google": {
      "clientId": "",
      "secret": ""
    },
    "aws": {
      "bucket": "",
      "key": "",
      "secret": "",
      "region": ""
    }
  }
}

然后按如下方式使用它们:

const p = Meteor.settings.private;

const faceAppId = p.facebook.appId;
const faceSecret = p.facebook.secret;

const ggClientId = p.google.clientId;
const ggSecret = p.google.secret;

ServiceConfiguration.configurations.upsert({
  service: 'facebook'
}, {
  $set: {
    service: 'facebook',
    appId: faceAppId,
    secret: faceSecret,
  }
});


ServiceConfiguration.configurations.upsert({
  service: 'google'
}, {
  $set: {
    service: 'google',
    clientId: ggClientId,
    secret: ggSecret,
  }
});

Slingshot.createDirective('imageUpload', Slingshot.S3Storage, {
  bucket: p.aws.bucket,
  region: p.aws.region,
  AWSAccessKeyId: p.aws.key,
  AWSSecretAccessKey: p.aws.secret,
  acl: 'public-read',
  maxSize: 20 * 1024 * 1024,
  allowedFileTypes: ['image/png', 'image/jpeg', 'image/gif'],
  authorize: function() {
    // ...
  },
  key: function() {
    // ...
  }
});