Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication fails for microsoft account #17

Closed
azamsolix opened this issue Jan 12, 2022 · 3 comments
Closed

Authentication fails for microsoft account #17

azamsolix opened this issue Jan 12, 2022 · 3 comments

Comments

@azamsolix
Copy link

Hi,
I am trying to get token so i can pass it to imap .Below is the sample code .However,I am getting accessToken and i am passing it to imap and it is returning authentication failed.
try {
//here i am getting access token and refreshtoken and
const accessToken = await client.getToken(tokenParams);
var xoauth2 = require("xoauth2"), xoauth2gen;
console.log('accesstoken', accessToken, accessToken.token.access_token);
xoauth2gen = xoauth2.createXOAuth2Generator({
user: "sathyakrishna2021@hotmail.com",
clientId: "282abac0-3xxxxx9",
clientSecret: "11w7Q~58UxxxxxxxxxxxxxxxxWBkWb.mPJOM1rgnI1a",
accessUrl :'https://login.live.com/oauth20_token.srf',
accessToken:accessToken.token.access_token,
customPayload: {
"access_type": "offline"
}
});

// SMTP/IMAP
xoauth2gen.getToken(function (err, token) {
    if (err) {
        return console.log(err);
    }

// Here i am getting token and i am passing this token to imap and it is returning authentication fail error
console.log("AUTH XOAUTH2 " + token);
let Imap = require('imap');

         var imap = new Imap({
        xoauth2 :token,
    host: 'outlook.office365.com',
    port: 993,
    tls: true,
    authTimeout: 3000,
             tlsOptions: { rejectUnauthorized: false },
debug:console.log

});
imap.connect()
imap.once('ready', function() {
console.log('connectied')
imap.end();
});
imap.once('end', function() {
console.log('Connection ended');
});
});

//   res.status(200).json({response:accessToken})

} catch (error) {
console.log('Access Token Error', error);
}
am i doing something wrong?
Could you please help me with this?
Waiting for your response.
Thanks
Azam Ahmed

@andris9
Copy link
Owner

andris9 commented Jan 12, 2022

This library has been unmaintained for the last 7 years. Both Google and Microsoft have their own OAuth authentication libraries now, so there is no need for the xoauth2 library. When you create an application in Azure Directory then there is an option to download a sample Node.js application that shows you how to use their library. You could also check how other applications handle OAuth2 with Microsoft, eg you can find a tutorial for using it with EmailEngine here

@andris9 andris9 closed this as completed Jan 12, 2022
@giacomobartoli
Copy link

@andris9 so there's no way to use node-imap library with the new Microsoft OAuth authentication?
My idea is to use their SDK to generate the token, then create the xoauth2 string and still use node-imap to get notified about new incoming emails.

@andris9
Copy link
Owner

andris9 commented Oct 1, 2022

@giacomobartoli I know nothing about the node-imap library. The only option I provide support for is https://emailengine.app/ - you can use it to listen for incoming emails with Microsoft accounts as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants