Oauth "Service Not Configured" Error?


#1

I’m working on my accounts UI and getting a “Service Not Configured” error. I’m using React and Material-UI, so the currently available Atmosphere/NPM UI packages don’t appear to offer a solution I can use. I’ve checked the Meteor Guide and other sample projects, but haven’t yet found sample code for this.

Here’s what my settings.json looks like:

{
  "public": {},
  "private": {
    "oAuth": {
      "facebook": {
        "appId": "myAppID",
        "secret": "myAppSecret",
        "redirect_uri" : "/"
      }
    }
  }
}

And here’s my code to call the Facebook oauth:

    performSocialLogin(service){  //<==service == "loginWithFacebook"
        const options = {
            requestPermissions: ['user_friends', 'public_profile', 'email']
        };

        Meteor[service]({
            requestPermissions: options
        }, (err) => {
            if (err) {
                console.log('Login error - ', err);  <== "SERVICE NOT CONFIGURED"
            } else {
                console.log('Login error - ', err);
            }
        });
    }

What do I need to do to my settings.json file to complete the call to Meteor.loginWithFacebook?


#2

Have you set up the service configuration?

In your server code:

Meteor.startup(() => {
  ServiceConfiguration.configurations.upsert(
    { service: 'facebook' },
    {
      $set: {
        clientId: Meteor.settings.private.oAuth.facebook.appId,
        loginStyle: 'popup',
        secret: Meteor.settings.private.oAuth.facebook.secret
      }
    }
  );
});

You only ever need to do that once (unless you trash your database, change your keys, etc), so keeping the data in settings may be overkill.


#3

Thanks, @robfallows. I found my upsert code wasn’t being called. I moved it to a place and verified it was being called. I also added loginStyle: popup.


#4

Hello, any chance you could post how you did this? I am new to Meteor and trying to accomplish the same thing. I am just not sure what files the code is suppose to go in.


#5

I’m using Mantra, and so I may have a different folder layout than the one you are using. However, that said, I put the following in server/main.js.

//run this code whenever the oauth keys in settings.json change
const services = Meteor.settings.private.oAuth;

if (services) {
    for (let service in services) {
        ServiceConfiguration.configurations.upsert({service: service}, {
            $set: services[service]
        });
    }
}

Note on Mantra: Arunoda has recently mentioned that there’s a pretty big learning curve on Mantra, so I wouldn’t necessarily recommend it for a new Meteor user.


#6

Thanks, Im trying that but I keep get ‘Cannot read property ‘oAuth’ of undefined’. Is there something at the top of the file that you are importing? Thanks for the help!


#7

Do you have a settings.json file yet? This is a file, located in your app root folder, called “settings.json”, that looks like this:

{
  "public": {},
  "oAuth": {
    "facebook": {
      "appId": "yourID",
      "secret": "yourSecret",
      "redirect_uri" : "/"
    },
    "github": {
      "clientId": "",
      "secret": ""
    },
    "google": {
      "clientId": "",
      "secret": ""
    },
    "twitter": {
      "consumerKey": "",
      "secret": ""
    }
  }
}

To load it, launch your app like this:

meteor --settings settings.json


#8

Actually I got it without a settings file. All I had to do was add this to my main.js:

    import { Meteor } from 'meteor/meteor';
    import { ServiceConfiguration } from 'meteor/service-configuration';

    Meteor.startup(() => {
         ServiceConfiguration.configurations.upsert(
                  { service: 'facebook' },
         {
           $set: {
                 appId: 'xxx',
                 loginStyle: 'popup',
                 secret: 'xxx',
           },
         }
       );
     });

#9

That’s good, but less secure than it could be. Here’s a great article by @joshowens on the subject:

http://joshowens.me/environment-settings-and-security-with-meteor-js/


#10

Thanks, I can always secure it better. I wanted to just get it working for proof of concept first. Thanks for all your help. you are the only in the the couple forums that I posted on that responded.


#11

You’re very welcome!