node.js - 401 Error with post request Stormpath Express + React + Node + Gulp -


when attempting login user, following post error results:

xmlhttprequest cannot load https://api.stormpath.com/v1/applications/[app_href]/login. no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:8080' therefore not allowed access. response had http status code 401. 

in server.js file, have put following:

var express = require('express'); var stormpath = require('express-stormpath');  var cors = require('cors');  var app = express();  app.use(stormpath.init(app, {    apikey: {     id: 'xyz',     secret: 'abc'  // using unsafe inline option example purposes   },   application: {     href: `[app_href]`   },   web: {     produces: ['application/json']   },   debug: 'info' }));  app.use(cors({   origin: 'http://localhost:8080',   credentials: true }));  app.post('/', stormpath.loginrequired, function (req, res) {   function writeerror(message) {     res.status(400);     res.json({ message: message, status: 400 });     res.end();   }    });  app.on('stormpath.ready', function () {   var server = app.listen(process.env.port, function() {     try {       process.send('connected');     } catch(e) {}   }); }); 

in login.jsx file, have included:

login: function(e) {       e.preventdefault();       e.stoppropagation();         this.serverrequest = $.post('https://api.stormpath.com/v1/applications/[app_href]/login',          {          "username": document.getelementbyid("email").value,         "password": document.getelementbyid("pass").value         }, function (result) {         console.log(result);        }); 

i have saved stormpath.yml file.

i'm not using react-stormpath because created views login , registering. looks need access rest api stormpath, i'm not sure need add in order api key validated.

on actual login.jsx file, have send id:secret pair part of post request?

i see in login.jsx trying post directly stormpath rest api, unfortunately isn't possible yet. instead make post express server, , in turn communicate stormpath.

you have express-stormpath in express server, need post login form /login , stormpath take care of rest :)

let know if run issues! fyi, adding "serverless" feature soon, can follow here: http://ideas.stormpath.com/ideas/iam-i-59


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -