Skip to content

Instantly share code, notes, and snippets.

@themeteorchef
Last active April 24, 2018 11:26
Show Gist options
  • Save themeteorchef/e843ca232c082dc84136 to your computer and use it in GitHub Desktop.
Save themeteorchef/e843ca232c082dc84136 to your computer and use it in GitHub Desktop.
oAuth Configuration Pattern for Meteor
{
"private": {
"oAuth": {
"facebook": {
"development": {
"appId": "xxx",
"secret": "xxx"
},
"staging": {
"appId": "xxx",
"secret": "xxx"
},
"production": {
"appId": "xxx",
"secret": "xxx"
}
},
"github": {
"development": {
"clientId": "xxx",
"secret": "xxx"
},
"staging": {
"clientId": "xxx",
"secret": "xxx"
},
"production": {
"clientId": "xxx",
"secret": "xxx"
}
},
"google": {
"development": {
"clientId": "xxx",
"secret": "xxx"
},
"staging": {
"clientId": "xxx",
"secret": "xxx"
},
"production": {
"clientId": "xxx",
"secret": "xxx"
}
}
}
}
}
/*
* Service Configuration
* Configuration for third-party login services.
* Note: customize the config object and switch below to include additional services.
*/
createServiceConfiguration = function(service, clientId, secret){
ServiceConfiguration.configurations.remove({
service: service
});
var config = {
generic: {
service: service,
clientId: clientId,
secret: secret
},
facebook: {
service: service,
appId: clientId,
secret: secret
}
}
switch (service) {
case "facebook":
ServiceConfiguration.configurations.insert(config.facebook);
break;
default:
ServiceConfiguration.configurations.insert(config.generic);
break;
}
}
/*
* Configure oAuth
* This is done with a switch to test the current environment, loading the
* appropriate keys for each.
*/
// Get the current environment and get our oAuth keys from settings.json.
var environment = process.env.NODE_ENV;
var oAuth = Meteor.settings.private.oAuth;
// Perform the switch and configure environment.
switch(environment){
case "development":
createServiceConfiguration('facebook', oAuth.facebook.development.appId, oAuth.facebook.development.secret);
createServiceConfiguration('github', oAuth.github.development.clientId, oAuth.github.development.secret);
createServiceConfiguration('google', oAuth.google.development.clientId, oAuth.google.development.secret);
break;
case "staging":
createServiceConfiguration('facebook', oAuth.facebook.staging.appId, oAuth.facebook.staging.secret);
createServiceConfiguration('github', oAuth.github.staging.clientId, oAuth.github.staging.secret);
createServiceConfiguration('google', oAuth.google.staging.clientId, oAuth.google.staging.secret);
break;
case "production":
createServiceConfiguration('facebook', oAuth.facebook.production.appId, oAuth.facebook.production.secret);
createServiceConfiguration('github', oAuth.github.production.clientId, oAuth.github.production.secret);
createServiceConfiguration('google', oAuth.google.production.clientId, oAuth.google.production.secret);
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment