为什么要调用这个核心包?

时间:2015-03-16 09:33:36

标签: meteor

我正在尝试通过OAuth与Google进行身份验证,这是我的服务器代码

my.fetchTokens = function(code) {

    var endpoint = 'https://accounts.google.com/o/oauth2/token';
    var params   = {
      code: code,
      client_id: Meteor.settings.google.CLIENT_ID,
      client_secret: Meteor.settings.google.CLIENT_SECRET,
      redirect_uri: Meteor.settings.google.REDIRECT_URL,
      grant_type: 'authorization_code',
    };

    try {
      response = HTTP.post(endpoint, { params: params });
    } catch (err) {
      throw _.extend(new Error("Failed to complete OAuth handshake with Google. " + err.message),
                     {response: err.response});
    }

    if (response.data.error) { // if the http response was a json object with an error attribute
      throw new Error("Failed to complete OAuth handshake with Google. " + response.data);
    }

    var tokens = {
      accessToken: response.data.access_token,
      refreshToken: response.data.refresh_token,
      expiresIn: response.data.expires_in,
      idToken: response.data.id_token
    };
    console.log(tokens);
    return tokens;
  }; 

但是当我调用此方法时,我收到以下警告

 W20150316-10:30:05.853(1) (oauth_server.js:71) Unable to base64 decode state from OAuth query: undefined
W20150316-10:30:05.854(1) (oauth_server.js:71) Unable to base64 decode state from OAuth query: undefined
W20150316-10:30:05.855(1) (oauth_server.js:71) Unable to base64 decode state from OAuth query: undefined
W20150316-10:30:05.855(1) (oauth_server.js:398) Error in OAuth Server: Match error: Expected string, got undefined

但我不明白为什么oauth_server.js:71被引用

任何想法?

1 个答案:

答案 0 :(得分:0)

可能是因为您正在调用OAuth.openSecretOAuth._redirectUri('google', config)

我假设其中一个调用解析当前的URL。