File tree Expand file tree Collapse file tree 4 files changed +472
-0
lines changed Expand file tree Collapse file tree 4 files changed +472
-0
lines changed Original file line number Diff line number Diff line change @@ -32,3 +32,134 @@ override.tf.json
32
32
# Ignore CLI configuration files
33
33
.terraformrc
34
34
terraform.rc
35
+
36
+ # Logs
37
+ logs
38
+ * .log
39
+ npm-debug.log *
40
+ yarn-debug.log *
41
+ yarn-error.log *
42
+ lerna-debug.log *
43
+ .pnpm-debug.log *
44
+
45
+ # Diagnostic reports (https://nodejs.org/api/report.html)
46
+ report. [0-9 ]* . [0-9 ]* . [0-9 ]* . [0-9 ]* .json
47
+
48
+ # Runtime data
49
+ pids
50
+ * .pid
51
+ * .seed
52
+ * .pid.lock
53
+
54
+ # Directory for instrumented libs generated by jscoverage/JSCover
55
+ lib-cov
56
+
57
+ # Coverage directory used by tools like istanbul
58
+ coverage
59
+ * .lcov
60
+
61
+ # nyc test coverage
62
+ .nyc_output
63
+
64
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
65
+ .grunt
66
+
67
+ # Bower dependency directory (https://bower.io/)
68
+ bower_components
69
+
70
+ # node-waf configuration
71
+ .lock-wscript
72
+
73
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
74
+ build /Release
75
+
76
+ # Dependency directories
77
+ node_modules /
78
+ jspm_packages /
79
+
80
+ # Snowpack dependency directory (https://snowpack.dev/)
81
+ web_modules /
82
+
83
+ # TypeScript cache
84
+ * .tsbuildinfo
85
+
86
+ # Optional npm cache directory
87
+ .npm
88
+
89
+ # Optional eslint cache
90
+ .eslintcache
91
+
92
+ # Optional stylelint cache
93
+ .stylelintcache
94
+
95
+ # Microbundle cache
96
+ .rpt2_cache /
97
+ .rts2_cache_cjs /
98
+ .rts2_cache_es /
99
+ .rts2_cache_umd /
100
+
101
+ # Optional REPL history
102
+ .node_repl_history
103
+
104
+ # Output of 'npm pack'
105
+ * .tgz
106
+
107
+ # Yarn Integrity file
108
+ .yarn-integrity
109
+
110
+ # dotenv environment variable files
111
+ .env
112
+ .env.development.local
113
+ .env.test.local
114
+ .env.production.local
115
+ .env.local
116
+
117
+ # parcel-bundler cache (https://parceljs.org/)
118
+ .cache
119
+ .parcel-cache
120
+
121
+ # Next.js build output
122
+ .next
123
+ out
124
+
125
+ # Nuxt.js build / generate output
126
+ .nuxt
127
+ dist
128
+
129
+ # Gatsby files
130
+ .cache /
131
+ # Comment in the public line in if your project uses Gatsby and not Next.js
132
+ # https://nextjs.org/blog/next-9-1#public-directory-support
133
+ # public
134
+
135
+ # vuepress build output
136
+ .vuepress /dist
137
+
138
+ # vuepress v2.x temp and cache directory
139
+ .temp
140
+ .cache
141
+
142
+ # Docusaurus cache and generated files
143
+ .docusaurus
144
+
145
+ # Serverless directories
146
+ .serverless /
147
+
148
+ # FuseBox cache
149
+ .fusebox /
150
+
151
+ # DynamoDB Local files
152
+ .dynamodb /
153
+
154
+ # TernJS port file
155
+ .tern-port
156
+
157
+ # Stores VSCode versions used for testing VSCode extensions
158
+ .vscode-test
159
+
160
+ # yarn v2
161
+ .yarn /cache
162
+ .yarn /unplugged
163
+ .yarn /build-state.yml
164
+ .yarn /install-state.gz
165
+ .pnp. *
Original file line number Diff line number Diff line change
1
+ const jwt = require ( "jsonwebtoken" ) ;
2
+
3
+ // Constants.
4
+ const JWT_PRIVATE_KEY = process . env . JWT_PRIVATE_KEY ;
5
+ const JWT_EXPIRATION_TIME = "1h" ;
6
+
7
+ exports . handler = async ( event ) => {
8
+ try {
9
+ // Gets event body.
10
+ const body =
11
+ typeof event . body === "string" ? JSON . parse ( event . body ) : event . body ;
12
+
13
+ // Client will be identified by national id.
14
+ const nationalId = body . nationalId ;
15
+
16
+ if ( ! nationalId ) {
17
+ return {
18
+ statusCode : 400 ,
19
+ } ;
20
+ }
21
+ } catch ( error ) {
22
+ return {
23
+ statusCode : 400 ,
24
+ } ;
25
+ }
26
+
27
+ ////////////////////////////////////////////////////////////////////////
28
+
29
+ // TODO gets client by national id, creates it if no national id matches.
30
+
31
+ ////////////////////////////////////////////////////////////////////////
32
+
33
+ // TODO pass client id to 'sub' instead of using this '1111111111' hardcoded value.
34
+ // Object that stores values used by 'jsonwebtoken - sign' function call.
35
+ // Sub represents the client ID.
36
+ const jwtSettings = {
37
+ privateKey : JWT_PRIVATE_KEY ,
38
+ payload : {
39
+ sub : 1111111111 ,
40
+ } ,
41
+ options : {
42
+ expiresIn : JWT_EXPIRATION_TIME ,
43
+ algorithm : "RS256" ,
44
+ } ,
45
+ } ;
46
+
47
+ try {
48
+ const token = jwt . sign (
49
+ jwtSettings . payload ,
50
+ jwtSettings . privateKey ,
51
+ jwtSettings . options
52
+ ) ;
53
+
54
+ return {
55
+ headers : { "content-type" : "application/json" } ,
56
+ statusCode : 200 ,
57
+ body : JSON . stringify ( { token } ) ,
58
+ } ;
59
+ } catch ( error ) {
60
+ return {
61
+ statusCode : 500 ,
62
+ body : "asd " + error ,
63
+ } ;
64
+ }
65
+ } ;
You can’t perform that action at this time.
0 commit comments