我收到无效令牌提供错误。我创建了新的令牌和邮递员,我能够创建用户但是使用ajax调用我无法创建user.Here是示例代码。
var express = require('express');
var bodyParser = require('body-parser');
var nodemailer = require('nodemailer');
var request = require('request');
var cookieParser = require('cookie-parser')
var port = process.env.port || 9002;
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cookieParser());
var router = express.Router();
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
next();
});
router.post('/createUser', function(req, res) {
var oktaUserCreationData = {
"profile": {
"firstName": req.body.profile.firstName,
"lastName": req.body.profile.lastName,
"email": req.body.profile.email,
"login": req.body.profile.webId + '~' + req.body.profile.email
}
};
var usderData = JSON.stringify(oktaUserCreationData);
request({
url: "https://dev-58043.oktapreview.com/api/v1/users?activate=false",
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'SSWS {{apiKey}}
},
json: true, // <--Very important!!!
body: usderData
}, function(error, response, body) {
console.log(response);
ActivatedUser(response.body.id);
res.json({ "message": "Please check your mail and follow steps, to set your credential." })
});
});
app.use('/api', router);
app.listen(port, function() {
console.log('Example app listening on port 9002!')
});
在这里,我使用自己的api密钥,这是密码,所以用{{apiKey}}
替换答案 0 :(得分:0)
您似乎错过了
的结束语'Authorization': 'SSWS {{apiKey}}
此外,我希望您已在代码中用您的api令牌替换SSWS {{apiKey}}。 SSWS {{apiKey}}只能在邮递员中工作,您可能知道。