【问题标题】:node imap xoauth2 authentication failed节点 imap xoauth2 身份验证失败
【发布时间】:2016-05-20 11:54:10
【问题描述】:

我正在使用 xoauth2 模块生成一个 xoauth2 令牌以通​​过 imap 连接到 gmail,我收到此错误:

`

[09:50:28.806] [LOG] [connection] Connected to host
[09:50:28.873] [LOG] <= '* OK Gimap ready for requests from 31.154.25.42 q4mb701
07656lfe'
[09:50:28.881] [LOG] => 'A0 CAPABILITY'
[09:50:29.067] [LOG] <= '* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID
 XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIE
NTTOKEN AUTH=OAUTHBEARER AUTH=XOAUTH'
[09:50:29.069] [LOG] <= 'A0 OK Thats all she wrote! q4mb70107656lfe'
[09:50:29.073] [LOG] => 'A1 AUTHENTICATE XOAUTH2 ******************************************
****************************************************************************************************************************
********************************************************************************='
[09:50:29.374] [LOG] <= '+ eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2Nvc
GUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ=='
[09:50:29.377] [LOG] => '\r\n'
[09:50:29.534] [LOG] <= 'A1 NO [AUTHENTICATIONFAILED] Invalid credentials (Failu
re)'
[09:50:29.537] [ERROR] ERROR Imap:Error: Invalid credentials (Failure)
[09:50:29.755] [LOG] [connection] Ended
[09:50:29.756] [LOG] Imap: Connection ended
[09:50:29.758] [LOG] [connection] Closed`

这是我的连接代码:

this.setImap = function(connParams) {
    //----------------------------------------------
    console.log(connParams);
    xoauth2gen = xoauth2.createXOAuth2Generator({
      user: connParams.user",
      clientId: configAuth.googleAuth.clientID,
      clientSecret: configAuth.googleAuth.clientSecret,
      refreshToken: connParams.refresh_token,
      accessToken: connParams.access_token,
       customPayload: {
      "access_type": "offline"
    }
    });

xoauth2gen.getToken(function(err, token) {
  if (err) {
    return console.log(err);
  }
  console.log("AUTH XOAUTH2 " + token);
  connParams.xoauth2 = token;
});

connParams = {
  id: 13,
  user: connParams.user,
  xoauth2: connParams.xoauth2,
  host: 'imap.gmail.com',
  port: 993,
  tls: 1,
  debug: console.log
}
//------------------------------------------- 
connParams.tlsOptions = {
  rejectUnauthorized: false
};

console.log(connParams);



self.imap = new Imap(connParams);

this.imap.once('ready', function() {
  console.log('Imap: ready');
  self.openInbox();
});

this.imap.once('error', function(err) {
  console.error("ERROR Imap:" + err);
});

this.imap.once('end', function() {
  console.log('Imap: Connection ended');
});
};

详细检查了一百万次:(

这是我正在使用的范围:

scope: ['profile', "https://mail.google.com/" ]

如果有任何帮助,我将不胜感激,谢谢!!

【问题讨论】:

  • 错误信息是base64解码的:{"status":"400","schemes":"Bearer","scope":"mail.google.com"}
  • 您在何时何地获得刷新令牌?

标签: node.js oauth-2.0 imap gmail-imap google-oauth


【解决方案1】:

您应该从 connParams 中删除用户,并在 xoauth 模块中添加一个空格...

【讨论】:

  • 能否指定,在xoauth模块中加个空格,这是什么意思
猜你喜欢
  • 2020-08-19
  • 2016-01-26
  • 2020-10-24
  • 2016-06-30
  • 2020-11-10
  • 2017-01-27
  • 2017-09-08
  • 2020-12-03
  • 1970-01-01
相关资源
最近更新 更多