전자 기반 데스크톱 응용 프로그램 용 NodeJS API 시스템을 만들려고합니다. 앱에서 사용자 이름과 비밀번호를 사용하여 기본 로그인을 허용해야하며, 사용자가 로그인하면 모든 후속 API 호출이 ID와 비밀 키를 통해 인증됩니다. 나는 this guide on using express-strompath description here을 참조하고있다. 이런 사용자 이름/비밀번호 인증을 수행 할 수 없습니다. 기본 사용자 이름 : 암호 인증으로 Stormpath-express 로그인이 작동하지 않습니다.
curl -L -H "Content-Type: application/json" -X POST -d '{"password":"Som3Pa55Word", "username":"[email protected]"}' http://ec2-54-88-168-7.compute-1.amazonaws.com:8000/api/v1.0/login
아니면 사용자 API 키, 내가 로그인 할 수 있어요 그러나 자바 스크립트
function Login() {
...
var user = {
username: '[email protected]',
password: 'Som3Pa55Word ',
}
var req = {
method: 'POST',
url: apiBaseUrl + '/login',
headers: {
'Content-Type': 'application/json'
},
data: user
}
return $http(req).then(handleSuccess, handleError);
}
를 통해
.curl -L -H "Content-Type: application/json" -X POST --user ABCDEFGHIJKLMNOPQRSTUVWXYZ:AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz -d '{}' http://ec2-54-88-168-7.compute-1.amazonaws.com:8000/api/v1.0/login
또는 자바 스크립트
를 통해 var url = apiBaseUrl + '/login';
var sp_api_key_id = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var sp_api_key_secret ='AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz';
get the Resource object w/ custom "get" method
$resource(url, {}, {
get: {
method: 'GET',
headers: {
Authorization: 'Basic ' +
$base64.encode(sp_api_key_id + ':' + sp_api_key_secret)
}
}
}).get().then(function(result) {
console.log("Loging Success")
});
는 분명히 사용자가 인증을위한 형태로 자신의 API 키를 입력해야하는 불편. stormpath-express가 API ID/비밀 조합을 허용하지만 사용자 이름/비밀번호를 허용하지 않는 이유가 궁금합니다. 여기
내 nodejs 서버router.post('/login', stormpath.loginRequired, function (req, res, next) {
/*
* If we get here, the user is logged in. Otherwise, they
* were redirected to the login page
*/
var respnse = {
message: 'If you can see this page, you must be logged into your account!'
}
res.json(respnse);
res.status(200);
});
그리고 Stormpath 설정 코드 나에서 일
// Config
app.use(stormpath.init(app, {
// TODO
// apiKeyFile: './app/config/stormpath_apikey.properties',
application: 'https://api.stormpath.com/v1/applications/ABCDEFGHIJKLMNOPQRSTUVWXYZ',
secretKey: settings.stormpath_secret_key,
web: {
login: {
enabled: false
},
register: {
uri: '/user/register'
},
preLoginHandler: function (formData, req, res, next) {
console.log('Got login request', formData);
next();
}
},
postLoginHandler: function (account, req, res, next) {
console.log('User:', account.email, 'just logged in!');
next();
}
}));