Nodemailer: XOAuth2 returns "unauthorized_client"

Created on 12 May 2014  路  5Comments  路  Source: nodemailer/nodemailer

I want to send an email from the Google account currently logged, so I'm trying to send mail through XOAuth2 option.

I'm setting these parameters:

XOAuth2: {
  user: <application's email account which I login using oauth> (not the account i'm trying to send the mail),
  clientId: <Client ID for web application>,
  clientSecret: <Client secret from web application>,
  refreshToken: <the one I get in OAuth 2.0 Playground>
}

Also I'm using hello.js for authenticating with OAuth2.

Is this configuration correct?
Thanks in advance!

Most helpful comment

For anyone having "unauthorized_client" issues whilst the following apply:

I finally solved it following the documentation here: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority

In essence going to
https://admin.google.com/yourgsuitedomain.com/ManageOauthClients
Adding a client id (from service account) and scope: https://mail.google.com/ (final slash important)

Emails started working after that.

All 5 comments

unauthorized_client might happen when clientId and clientSecret do not match

It says 'Username and Password not accepted. [...]"

I use clientId, clientSecret and user (email address) from console.developers.google.com.

XOAuth2 parameters change depending on who is sending the email or those parameters are from Google App owner?

I already added https://mail.google.com/ scope on Google's OAuth 2.0 Playground

Any chance to send an email using this library, without requiring the user to type his password every time?

Check the following things :-

  1. The Redirect URI is set to "https://developers.google.com/oauthplayground" in your Google Developer Console Project.
  2. Enter the values of "pass" parameters too. Something like
    XOAuth2: { user: "[email protected]", // Your gmail address. pass: "XXXXXXXXXXXXXXX", // Not @developer.gserviceaccount.com clientId: "XXXXXXXXXXXXX", clientSecret: "XXXXXXXXXXXXX", refreshToken: "XXXXXXXXXXXXX" }

Check This Example

For anyone having "unauthorized_client" issues whilst the following apply:

I finally solved it following the documentation here: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority

In essence going to
https://admin.google.com/yourgsuitedomain.com/ManageOauthClients
Adding a client id (from service account) and scope: https://mail.google.com/ (final slash important)

Emails started working after that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tegarkurniawan picture tegarkurniawan  路  3Comments

mohammedSlimani picture mohammedSlimani  路  4Comments

uiteoi picture uiteoi  路  5Comments

JYC-99 picture JYC-99  路  6Comments

ryanrolds picture ryanrolds  路  4Comments