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

时间:2016-03-17 10:57:53

标签: oauth oauth-2.0 imap yahoo-mail yahoo-oauth

根据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

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

我在https://developer.yahoo.com/apps/上注册了我的应用,因此我获得了客户端ID和客户端密钥。我没有找到任何与Mail相关的范围(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)并在浏览器中打开它时,带有文本的页面“开发人员:请从已注册的范围请求范围并再次提交”。被展示。它适用于其他范围。例如,我可以获得“sdct-r”

的授权码

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

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

6 个答案:

答案 0 :(得分:11)

2017年2月27日更新:由于雅虎不幸删除了下面引用的cck-form.html页面并且似乎不允许新应用程序请求邮件,因此这种解决方法将不再适用相关的API访问。希望这会改变。

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

  1. 访问https://developer.yahoo.com/oauth/guide/cck-form.html并查找"以下是一个示例表单以及您可以在表单中使用的示例值"并将示例html复制到本地文件并保存。下面提供了html的副本。

  2. 在浏览器上打开文件。填写适当的信息(设置范围= ymrf以获取完整邮件访问权限),然后单击"使用调试"弹出窗口。

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

  4. 转到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> 
    &#13;
    &#13;
    &#13;

答案 1 :(得分:1)

截至2017年8月,获取电子邮件地址的唯一方法是使用名为个人资料 - 读/写公共和私人的范围。雅虎选择误导性的选择是非常愚蠢的,因为我们不想写&#34;写&#34;什么都没有。

作为额外的麻烦,这还会返回与该帐户关联的所有电子邮件列表,而不仅仅是主要电子邮件。并且无法准确识别哪个是真实的 - 列表中返回的 primary = true 字段无法信任。

答案 2 :(得分:0)

https://developer.yahoo.com/apps/上创建/配置应用时,您必须添加“Mail Read-Only”范围。

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

您可能需要与雅虎联系,让他们允许您申请这些范围。

答案 3 :(得分:0)

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

下收到电子邮件

答案 4 :(得分:0)

我找到了另一种创建启用了Mail API权限的应用的方法。我注意到你是否包括了一个&#39; api&#39;您可以在URL中指定要包含哪些范围的参数,无论它们是否在底部进行检查。我注意到你提供了#api = mail&#39;在URL中,它默认包含邮件权限。因此,要创建具有邮件权限的新应用,请使用以下URL:

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

答案 5 :(得分:0)

为了让您能够在潜在范围列表中看到邮件复选框,雅虎必须将您的开发者帐户列入白名单。我找不到任何关于此的文档,或者有关如何提出这些文档的说明,因此我无法使用任何文档对此进行备份。