Parse Server Simple Mailgun Adapter 'verifyUserEmails' issue - heroku

I am using the Parse Server Simple Mailgun Adapter, and my Parse Server is working perfectly on Heroku. I am new to node.js and Express, but I installed the adapter on the root of the Parse Server via:
npm i parse-server-simple-mailgun-adapter
This created a node_modules folder and essentially cloned the Github repository for the Mailgun Adapter. My index.js Parse Server configuration looks like:
var api = new ParseServer({
verifyUserEmails: true,
databaseURI: databaseUri || 'mongodb://DATABASE',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'APPID',
masterKey: process.env.MASTER_KEY || 'MASTERKEY', //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'https://SERVER/parse', // Don't forget to change to https if needed
publicServerURL: 'https://SERVER/parse',
fileKey: process.env.FILE_KEY || 'FILEKEY',
push: {
ios: [
{
pfx: 'FILE.p12', // Dev PFX or P12
bundleId: 'BUNDLE',
production: false // Dev
},
{
pfx: 'FILE.p12', // Prod PFX or P12
bundleId: 'BUNDLE',
production: true // Prod
}
]
},
emailAdapter: {
module: 'parse-server-simple-mailgun-adapter',
options: {
fromAddress: 'EMAIL#DOMAIN',
domain: 'DOMAIN',
apiKey: 'KEY',
}
},
liveQuery: {
classNames: ["Posts", "Comments"] // List of classes to support for query subscriptions
}
});
The server works perfectly when commenting out the verifyUserEmails key. With it, the server will not work. The Mailgun adapter does not work regardless. Any help would be greatly appreciated. Thanks!

Did you set up the email adapter?
Take a look at : https://github.com/ParsePlatform/parse-server
Email verification and password reset
Verifying user email addresses and enabling password reset via email requries an email adapter. As part of the parse-server package we provide an adapter for sending email through Mailgun. To use it, sign up for Mailgun, and add this to your initialization code:
var server = ParseServer({
...otherOptions,
// Enable email verification
verifyUserEmails: true,
// The public URL of your app.
// This will appear in the link that is used to verify email addresses and reset passwords.
// Set the mount path as it is in serverURL
publicServerURL: 'https://example.com/parse',
// Your apps name. This will appear in the subject and body of the emails that are sent.
appName: 'Parse App',
// The email adapter
emailAdapter: {
module: 'parse-server-simple-mailgun-adapter',
options: {
// The address that your emails come from
fromAddress: 'parse#example.com',
// Your domain from mailgun.com
domain: 'example.com',
// Your API key from mailgun.com
apiKey: 'key-mykey',
}
}
});
You can also use other email adapters contributed by the community such as parse-server-sendgrid-adapter or parse-server-mandrill-adapter.
OR
Create your own in cloud code using mailgun-js
https://www.npmjs.com/package/mailgun-js
var api_key = '[SECRET_API_KEY]';
var domain = '[DOMAIN_HERE]';
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
Parse.Cloud.define('testemail', function(req, res) {
var data = {
from: 'Excited User <me#samples.mailgun.org>',
to: 'foo#bar.com',
subject: 'Hello',
text: 'Testing some Mailgun awesomness!'
};
mailgun.messages().send(data, function (error, body) {
console.log(body);
});
res.success('Email Sent!');
});

The real reason why this happens is because you need to include the appName in your server initialization (this drove me crazy for hours)
appName: 'yourAppName',

Related

sveltekit/vite problem with self signed certificate on localhost

In my dev environment I'm using the basicSsl-Plugin for generating a self-signed-certificate. The website works fine under https until the fetch function is trying to delete a user.
my vite.config.js:
plugins: [
basicSsl(),
sveltekit(),
{
name: 'sveltekit-socket-io',
configureServer(server) {
const io = new Server(server.httpServer);
io.on('connection', (socket) => {
const agent = new https.Agent({
rejectUnauthorized: false
});
socket.on('disconnect', () => {
await fetch('https://localhost:5173/api/users', {
method: 'DELETE',
body: JSON.stringify({ id: socket.uid }),
agent: agent
});
});
});
i get the error Error: self-signed certificate and code DEPTH_ZERO_SELF_SIGNED_CERT.
when instead of using the basicSsl-Plugin I try using using mkcert-created self signed certificates I cant even access the website anymore with https because I get the following error in the browser: ERR_SSL_VERSION_OR_CIPHER_MISMATCH.
I added process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; and now it seems to work. I guess it's fine for development purposes, don't use it on production.

FCM push notification with parse server

I need to add FCM push in parse server setting. Please help me.
However when sending from parse. There is some issue between parse server and FCM then.
Here is my index.js, sample code:
var express = require("express");
var ParseServer = require("/usr/lib/node_modules/parse-server").ParseServer;
var ParseDashboard = require("/usr/lib/node_modules/parse-dashboard");
var allowInsecureHTTP = true;
var api = new ParseServer({
databaseURI: "mongodb://127.0.0.1:27017/****",
appId: "****",
masterKey: "****",
serverURL: "http://**.**.**.**:1234/parse",
push: {
ios: {
pfx: "/usr/lib/node_modules/push_crt.p12",
passphrase: "example",
bundleId: "com.example",
production: true
},
android: {
senderId: "123456",
apiKey: "******"
}
}
});
var dashboard = new ParseDashboard(
{
apps: [
{
serverURL: "http://**.**.**.**:1234/parse",
appId: "******",
masterKey: "******",
appName: "MyApp"
}
],
users: [{ user: "admin", pass: "admin" }]
},
allowInsecureHTTP
);
var app = express();
// make the Parse Server available at /parse
app.use("/parse", api);
// make the Parse Dashboard available at /dashboard
app.use("/dashboard", dashboard);
var httpServer = require("http").createServer(app);
httpServer.listen(1234);
Please check and help me. How to add FCM connection inside parse server.
For the ios configuration, I can see 2 errors:
pfx path is probably wrong and that wont work on a server cause its not relative (ie. thats specific to your local computer). Save the file in a "certs" (or whatever you wanna call it) folder where you got the nodejs code. Then update with pfx: __dirname + '/certs/push_crt.p12'
bundleId is not the right key, this should be updated to topic: 'com.example'
For the android config, im not sure what senderId is for, maybe you should get rid of that, unless you are sure you need it.

In Bot Framework Web Chat, how do I connect to my bot server?

All the tutorial are connecting to direct line, what about using my own bot server? How do I connect in javascript?
I already setup server side:
// Setup BotFramework
var connector = new Builder.ChatConnector({
appId: "a8...",
appPassword: "ko...",
openIdMetadata: process.env.BotOpenIdMetadata
});
// Setup Bot
var bot = new Builder.UniversalBot(connector);
bot.set('storage', new Builder.MemoryBotStorage());
// Setup Server
var server = Restify.createServer();
server.listen(process.env.port || process.env.PORT || 4000, function () {
console.log("Listening on port "+(process.env.port || process.env.PORT || 4000));
});
server.post('/api/messages', connector.listen());
On the client side, here is what I currently got using direct line:
<script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
<script src="https://cdn.botframework.com/botframework-webchat/latest/CognitiveServices.js"></script>
<script>
const params = BotChat.queryParams(location.search);
const speechOptions = {
speechRecognizer: new BotChat.Speech.BrowserSpeechRecognizer(),
speechSynthesizer: new BotChat.Speech.BrowserSpeechSynthesizer()
};
BotChat.App({
showUploadButton: false,
directLine: { secret: '_bm...' },
bot: { id: 'a8...' },
locale: params['locale'],
resize: 'detect',
speechOptions: speechOptions,
user: {
id: 'WebChatDemoUser',
name: 'You'
},
}, document.getElementById('ChatBot'));
var header = document.getElementsByClassName("wc-header");
header[0].innerHTML = "<span>Chat</span>"
</script>
So this work, but it connect directly to the bot framework, I need to connect to my server like this:
http://localhost:4000/api/messages
Or on production would be like this:
http://myserver.com:4000/api/messages
Basically, similar to how Bot Emulator connect:
DirectLineJs will call the Direct Line Connector Service by default. The connector service then calls your bot, and the bot calls back to the connector service with responses (or proactive messages). DirectLineJs does provide a domain parameter you can supply to override the default:
const dl = new DirectLine({
secret: /* put your Direct Line secret here */,
token: /* or put your Direct Line token here (supply secret OR token, not both) */,
domain: /* optional: if you are not using the default Direct Line endpoint, e.g. if you are using a region-specific endpoint, put its full URL here */
webSocket: /* optional: false if you want to use polling GET to receive messages. Defaults to true (use WebSocket). */,
pollingInterval: /* optional: set polling interval in milliseconds. Default to 1000 */,
});
However, there is a lot more involved in hosting your own Direct Line Connector Service. The SDK code will use the activity's serviceUrl property to send messages back to the connector service. The bot is expecting endpoints such as those in this MockChannelController: https://github.com/Microsoft/BotFramework-Samples/blob/master/blog-samples/CSharp/MockChannel/Controllers/MockChannelController.cs
More details are explained in this Load Testing blog post: https://blog.botframework.com/2017/06/19/load-testing-a-bot/
There's also this limited node example: offline-directline

parse reset password hyper link issue

I had implemented Parse Server(use parse-server-example) reset password via mailgun-adapter, the config like below:
var api = new ParseServer({
....
verifyUserEmails: true,
emailVerifyTokenValidityDuration: 2 * 60 * 60,
preventLoginWithUnverifiedEmail: false,
publicServerURL: 'http://my.domain.com',
appName: 'MyApp',
emailAdapter: {
module: 'parse-server-mailgun-adapter-template',
options: {
fromAddress: 'no-reply#mydomain.com',
domain: 'domain.mailgun',
apiKey: 'key-FromMailGun'
}
},
....
});
After send reset password via my App, I will receive the mail like:
Hi,
You requested a password reset for MyApp.
Click here to reset it:
http://my.domain.com/apps/appid/request_password_reset?token=tokenid&username=username
But, I click the link that attached in mail. the web display
Cannot GET /apps/appid/request_password_reset?token=token&username=username.
Therefore, I have to implement my app.get(/request_password_reset) function by myself? or can use Parse Server default html and forms?
I have read through your index.js and i think the issue is being your publicServerURL. Make sure you are using the same URL as your serverURL.
http://192.168.200.45:1111/parse

Parse server password reset with Mailgun issue

I'm trying to get the parse-server password reset functionality working, but no success so far. This is my setup:
var api = new ParseServer({
databaseURI: process.env.DATABASE_URI || process.env.MONGOLAB_IVORY_URI,
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'APP_NAME',
clientKey: process.env.CLIENT_KEY || 'xxxx',
masterKey: process.env.MASTER_KEY || '',
serverURL: process.env.SERVER_URL || 'https://APP.herokuapp.com/parse',
appName : 'APP_NAME',
verifyUserEmails: true,
publicServerURL: 'https://APP.herokuapp.com/parse',
emailAdapter: {
module: 'parse-server-simple-mailgun-adapter',
options: {
fromAddress: 'From Name <from#email.com>',
domain: 'https://api.mailgun.net/v3/***MY_DOMAIN***/messages',
apiKey: 'key-xxxxxxxxxx',
}
}
});
The iOS Parse SDK simply says the email is succesfully sent, but nothing arrives. Also the Mailgun logs show no sign of activity. I have tested this Mailgun setup with curl and that worked just fine.
I tried both https://api.mailgun.net/v3/MY_DOMAIN/messages and https://api.mailgun.net/v3/MY_DOMAIN
Any clue what's wrong with my setup?
Or how I can troubleshoot this remotely running Parse setup?
Ok I managed to solve it after hours of digging.
As it turns out the parse-simple-mailgun-adapter does not handle invalid Mailgun URLs.
Instead of providing https://api.mailgun.net/v3/MY_DOMAIN, I should have provided just MY_DOMAIN. Appearantly the adapter will construct the url.

Resources