Populating username & appname using parse-server-mandrill-adapter, not working - mandrill

Im trying to use parse-server-mandrill-adapter for generating a new password for users who has forgot their passwords.
I am using a parse-server and I am using parse unbuilt function requestPasswordReset to generate a mail to the user. I manage to send the email successfully to the user using parse-server-mandrill-adapter, however I cant manage to get any data concerning the user included in this. E.g fields like username, appname do not populate.
Parse server index.js
emailAdapter: {
module: 'parse-server-mandrill-adapter',
options: {
// API key from Mandrill account
apiKey: process.env.MANDRILL_API_KEY || '',
// From email address
fromEmail: 'kontakt#bonsai.se',
// Display name
displayName: 'no-reply#bonsai.se',
// Reply-to email address
replyTo: 'no-reply#bonsai.se',
// Verification email subject
verificationSubject: 'Please verify your e-mail for *|appname|*',
// Verification email body
verificationBody: 'Hi *|username|*,\n\nYou are being asked to confirm the e-mail address *|email|* with *|appname|*\n\nClick here to confirm it:\n*|link|*',
// Password reset email subject
passwordResetSubject: 'Password Reset Request for *|appname|*',
// Password reset email body
passwordResetBody: 'Hi apa *|username|*,\n\nYou requested a password reset for *|appname|*.\n\nClick here to reset it:\n*|link|*'
}
The main.js file, where the requestPasswordReset function is called, with email, options and callback.
var query = new Parse.Query(Parse.User)
query.equalTo("email", request.params.email)
query.first({
useMasterKey: true
}).then(function (user) {
Parse.User.requestPasswordReset(request.params.email, {
options: {
"username": "test",
useMasterKey: true
}
}).then(function (success) {
console.log(success)
response.success("success")
}, function (error) {
console.log(error)
response.error("error")
});
})
The look of the email.
How the email looks

Take a look at : https://github.com/ParsePlatform/parse-server
Email verification and password reset
Also similar question & answer :
Parse open source server reset password error
I use the MailGun adapter which is included into the open-parse server and works like a charm!

I was able to use the parse-server-mandrill-adapter, and successfully reset user passwords with proper replacements to the email/appname/link:
1) Install the parse-server-mandrill-adapter, (add it to the package.json to be able to deploy it onto the remote server).
2) Update your index.js to support the emailAdapter, source link:
var server = ParseServer({
...
// App Name
appName: 'YourAppName',
// Environment where the user can confirm his e-mail address or reset his password (most likely the same as your 'serverURL')
publicServerURL: 'YourPublicServerURL',
emailAdapter: {
module: 'parse-server-mandrill-adapter',
options: {
// API key from Mandrill account
apiKey: 'API-KEY',
// From email address
fromEmail: 'no-reply#yourdomain.com',
// Display name
displayName: 'no-reply#yourdomain.com',
// Reply-to email address
replyTo: 'no-reply#yourdomain.com',
// Verification email subject
verificationSubject: 'Please verify your e-mail for *|appname|*',
// Verification email body
verificationBody: 'Hi *|username|*,\n\nYou are being asked to confirm the e-mail address *|email|* with *|appname|*\n\nClick here to confirm it:\n*|link|*',
// Password reset email subject
passwordResetSubject: 'Password Reset Request for *|appname|*',
// Password reset email body
passwordResetBody: 'Hi *|username|*,\n\nYou requested a password reset for *|appname|*.\n\nClick here to reset it:\n*|link|*'
}
}
...
});
3) The password reset code:
Parse.User.requestPasswordReset(userEmail, {
success: function() {
// success
},
error: function(error) {
// error
}
});
4) Make sure when running that code, that your app is running from the remote server, it failed for me when running on localhost:1337!

Related

Sending mail using SendGrid in Groovy - Grails

I was using smtp server with Username password to send mail using the below function.
def sendEmail() {
AsynchronousMailMessage message = asyncMailService.sendMail {
// Mail parameters
to appointmentDetails.emailAddress
from AppConstant.EMAIL_SENDER
subject emailSubject
html emailMessage
}
}
SMTP details are stored in application.groovy.
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "XXXXXXXXXXXX#gmail.com"
password = "XXXXXXXXX"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
So this was working fine. Now our team wants to use SendGrid for achieve sending mails. I have got the API key, Key Name and other details from SendGrid Team and also have whitelisted my IP in sendGrid configuration. How can i implement that?
Have added below config in application.yml
sendgrid:
api: '${SENDGRID_APIKEY}'
from: '${SENDGRID_FROM_EMAIL}'

How to create SendBird user with SendBird Platform API and Request node library

We are building a react-native chat app. We are implementing a back end authentication solution on google Firebase. The creation of a new user in Firebase Auth triggers a cloud function which should create a new SendBird user with an access token. The access token will be stored in Cloud Firestore, ready for retrieval the next time the user logs in.
We are having trouble implementing the POST request that creates the new user via the platform API. We are using the Request library for node.js. We are able to reach the API endpoint, but the following object is returned: { message: 'SendBird API Endpoint.', error: true }. There is no indication of what the error may be.
This happens when sending the request to the base url. When we send the request to /users or /v3/users, we receive a 403 error.
Any indication as to what may be causing this problem would be greatly appreciated.
Below is the cloud function index.js code
const functions = require('firebase-functions');
const admin = require("firebase-admin");
const request = require('request');
admin.initializeApp();
exports.handleNewUser = functions.auth.user().onCreate((user) => {
var newUserRequestBody = {
"user_id": user.email,
"nickname": user.email,
"profile_url": "",
"issue_access_token": true,
}
request.post({
headers: {
'Content-Type': 'application/json, charset=utf8',
'Api-Token': // API Token
},
url: 'https://api-{application_id}.sendbird.com',
form: newUserRequestBody
}, function(error, response, body){
if (!error && response.statusCode === 200) {
const info = JSON.parse(body);
console.log("request successful");
console.log(response.statusCode);
console.log(info);
}
else{
console.log("request unsuccessful");
console.log(response.statusCode);
console.log(error);
}
});
return null;
});
Did you try with full path of end point to url: (including /v3/users)?
Or you may need to use "baseUrl" like below?
https://github.com/request/request#requestoptions-callback
Also, you need to make sure that you correctly used {application_id} value and {API Token} value.
You can double check this from your dashboard of SendBird.
http://dashboard.sendbird.com > Log in with your ID > select your APP.
There is a section named "App credentials" in "Overview" menu.
You can double check your API-request URL and API-Token value from there.

Nodemailer OAUTH Gmail connection (Error: connect ETIMEDOUT 74.125.140.108:465)

Im trying to use OAUTH 2.0 to send emails with Gmail API using Nodemailer
I have Enable the Gmail API and i have clientId, clientSecret, refreshToken and accessToken (refreshtoken and accesstoken were taken from developers.google.com/oauthplayground) because these all were needed for OAUTH to work.
i have followed every detail form (https://nodemailer.com/smtp/oauth2/#examples)
But i'm getting following error
{ Error: connect ETIMEDOUT 74.125.140.108:465
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
errno: 'ETIMEDOUT',
code: 'ESOCKET',
syscall: 'connect',
address: '74.125.140.108',
port: 465,
command: 'CONN' }
But there is a catch when i use Plain username and password there is no connection timeout error because i have already enabled less secure app access form (https://myaccount.google.com/lesssecureapps) so there is no error in sending emails using plain username and password but this is not a good approach so OAUTH is the solution
here is my code for you to check (its an express app) running in development running on http://localhost:3000
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
service: 'gmail',
auth: {
type: 'OAuth2',
user: 'mygmailaddress#gmail.com',
clientId: 'clientID',
clientSecret: 'clientSecret',
refreshToken: 'refresh token obtained from https://developers.google.com/oauthplayground',
accessToken: 'access token also obtained from https://developers.google.com/oauthplayground'
}
});
var mailOptions = {
from: 'me <myemailaddress#gmail.com>',
to: '',
subject: 'Subject ',
text: 'Some thing',
};
transporter.sendMail(mailOptions, (error, response) => {
if(error){
console.log(error); // Always giving Error: connect ETIMEDOUT 74.125.140.108:465
} else {
console.log(response);
}
});
it not even try to login because when login fails it gives error of wrong credentials (checked with plain username and password)
*Note please don't mark this question as duplicate because i have check almost all other question and answers but nothing worked
some people said its because of firewall setting i have check that too but didn't worked
So whats the issue and how to solve it
Your port no is wrong for gmail. Use This Format for gmail
const nodeMailer = require('nodemailer');
let transporter = nodeMailer.createTransport({
host: "smtp.gmail.com",
port: 587,
secure: false, // true for 587, false for other ports
requireTLS: true,
auth: {
user: your email,
pass: your password,
},
});
let mailOptions = {
from: 'from#gmail.com',
to: 'to#gmail.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
After looking to your problem i assume that when generated the OAuth credentials e.g(clienId and Clientsecret ) you did not added https://mail.google.com/ in you scope on connect screen because you would need verification form google to add these scope for the credentials
you must have added this to your scope on (https://developers.google.com/oauthplayground) but i'm sure you have add this to your scope on consent screen as well before generating credentials
OAuth consent screen
as you are in Development mode and running your application on localhost so you don't have private domain and privacy policy
Adding https://mail.google.com to your scope before generating clientId and Cliensecret will resolve your problem

Firebase Admin Create User Programmatically? [duplicate]

I am working on a angularfire project and I would like to know how can I create an user in Firebase 3 and once done, do not authenticate the specified user. In the previous Firebase version we had the method called createUser(email, password). Now we have the method createUserWithEmailAndPassword(email, password) only, it creates and authenticates the specified user.
The answer to the question is: you can't.
We have similar situation where we have 'admin' users that can create other users. With 2.x this was a snap. With 3.x it's a fail as that capability was completely removed.
If you create a user in 3.x you authenticate as that user, and unauthenticate the account that's logged in.
This goes deeper as you would then need to re-authenticate to create another user; so the admin either does that manually or (cringe) stores the authentication data locally so it could be an automated process (cringe cringe, please don't do this)
Firebase has publicly stressed that 2.x will continue to be supported so you may just want to avoid 3.x.
Update:
one of the Firebaser's actually came up with a workaround on this. Conceptually you had an admin user logged in. You then create a second connection to firebase and authenticate with another user, that connection then creates the new user. Rinse - repeat.
Update again
See this question and answer
Firebase kicks out current user
You can do this using cloud function and firebase admin SDK.
Create HTTP function like below.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions
exports.createUser = functions.https.onRequest((request, response) => {
if (request.method !== "POST") {
response.status(405).send("Method Not Allowed");
} else {
let body = request.body;
const email = body.email;
const password = body.password;
const displayName = body.displayName;
admin.auth().createUser({
email: email,
emailVerified: false,
password: password,
displayName: displayName,
disabled: false
})
.then((userRecord) => {
return response.status(200).send("Successfully created new user: " +userRecord.uid);
})
.catch((error) => {
return response.status(400).send("Failed to create user: " + error);
});
}
});
In your client app, call this function using Http request, for example using ajax
$.ajax({
url: "the url generated by cloud function",
type: "POST",
data: {
email: email,
password: password,
displayName: name
},
success: function(response) {
console.log(response);
},
error: function(xhr, status, error) {
let err = JSON.parse(xhr.responseText);
console.log(err.Message);
}
});

Authentication failure when using mail Grails plugin

i'm using Grails 2.5.1 and mail:1.0.7 plugin to send emails , but when i'm using it i always getting the bellow error :
Class:javax.mail.AuthenticationFailedExceptionMessage:535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/answer/14257 qq4sm4579366wjc.14 - gsmtp
although i can login with the provided credentials successfully from the browser !!
here are my configurations in the Config file :
grails {
mail {
host = "smtp.gmail.com"
port =465
username = "****"
password = "***"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
and here is the action :
mailService.sendMail{
to userInstance.toEmail
subject userInstance.subject
html "<strong>Test</strong> "
}
anything i'm missing ?
It may be because of gmail's security feature for less secure apps to get authenticated. Just turn on the access for less secure apps.
Follow below steps:
1 Login to your gmail account
2 Access the url:
https://www.google.com/settings/security/lesssecureapps
3 Select "Turn on"
If you have gmail - settings for plugin are correct (i have the same and they are working) , but if your email is not gmail you must have other config.
By the way if you gmail :
Username and Password not accepted.
your username or password is wrong, try to login with this Username and password, watch out for register of letters.
https://grails.org/plugin/mail

Resources