@agilesoft/ags_authrest2 v1.0.4
ags_authrest
packages library
For flutter** auth client https://pub.dev/packages/ags_authrest2
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
//เรียกใช้งาน
const ags_restauth = require("ags_authrest");
const Auth = new ags_restauth();
//.env
process.env.SECERT_JWT = "ihavealongpassword"; //ใช้secert ที่มีความปลอดภัยสูง
//เปิดใช้ request เพื่อทดสอบ
// process.env.R_USER = "karan"
// process.env.R_PASS = "123456"
//app.use(Auth.RequestToken)
//ตัวอย่าง midleware ที่มีการ protect
app.post("/jwtauth", Auth.Middleware, (req, res, next) => {
return res.send(true);
});
const port = process.env.PORT || 3999;
app.listen(port, () => console.log("Server is listening on port ${port}."));
//สำหรับเรียกใช้ token
(async () => {
console.log(await Auth.GenToken(process.env.SECERT_JWT, process.env.R_USER));
})();
//Client Use
(async () => {
var bodyData = {
phone: "+66885257777",
otpCode: "778747",
refCode: "orxh4f",
fromBU: "Qsms",
};
var options = {
method: "POST",
url: "http://localhost:3999/",
headers: {
Authorization: await Auth.genTokenEncryp(),
"Content-Type": "application/json",
},
body: JSON.stringify(await Auth.encrypbody(bodyData)),
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(JSON.parse(response.body));
});
})();
//Exlample .env SECERT_JWT=ihavealongpassword
R_USER=karantest
R_PASS=123456
R_PATH=gentoken
TZ=Europe/London