IMAP 如何使用 OAuth 或 OAuth2 身份验证访问 Yahoo Mail

How can Yahoo Mail be accessed by IMAP using OAuth or OAuth2 authentication

根据 developer.yahoo.com/mail/ 和 IMAP 响应:

* OK [CAPABILITY IMAP4rev1 ID MOVE NAMESPACE X-ID-ACLID UIDPLUS LITERAL+ CHILDREN XAPPLEPUSHSERVICE XYMHIGHESTMODSEQ AUTH=PLAIN AUTH=LOGIN AUTH=XOAUTH2 AUTH=XYMCOOKIE AUTH=XYMECOOKIE AUTH=XYMCOOKIEB64 AUTH=XYMPKI] IMAP4rev1 imapgate-1.8.1_01.20166 imap1009.mail.ne1.yahoo.com

可以使用 OAuth(2) 身份验证通过 IMAP 访问 Yahoo Mail。

我在 https://developer.yahoo.com/apps/ 上注册了我的应用程序,所以我有客户端 ID 和客户端密码。我没有找到任何与邮件相关的范围(API 权限)。尽管如此,我还是选择了注册我的应用程序时显示的所有 API 权限。

我尝试同时实施 OAuth 和 OAuth2。

OAuth2: 我无法获得范围 "mail-r" 的授权码。当我生成 URL(https://api.login.yahoo.com/oauth2/request_auth?client_id=CLIENT_ID&redirect_uri=oob&scope=mail-r&response_type=code) 并在浏览器中打开它时,会显示带有文本 "Developers: Please request scope from registered scopes and submit again." 的页面。它适用于其他范围。例如,我可以获得 "sdct-r"

的授权码

OAuth: 我能够获得访问令牌。但是当我用 AUTHENTICATE XOAUTH2 命令发送它时,我得到 "NO [AUTHENTICATIONFAILED] (#AUTH007) Bad scope" 响应。

所以问题是应该设置什么范围来使用 IMAP 和 OAuth(2) 访问 Yahoo Mail?

当您在 https://developer.yahoo.com/apps/ 上 creating/configuring 应用程序时,您必须添加 "Mail Read-Only" 范围。

不幸的是,当我刚刚尝试在新创建的应用程序上执行此操作时,该选项不可用。

您可能需要与 Yahoo 取得联系,让他们允许您请求这些范围。

2017 年 2 月 27 日更新: 由于 Yahoo 不幸关闭了下面引用的 cck-form.html 页面并且似乎没有允许新应用程序请求与邮件相关的 API 访问权限。希望这会改变。

以下是如何在 yahoo 上创建具有电子邮件完全访问权限的应用程序。 (最近雅虎从他们的 UI 中删除了这个选项)一旦适当的权限到位,获取 oauth 令牌和访问邮箱应该是直截了当的,我不会在这里介绍它。

  1. 访问https://developer.yahoo.com/oauth/guide/cck-form.html并查找"Here is an example form along with sample values you can use in the form"并将示例html复制到本地文件并保存。下面提供了 html 的副本。

  2. 在浏览器上打开文件。填写适当的信息(设置 scope=ymrf 以获得完整的邮件访问权限)并单击 "pop window with debug".

  3. 在弹出窗口中单击允许 window。如果您尚未在浏览器上登录雅虎,则需要登录。

转到 https://developer.yahoo.com/apps/,您应该会看到具有适当权限的应用。

<html>  
<head>  
    <title>CCK Example</title>  
</head>  
<body>  
  
<form target="yCredWindow" action="http://developer.apps.yahoo.com/projects/createconsumerkey" method="post" id="extAuthForm" name="extAuthForm">  
  
<h2>Inputs</h2>  
<p>* = Required</p>    
<table>  
    <tr><th>Field</th>  
        <th>Input</th></tr>  
  
    <tr><td>* Application Name: </td>  
        <td><input name="name" id="name" value="Janrain Engage"></td></tr>  
  
    <tr><td>Description: </td>  
        <td><input name="description" id="desc"></td></tr>  
  
    <tr><td>appid: </td>  
        <td><input name="appid" id="appid"></td></tr>  
  
    <tr><td>Return to: </td>  
        <td><input name="return_to" id="return_to"></td></tr>  
  
    <tr><td>* Third Party Name: </td>  
        <td><input name="third_party" id="third_party" value="Janrain"></td></tr>  
  
    <tr><td>* Scopes: </td>  
        <td><input name="scopes" id="scope" value="ysrw"></td></tr>  
  
    <tr><td>Favicon URL: </td>  
        <td><input name="favicon" id="favicon"></td></tr>  
  
    <tr><td>Application URL: </td>  
        <td><input name="application_url" id="application_url"></td></tr>  
  
    <tr><td>* Domain: </td>  
        <td><input name="domain" id="domain" value="www.janrain.com"></td></tr></table>  
  
<input type="hidden" name="debug" id="debug" value="true">  
  
<button type="reset">clear all fields</button>  
<button type="button" id="submitWithDebug">pop window with debug</button>  
</form>  
  
<h6>Note: A URL that starts with http:// is required for: Return to, Favicon URL and Application URL.  However, you will get an error if you include http:// for the Domain.</h6>  
  
<h2>Returns</h2>  
<table>  
    <tr><td>Key returned:</td>  
        <td><input type="text" id="cKeyInputField"></td></tr>  
  
    <tr><td>Secret returned:</td>  
        <td><input type="text" id="cSecretInputField"></td></tr>  
  
    <tr><td>Appid returned:</td>  
        <td><input type="text" id="returnAppid"></td></tr></table>  
  
<script src="http://yui.yahooapis.com/3.0.0/build/yui/yui-min.js"></script>  
<script>  
  
var formTarget = null;  
  
// used by return_to.html to set the fields with the data that comes back  
var setFields = function(id, val)  { document.getElementById(id).value = val; };  
  
// pops the window, then submits to it  
var popWindowOnSubmit = function(e)  {  
    window.open('', formTarget, 'status=0,toolbar=0,location=0,menubar=0,width=545,height=650');  
    document.extAuthForm.submit();  
};  
  
// handle submit when the button is clicked  
YUI().use('node', function(Y) {  
    formObject = Y.one('#extAuthForm');  
    formTarget = formObject.getAttribute('target');  
    Y.on('click', popWindowOnSubmit, '#submitWithDebug');  
});  
  
</script>  
  
</body>  
</html> 

您必须在访问授权端点时添加 scope=openid, 然后在 hittng 令牌端点后获取令牌后, 使用获得的访问令牌命中配置文件端点, 然后我们在个人资料 json 对象

下收到电子邮件

我找到了另一种创建启用邮件 API 权限的应用程序的方法。我注意到,如果您在 URL 中包含一个 'api' 参数,您可以指定要包含的范围,而不管它们是否在底部被选中。我注意到如果您在 URL 中提供 'api=mail',它默认包含邮件权限。因此,要创建具有邮件权限的新应用,请使用此 URL:

https://developer.yahoo.com/apps/create/?api=mail

为了让您在潜在范围列表中看到邮件复选框,雅虎必须将您的开发者帐户列入白名单。我找不到任何关于此的文档或如何请求它的说明,所以我无法用任何文档来支持它。

截至 2017 年 8 月,获取电子邮件地址的唯一方法是使用名为 Profiles - Read/Write Public 和 Private 的范围。雅虎的一个非常愚蠢的误导性选择,因为我们根本不想 "write" 任何东西。

令人头疼的是,这还将 return 与帐户关联的 所有 电子邮件列表,而不仅仅是主要电子邮件。并且无法准确识别哪个是真实的 - primary=true 字段 return 在列表中无法信任。