@agilesoft/ags_authrest2 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +109 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1 +1,109 @@
1
- This version has been deprecated
1
+ # ags_authrest
2
+
3
+ **packages library**
4
+ ** For **flutter** auth client https://pub.dev/packages/ags_authrest2
5
+ ---
6
+
7
+ const express = require("express");
8
+
9
+ const bodyParser = require("body-parser");
10
+
11
+ const app = express();
12
+
13
+ app.use(bodyParser.json());
14
+
15
+ app.use(bodyParser.urlencoded({ extended: true }));
16
+
17
+ //เรียกใช้งาน
18
+
19
+ **const ags_restauth = require("ags_authrest");**
20
+
21
+ **const Auth = new ags_restauth();**
22
+
23
+ //.env
24
+
25
+ **process.env.SECERT_JWT = "ihavealongpassword";** //ใช้secert ที่มีความปลอดภัยสูง
26
+
27
+ //เปิดใช้ request เพื่อทดสอบ
28
+
29
+ // process.env.R_USER = "karan"
30
+
31
+ // process.env.R_PASS = "123456"
32
+
33
+ //app.use(Auth.RequestToken)
34
+
35
+ //ตัวอย่าง midleware ที่มีการ protect
36
+
37
+ app.post("/jwtauth", Auth.Middleware, (req, res, next) => {
38
+
39
+ return res.send(true);
40
+
41
+ });
42
+
43
+ const port = process.env.PORT || 3999;
44
+
45
+ app.listen(port, () => console.log("Server is listening on port ${port}."));
46
+
47
+ **//สำหรับเรียกใช้ token**
48
+
49
+ (async () => {
50
+
51
+ console.log(await Auth.GenToken(process.env.SECERT_JWT, process.env.R_USER));
52
+
53
+ })();
54
+
55
+ **//Client Use**
56
+
57
+ (async () => {
58
+
59
+ var bodyData = {
60
+
61
+ phone: "+66885257777",
62
+
63
+ otpCode: "778747",
64
+
65
+ refCode: "orxh4f",
66
+
67
+ fromBU: "Qsms",
68
+
69
+ };
70
+
71
+ var options = {
72
+
73
+ method: "POST",
74
+
75
+ url: "http://localhost:3999/",
76
+
77
+ headers: {
78
+
79
+ Authorization: await Auth.genTokenEncryp(),
80
+
81
+ "Content-Type": "application/json",
82
+
83
+ },
84
+
85
+ body: JSON.stringify(await Auth.encrypbody(bodyData)),
86
+
87
+ };
88
+
89
+ request(options, function (error, response) {
90
+
91
+ if (error) throw new Error(error);
92
+
93
+ console.log(JSON.parse(response.body));
94
+
95
+ });
96
+
97
+ })();
98
+
99
+
100
+ **//Exlample .env**
101
+ SECERT_JWT=ihavealongpassword
102
+
103
+ R_USER=karantest
104
+
105
+ R_PASS=123456
106
+
107
+ R_PATH=gentoken
108
+
109
+ TZ=Europe/London
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agilesoft/ags_authrest2",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "This version has been deprecated",
5
5
  "main": "index.js",
6
6
  "scripts": {