@things-factory/auth-google 6.1.186

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 (67) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/assets/images/hatiolab-logo.png +0 -0
  3. package/client/bootstrap.ts +1 -0
  4. package/client/index.ts +0 -0
  5. package/client/route.ts +4 -0
  6. package/client/tsconfig.json +11 -0
  7. package/config/config.development.js +19 -0
  8. package/config/config.production.js +19 -0
  9. package/dist-client/bootstrap.d.ts +1 -0
  10. package/dist-client/bootstrap.js +2 -0
  11. package/dist-client/bootstrap.js.map +1 -0
  12. package/dist-client/index.d.ts +0 -0
  13. package/dist-client/index.js +2 -0
  14. package/dist-client/index.js.map +1 -0
  15. package/dist-client/route.d.ts +1 -0
  16. package/dist-client/route.js +5 -0
  17. package/dist-client/route.js.map +1 -0
  18. package/dist-client/tsconfig.tsbuildinfo +1 -0
  19. package/dist-server/controllers/get-access-token.js +30 -0
  20. package/dist-server/controllers/get-access-token.js.map +1 -0
  21. package/dist-server/controllers/subscribe-users-change.js +33 -0
  22. package/dist-server/controllers/subscribe-users-change.js.map +1 -0
  23. package/dist-server/controllers/sync-user-info.js +95 -0
  24. package/dist-server/controllers/sync-user-info.js.map +1 -0
  25. package/dist-server/index.js +19 -0
  26. package/dist-server/index.js.map +1 -0
  27. package/dist-server/middlewares/google-authenticate-middleware.js +62 -0
  28. package/dist-server/middlewares/google-authenticate-middleware.js.map +1 -0
  29. package/dist-server/middlewares/index.js +13 -0
  30. package/dist-server/middlewares/index.js.map +1 -0
  31. package/dist-server/router/auth-google-router.js +11 -0
  32. package/dist-server/router/auth-google-router.js.map +1 -0
  33. package/dist-server/router/auth-google-webhook-router.js +73 -0
  34. package/dist-server/router/auth-google-webhook-router.js.map +1 -0
  35. package/dist-server/router/index.js +6 -0
  36. package/dist-server/router/index.js.map +1 -0
  37. package/dist-server/routes.js +23 -0
  38. package/dist-server/routes.js.map +1 -0
  39. package/dist-server/service/auth-google/auth-google-mutation.js +32 -0
  40. package/dist-server/service/auth-google/auth-google-mutation.js.map +1 -0
  41. package/dist-server/service/auth-google/index.js +6 -0
  42. package/dist-server/service/auth-google/index.js.map +1 -0
  43. package/dist-server/service/index.js +19 -0
  44. package/dist-server/service/index.js.map +1 -0
  45. package/dist-server/tsconfig.tsbuildinfo +1 -0
  46. package/helps/auth-google/auth-google.md +160 -0
  47. package/package.json +38 -0
  48. package/server/controllers/get-access-token.ts +30 -0
  49. package/server/controllers/subscribe-users-change.ts +34 -0
  50. package/server/controllers/sync-user-info.ts +129 -0
  51. package/server/index.ts +18 -0
  52. package/server/middlewares/google-authenticate-middleware.ts +70 -0
  53. package/server/middlewares/index.ts +13 -0
  54. package/server/router/auth-google-router.ts +14 -0
  55. package/server/router/auth-google-webhook-router.ts +96 -0
  56. package/server/router/index.ts +2 -0
  57. package/server/routes.ts +28 -0
  58. package/server/service/auth-google/auth-google-mutation.ts +24 -0
  59. package/server/service/auth-google/index.ts +3 -0
  60. package/server/service/index.ts +19 -0
  61. package/server/tsconfig.json +10 -0
  62. package/things-factory.config.js +8 -0
  63. package/translations/en.json +1 -0
  64. package/translations/ja.json +1 -0
  65. package/translations/ko.json +1 -0
  66. package/translations/ms.json +1 -0
  67. package/translations/zh.json +1 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
+ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
+
8
+ <!-- ## [Unreleased] -->
Binary file
@@ -0,0 +1 @@
1
+ export default function bootstrap() {}
File without changes
@@ -0,0 +1,4 @@
1
+ export default function route(page: string) {
2
+ switch (page) {
3
+ }
4
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "strict": true,
5
+ "declaration": true,
6
+ "module": "esnext",
7
+ "outDir": "../dist-client",
8
+ "baseUrl": "./"
9
+ },
10
+ "include": ["./**/*"]
11
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * SSO configuration for Google
3
+ *
4
+ {
5
+ sso: {
6
+ google: {
7
+ title: 'Google',
8
+ link: '/auth/signin-with-google', // signin-link
9
+ config: {
10
+ clientID: 'YOUR_GOOGLE_CLIENT_ID',
11
+ clientSecret: 'YOUR_GOOGLE_CLIENT_SECRET',
12
+ callbackURL: 'http://localhost:3000/auth/callback-auth-google'
13
+ }
14
+ }
15
+ }
16
+ }
17
+ */
18
+
19
+ module.exports = {}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * SSO configuration for Google
3
+ *
4
+ {
5
+ sso: {
6
+ google: {
7
+ title: 'Google',
8
+ link: '/auth/signin-with-google', // signin-link
9
+ config: {
10
+ clientID: 'YOUR_GOOGLE_CLIENT_ID',
11
+ clientSecret: 'YOUR_GOOGLE_CLIENT_SECRET',
12
+ callbackURL: 'http://localhost:3000/auth/callback-auth-google'
13
+ }
14
+ }
15
+ }
16
+ }
17
+ */
18
+
19
+ module.exports = {}
@@ -0,0 +1 @@
1
+ export default function bootstrap(): void;
@@ -0,0 +1,2 @@
1
+ export default function bootstrap() { }
2
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../client/bootstrap.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,SAAS,KAAI,CAAC","sourcesContent":["export default function bootstrap() {}\n"]}
File without changes
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../client/index.ts"],"names":[],"mappings":"","sourcesContent":[""]}
@@ -0,0 +1 @@
1
+ export default function route(page: string): void;
@@ -0,0 +1,5 @@
1
+ export default function route(page) {
2
+ switch (page) {
3
+ }
4
+ }
5
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../client/route.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,IAAY;IACxC,QAAQ,IAAI,EAAE;KACb;AACH,CAAC","sourcesContent":["export default function route(page: string) {\n switch (page) {\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"program":{"fileNames":["../../../node_modules/lerna/node_modules/typescript/lib/lib.es5.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2016.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2017.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2018.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2019.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.dom.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.core.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2017.object.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2017.string.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2019.array.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2019.object.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2019.string.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.date.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.string.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.es2020.number.d.ts","../../../node_modules/lerna/node_modules/typescript/lib/lib.esnext.intl.d.ts","../../../node_modules/tslib/tslib.d.ts","../client/bootstrap.ts","../client/index.ts","../client/route.ts","../../../node_modules/@types/node/assert.d.ts","../../../node_modules/@types/node/assert/strict.d.ts","../../../node_modules/@types/node/globals.d.ts","../../../node_modules/@types/node/async_hooks.d.ts","../../../node_modules/@types/node/buffer.d.ts","../../../node_modules/@types/node/child_process.d.ts","../../../node_modules/@types/node/cluster.d.ts","../../../node_modules/@types/node/console.d.ts","../../../node_modules/@types/node/constants.d.ts","../../../node_modules/@types/node/crypto.d.ts","../../../node_modules/@types/node/dgram.d.ts","../../../node_modules/@types/node/diagnostics_channel.d.ts","../../../node_modules/@types/node/dns.d.ts","../../../node_modules/@types/node/dns/promises.d.ts","../../../node_modules/@types/node/domain.d.ts","../../../node_modules/@types/node/dom-events.d.ts","../../../node_modules/@types/node/events.d.ts","../../../node_modules/@types/node/fs.d.ts","../../../node_modules/@types/node/fs/promises.d.ts","../../../node_modules/@types/node/http.d.ts","../../../node_modules/@types/node/http2.d.ts","../../../node_modules/@types/node/https.d.ts","../../../node_modules/@types/node/inspector.d.ts","../../../node_modules/@types/node/module.d.ts","../../../node_modules/@types/node/net.d.ts","../../../node_modules/@types/node/os.d.ts","../../../node_modules/@types/node/path.d.ts","../../../node_modules/@types/node/perf_hooks.d.ts","../../../node_modules/@types/node/process.d.ts","../../../node_modules/@types/node/punycode.d.ts","../../../node_modules/@types/node/querystring.d.ts","../../../node_modules/@types/node/readline.d.ts","../../../node_modules/@types/node/readline/promises.d.ts","../../../node_modules/@types/node/repl.d.ts","../../../node_modules/@types/node/stream.d.ts","../../../node_modules/@types/node/stream/promises.d.ts","../../../node_modules/@types/node/stream/consumers.d.ts","../../../node_modules/@types/node/stream/web.d.ts","../../../node_modules/@types/node/string_decoder.d.ts","../../../node_modules/@types/node/test.d.ts","../../../node_modules/@types/node/timers.d.ts","../../../node_modules/@types/node/timers/promises.d.ts","../../../node_modules/@types/node/tls.d.ts","../../../node_modules/@types/node/trace_events.d.ts","../../../node_modules/@types/node/tty.d.ts","../../../node_modules/@types/node/url.d.ts","../../../node_modules/@types/node/util.d.ts","../../../node_modules/@types/node/v8.d.ts","../../../node_modules/@types/node/vm.d.ts","../../../node_modules/@types/node/wasi.d.ts","../../../node_modules/@types/node/worker_threads.d.ts","../../../node_modules/@types/node/zlib.d.ts","../../../node_modules/@types/node/globals.global.d.ts","../../../node_modules/@types/node/index.d.ts","../../../node_modules/@jest/expect-utils/build/index.d.ts","../../../node_modules/chalk/index.d.ts","../../../node_modules/@sinclair/typebox/typebox.d.ts","../../../node_modules/@jest/schemas/build/index.d.ts","../../../node_modules/pretty-format/build/index.d.ts","../../../node_modules/jest-diff/build/index.d.ts","../../../node_modules/jest-matcher-utils/build/index.d.ts","../../../node_modules/expect/build/index.d.ts","../../../node_modules/@types/jest/index.d.ts"],"fileInfos":[{"version":"8730f4bf322026ff5229336391a18bcaa1f94d4f82416c8b2f3954e2ccaae2ba","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","4b421cbfb3a38a27c279dec1e9112c3d1da296f77a1a85ddadf7e7a425d45d18","1fc5ab7a764205c68fa10d381b08417795fc73111d6dd16b5b1ed36badb743d9",{"version":"3aafcb693fe5b5c3bd277bd4c3a617b53db474fe498fc5df067c5603b1eebde7","affectsGlobalScope":true},{"version":"f3d4da15233e593eacb3965cde7960f3fddf5878528d882bcedd5cbaba0193c7","affectsGlobalScope":true},{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true},{"version":"8cc8c5a3bac513368b0157f3d8b31cfdcfe78b56d3724f30f80ed9715e404af8","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"5f406584aef28a331c36523df688ca3650288d14f39c5d2e555c95f0d2ff8f6f","affectsGlobalScope":true},{"version":"22f230e544b35349cfb3bd9110b6ef37b41c6d6c43c3314a31bd0d9652fcec72","affectsGlobalScope":true},{"version":"7ea0b55f6b315cf9ac2ad622b0a7813315bb6e97bf4bb3fbf8f8affbca7dc695","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"eb26de841c52236d8222f87e9e6a235332e0788af8c87a71e9e210314300410a","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"81cac4cbc92c0c839c70f8ffb94eb61e2d32dc1c3cf6d95844ca099463cf37ea","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"5e5e095c4470c8bab227dbbc61374878ecead104c74ab9960d3adcccfee23205","affectsGlobalScope":true},{"version":"09aa50414b80c023553090e2f53827f007a301bc34b0495bfb2c3c08ab9ad1eb","affectsGlobalScope":true},{"version":"d7f680a43f8cd12a6b6122c07c54ba40952b0c8aa140dcfcf32eb9e6cb028596","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"2768ef564cfc0689a1b76106c421a2909bdff0acbe87da010785adab80efdd5c","affectsGlobalScope":true},{"version":"b248e32ca52e8f5571390a4142558ae4f203ae2f94d5bac38a3084d529ef4e58","affectsGlobalScope":true},{"version":"52d1bb7ab7a3306fd0375c8bff560feed26ed676a5b0457fa8027b563aecb9a4","affectsGlobalScope":true},"7a1971efcba559ea9002ada4c4e3c925004fb67a755300d53b5edf9399354900",{"version":"1f8f1bd57f21c36cc25547a0cb99a097f5e5443815789833d230741315a3a948","signature":"aac4ddff3d5c1247433870879e9838b1e23b81a9b62c75f59c3e1b64802f2b16"},"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",{"version":"c0ae510b4743cf5f73102c35337e76cdf9b6340c9e6f117191422603d4387236","signature":"21583817860b17e4b3e44bb8f61dd5965baf7acf41f67bfbf5546e78bd58810c"},"09df3b4f1c937f02e7fee2836d4c4d7a63e66db70fd4d4e97126f4542cc21d9d","7394959e5a741b185456e1ef5d64599c36c60a323207450991e7a42e08911419",{"version":"32465ea19404cb188e84cf08c6b1f6b12d739140436402cdbc184a3fd20a7d81","affectsGlobalScope":true},"cce1f5f86974c1e916ec4a8cab6eec9aa8e31e8148845bf07fbaa8e1d97b1a2c",{"version":"62486c25ff70799e9faac5c6108820969617daeb6e65644c212d03cdb5902a3c","affectsGlobalScope":true},"546ab07e19116d935ad982e76a223275b53bff7771dab94f433b7ab04652936e","7b43160a49cf2c6082da0465876c4a0b164e160b81187caeb0a6ca7a281e85ba",{"version":"aefb5a4a209f756b580eb53ea771cca8aad411603926f307a5e5b8ec6b16dcf6","affectsGlobalScope":true},"a40826e8476694e90da94aa008283a7de50d1dafd37beada623863f1901cb7fb","f5a8b7ec4b798c88679194a8ebc25dcb6f5368e6e5811fcda9fe12b0d445b8db","b86e1a45b29437f3a99bad4147cb9fe2357617e8008c0484568e5bb5138d6e13","b5b719a47968cd61a6f83f437236bb6fe22a39223b6620da81ef89f5d7a78fb7","42c431e7965b641106b5e25ab3283aa4865ca7bb9909610a2abfa6226e4348be","0b7e732af0a9599be28c091d6bd1cb22c856ec0d415d4749c087c3881ca07a56","b7fe70be794e13d1b7940e318b8770cd1fb3eced7707805318a2e3aaac2c3e9e",{"version":"2c71199d1fc83bf17636ad5bf63a945633406b7b94887612bba4ef027c662b3e","affectsGlobalScope":true},{"version":"8d6138a264ddc6f94f16e99d4e117a2d6eb31b217891cf091b6437a2f114d561","affectsGlobalScope":true},"3b4c85eea12187de9929a76792b98406e8778ce575caca8c574f06da82622c54","f788131a39c81e0c9b9e463645dd7132b5bc1beb609b0e31e5c1ceaea378b4df","0c236069ce7bded4f6774946e928e4b3601894d294054af47a553f7abcafe2c1","21894466693f64957b9bd4c80fa3ec7fdfd4efa9d1861e070aca23f10220c9b2","396a8939b5e177542bdf9b5262b4eee85d29851b2d57681fa9d7eae30e225830","ad8848c289c0b633452e58179f46edccd14b5a0fe90ebce411f79ff040b803e0",{"version":"5d4ef3f46c7f9d62f7c964f9f9ccdd293be99fb3dcc66c983f2aea7430e3c7c6","affectsGlobalScope":true},"91f8b5abcdff8f9ecb9656b9852878718416fb7700b2c4fad8331e5b97c080bb","59d8f064f86a4a2be03b33c0efcc9e7a268ad27b22f82dce16899f3364f70ba8","0f05c06ff6196958d76b865ae17245b52d8fe01773626ac3c43214a2458ea7b7",{"version":"f49fb15c4aa06b65b0dce4db4584bfd8a9f74644baef1511b404dc95be34af00","affectsGlobalScope":true},{"version":"d48009cbe8a30a504031cc82e1286f78fed33b7a42abf7602c23b5547b382563","affectsGlobalScope":true},"7aaeb5e62f90e1b2be0fc4844df78cdb1be15c22b427bc6c39d57308785b8f10","3ba30205a029ebc0c91d7b1ab4da73f6277d730ca1fc6692d5a9144c6772c76b","d8dba11dc34d50cb4202de5effa9a1b296d7a2f4a029eec871f894bddfb6430d","8b71dd18e7e63b6f991b511a201fad7c3bf8d1e0dd98acb5e3d844f335a73634","01d8e1419c84affad359cc240b2b551fb9812b450b4d3d456b64cda8102d4f60","458b216959c231df388a5de9dcbcafd4b4ca563bc3784d706d0455467d7d4942","269929a24b2816343a178008ac9ae9248304d92a8ba8e233055e0ed6dbe6ef71","93452d394fdd1dc551ec62f5042366f011a00d342d36d50793b3529bfc9bd633","f8c87b19eae111f8720b0345ab301af8d81add39621b63614dfc2d15fd6f140a","831c22d257717bf2cbb03afe9c4bcffc5ccb8a2074344d4238bf16d3a857bb12",{"version":"24ba151e213906027e2b1f5223d33575a3612b0234a0e2b56119520bbe0e594b","affectsGlobalScope":true},{"version":"cbf046714f3a3ba2544957e1973ac94aa819fa8aa668846fa8de47eb1c41b0b2","affectsGlobalScope":true},"aa34c3aa493d1c699601027c441b9664547c3024f9dbab1639df7701d63d18fa","eae74e3d50820f37c72c0679fed959cd1e63c98f6a146a55b8c4361582fa6a52","7c651f8dce91a927ab62925e73f190763574c46098f2b11fb8ddc1b147a6709a","7440ab60f4cb031812940cc38166b8bb6fbf2540cfe599f87c41c08011f0c1df",{"version":"aed89e3c18f4c659ee8153a76560dffda23e2d801e1e60d7a67abd84bc555f8d","affectsGlobalScope":true},{"version":"0ed13c80faeb2b7160bffb4926ff299c468e67a37a645b3ae0917ba0db633c1b","affectsGlobalScope":true},"e393915d3dc385e69c0e2390739c87b2d296a610662eb0b1cb85224e55992250","2f940651c2f30e6b29f8743fae3f40b7b1c03615184f837132b56ea75edad08b","5749c327c3f789f658072f8340786966c8b05ea124a56c1d8d60e04649495a4d",{"version":"c9d62b2a51b2ff166314d8be84f6881a7fcbccd37612442cf1c70d27d5352f50","affectsGlobalScope":true},"e7dbf5716d76846c7522e910896c5747b6df1abd538fee8f5291bdc843461795",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"d3f4c342fb62f348f25f54b473b0ab7371828cbf637134194fa9cdf04856f87b","cdcc132f207d097d7d3aa75615ab9a2e71d6a478162dde8b67f88ea19f3e54de","0d14fa22c41fdc7277e6f71473b20ebc07f40f00e38875142335d5b63cdfc9d2","c085e9aa62d1ae1375794c1fb927a445fa105fed891a7e24edbb1c3300f7384a","f315e1e65a1f80992f0509e84e4ae2df15ecd9ef73df975f7c98813b71e4c8da","5b9586e9b0b6322e5bfbd2c29bd3b8e21ab9d871f82346cb71020e3d84bae73e","3e70a7e67c2cb16f8cd49097360c0309fe9d1e3210ff9222e9dac1f8df9d4fb6","ab68d2a3e3e8767c3fba8f80de099a1cfc18c0de79e42cb02ae66e22dfe14a66","d96cc6598148bf1a98fb2e8dcf01c63a4b3558bdaec6ef35e087fd0562eb40ec",{"version":"c8950367d1812758e9e354c695c60c3e6311bf2cd98b9f9eb469a19df8a9a486","affectsGlobalScope":true}],"options":{"allowSyntheticDefaultImports":true,"declaration":true,"emitDecoratorMetadata":true,"esModuleInterop":true,"experimentalDecorators":true,"importHelpers":true,"inlineSources":true,"module":99,"noEmitOnError":true,"noImplicitAny":false,"outDir":"./","skipLibCheck":true,"sourceMap":true,"strict":true,"target":4,"useDefineForClassFields":false},"fileIdsList":[[94],[94,104],[94,106,109],[48,94],[51,94],[52,57,85,94],[53,64,65,72,82,93,94],[53,54,64,72,94],[55,94],[56,57,65,73,94],[57,82,90,94],[58,60,64,72,94],[59,94],[60,61,94],[64,94],[62,64,94],[51,64,94],[64,65,66,82,93,94],[64,65,66,79,82,85,94],[94,98],[60,64,67,72,82,93,94],[64,65,67,68,72,82,90,93,94],[67,69,82,90,93,94],[48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100],[64,70,94],[71,93,94,98],[60,64,72,82,94],[73,94],[74,94],[51,75,94],[76,92,94,98],[77,94],[78,94],[64,79,80,94],[79,81,94,96],[52,64,82,83,84,85,94],[52,82,84,94],[82,83,94],[85,94],[86,94],[51,82,94],[64,88,89,94],[88,89,94],[57,72,82,90,94],[91,94],[72,92,94],[52,67,78,93,94],[57,94],[82,94,95],[71,94,96],[94,97],[52,57,64,66,75,82,93,94,96,98],[82,94,99],[94,102,108],[94,106],[94,103,107],[94,105],[44,94]],"referencedMap":[[102,1],[105,2],[104,1],[110,3],[48,4],[49,4],[51,5],[52,6],[53,7],[54,8],[55,9],[56,10],[57,11],[58,12],[59,13],[60,14],[61,14],[63,15],[62,16],[64,17],[65,18],[66,19],[50,20],[100,1],[67,21],[68,22],[69,23],[101,24],[70,25],[71,26],[72,27],[73,28],[74,29],[75,30],[76,31],[77,32],[78,33],[79,34],[80,34],[81,35],[82,36],[84,37],[83,38],[85,39],[86,40],[87,41],[88,42],[89,43],[90,44],[91,45],[92,46],[93,47],[94,48],[95,49],[96,50],[97,51],[98,52],[99,53],[103,1],[109,54],[107,55],[108,56],[8,1],[9,1],[11,1],[10,1],[2,1],[12,1],[13,1],[14,1],[15,1],[16,1],[17,1],[18,1],[19,1],[3,1],[4,1],[23,1],[20,1],[21,1],[22,1],[24,1],[25,1],[26,1],[5,1],[27,1],[28,1],[29,1],[30,1],[6,1],[34,1],[31,1],[32,1],[33,1],[35,1],[7,1],[36,1],[41,1],[42,1],[37,1],[38,1],[39,1],[40,1],[1,1],[43,1],[106,57],[44,1],[45,58],[46,1],[47,58]],"exportedModulesMap":[[102,1],[105,2],[104,1],[110,3],[48,4],[49,4],[51,5],[52,6],[53,7],[54,8],[55,9],[56,10],[57,11],[58,12],[59,13],[60,14],[61,14],[63,15],[62,16],[64,17],[65,18],[66,19],[50,20],[100,1],[67,21],[68,22],[69,23],[101,24],[70,25],[71,26],[72,27],[73,28],[74,29],[75,30],[76,31],[77,32],[78,33],[79,34],[80,34],[81,35],[82,36],[84,37],[83,38],[85,39],[86,40],[87,41],[88,42],[89,43],[90,44],[91,45],[92,46],[93,47],[94,48],[95,49],[96,50],[97,51],[98,52],[99,53],[103,1],[109,54],[107,55],[108,56],[8,1],[9,1],[11,1],[10,1],[2,1],[12,1],[13,1],[14,1],[15,1],[16,1],[17,1],[18,1],[19,1],[3,1],[4,1],[23,1],[20,1],[21,1],[22,1],[24,1],[25,1],[26,1],[5,1],[27,1],[28,1],[29,1],[30,1],[6,1],[34,1],[31,1],[32,1],[33,1],[35,1],[7,1],[36,1],[41,1],[42,1],[37,1],[38,1],[39,1],[40,1],[1,1],[43,1],[106,57],[44,1],[46,1]],"semanticDiagnosticsPerFile":[102,105,104,110,48,49,51,52,53,54,55,56,57,58,59,60,61,63,62,64,65,66,50,100,67,68,69,101,70,71,72,73,74,75,76,77,78,79,80,81,82,84,83,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,103,109,107,108,8,9,11,10,2,12,13,14,15,16,17,18,19,3,4,23,20,21,22,24,25,26,5,27,28,29,30,6,34,31,32,33,35,7,36,41,42,37,38,39,40,1,43,106,44,45,46,47]},"version":"4.9.5"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAccessToken = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
6
+ const authorityHostUrl = 'https://login.microsoftonline.com';
7
+ async function getAccessToken(authProvider) {
8
+ try {
9
+ const { clientId, clientSecret, tenantId } = authProvider;
10
+ const authorityUrl = `${authorityHostUrl}/${tenantId}`;
11
+ const resource = 'https://graph.microsoft.com';
12
+ const OAUTH2_URL = `${authorityUrl}/oauth2/token?api-version=1.0`;
13
+ const tokenResponse = await (0, node_fetch_1.default)(OAUTH2_URL, {
14
+ method: 'POST',
15
+ headers: {
16
+ 'Content-Type': 'application/x-www-form-urlencoded'
17
+ },
18
+ body: `client_id=${clientId}&resource=${resource}&client_secret=${clientSecret}&grant_type=client_credentials`
19
+ });
20
+ const result = await tokenResponse.json();
21
+ const { access_token } = result;
22
+ return access_token;
23
+ }
24
+ catch (error) {
25
+ console.error('Error fetching access token:', error);
26
+ return null;
27
+ }
28
+ }
29
+ exports.getAccessToken = getAccessToken;
30
+ //# sourceMappingURL=get-access-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-access-token.js","sourceRoot":"","sources":["../../server/controllers/get-access-token.ts"],"names":[],"mappings":";;;;AAAA,oEAA8B;AAI9B,MAAM,gBAAgB,GAAG,mCAAmC,CAAA;AAErD,KAAK,UAAU,cAAc,CAAC,YAA0B;IAC7D,IAAI;QACF,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAA;QAEzD,MAAM,YAAY,GAAG,GAAG,gBAAgB,IAAI,QAAQ,EAAE,CAAA;QACtD,MAAM,QAAQ,GAAG,6BAA6B,CAAA;QAC9C,MAAM,UAAU,GAAG,GAAG,YAAY,+BAA+B,CAAA;QAEjE,MAAM,aAAa,GAAG,MAAM,IAAA,oBAAK,EAAC,UAAU,EAAE;YAC5C,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,mCAAmC;aACpD;YACD,IAAI,EAAE,aAAa,QAAQ,aAAa,QAAQ,kBAAkB,YAAY,gCAAgC;SAC/G,CAAC,CAAA;QAEF,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,CAAA;QACzC,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;QAC/B,OAAO,YAAY,CAAA;KACpB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAA;QACpD,OAAO,IAAI,CAAA;KACZ;AACH,CAAC;AAvBD,wCAuBC","sourcesContent":["import fetch from 'node-fetch'\n\nimport { AuthProvider } from '@things-factory/auth-base'\n\nconst authorityHostUrl = 'https://login.microsoftonline.com'\n\nexport async function getAccessToken(authProvider: AuthProvider): Promise<string | null> {\n try {\n const { clientId, clientSecret, tenantId } = authProvider\n\n const authorityUrl = `${authorityHostUrl}/${tenantId}`\n const resource = 'https://graph.microsoft.com'\n const OAUTH2_URL = `${authorityUrl}/oauth2/token?api-version=1.0`\n\n const tokenResponse = await fetch(OAUTH2_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded'\n },\n body: `client_id=${clientId}&resource=${resource}&client_secret=${clientSecret}&grant_type=client_credentials`\n })\n\n const result = await tokenResponse.json()\n const { access_token } = result\n return access_token\n } catch (error) {\n console.error('Error fetching access token:', error)\n return null\n }\n}\n"]}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.msgraphSubscriptions = exports.getClientState = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
6
+ const get_access_token_1 = require("./get-access-token");
7
+ var clientState;
8
+ function getClientState() {
9
+ return clientState;
10
+ }
11
+ exports.getClientState = getClientState;
12
+ async function msgraphSubscriptions(authProvider) {
13
+ const accessToken = await (0, get_access_token_1.getAccessToken)(authProvider);
14
+ const expirationDateTime = new Date(Date.now() + 3 * 24 * 60 * 60 * 1000);
15
+ clientState = `${authProvider.domainId}:${authProvider.id}`; // TODO make secure
16
+ const response = await (0, node_fetch_1.default)('https://graph.microsoft.com/v1.0/subscriptions', {
17
+ method: 'POST',
18
+ headers: {
19
+ Authorization: `Bearer ${accessToken}`,
20
+ 'Content-Type': 'application/json'
21
+ },
22
+ body: JSON.stringify({
23
+ changeType: 'created,updated',
24
+ notificationUrl: 'YOUR_WEBHOOK_ENDPOINT_BASE' + '/webhook/google-users',
25
+ resource: '/users',
26
+ expirationDateTime: expirationDateTime.toISOString() /* 최대 3일 이내, UTC 타임으로 설정 */,
27
+ clientState
28
+ })
29
+ });
30
+ const data = await response.json();
31
+ }
32
+ exports.msgraphSubscriptions = msgraphSubscriptions;
33
+ //# sourceMappingURL=subscribe-users-change.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscribe-users-change.js","sourceRoot":"","sources":["../../server/controllers/subscribe-users-change.ts"],"names":[],"mappings":";;;;AAAA,oEAA8B;AAE9B,yDAAmD;AAGnD,IAAI,WAAW,CAAA;AAEf,SAAgB,cAAc;IAC5B,OAAO,WAAW,CAAA;AACpB,CAAC;AAFD,wCAEC;AAEM,KAAK,UAAU,oBAAoB,CAAC,YAA0B;IACnE,MAAM,WAAW,GAAG,MAAM,IAAA,iCAAc,EAAC,YAAY,CAAC,CAAA;IACtD,MAAM,kBAAkB,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IAEzE,WAAW,GAAG,GAAG,YAAY,CAAC,QAAQ,IAAI,YAAY,CAAC,EAAE,EAAE,CAAA,CAAC,mBAAmB;IAE/E,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,gDAAgD,EAAE;QAC7E,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,WAAW,EAAE;YACtC,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,UAAU,EAAE,iBAAiB;YAC7B,eAAe,EAAE,4BAA4B,GAAG,uBAAuB;YACvE,QAAQ,EAAE,QAAQ;YAClB,kBAAkB,EAAE,kBAAkB,CAAC,WAAW,EAAE,CAAC,2BAA2B;YAChF,WAAW;SACZ,CAAC;KACH,CAAC,CAAA;IAEF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;AACpC,CAAC;AAtBD,oDAsBC","sourcesContent":["import fetch from 'node-fetch'\n\nimport { getAccessToken } from './get-access-token'\nimport { AuthProvider } from '@things-factory/auth-base'\n\nvar clientState\n\nexport function getClientState() {\n return clientState\n}\n\nexport async function msgraphSubscriptions(authProvider: AuthProvider) {\n const accessToken = await getAccessToken(authProvider)\n const expirationDateTime = new Date(Date.now() + 3 * 24 * 60 * 60 * 1000)\n\n clientState = `${authProvider.domainId}:${authProvider.id}` // TODO make secure\n\n const response = await fetch('https://graph.microsoft.com/v1.0/subscriptions', {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${accessToken}`,\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({\n changeType: 'created,updated',\n notificationUrl: 'YOUR_WEBHOOK_ENDPOINT_BASE' + '/webhook/google-users',\n resource: '/users',\n expirationDateTime: expirationDateTime.toISOString() /* 최대 3일 이내, UTC 타임으로 설정 */,\n clientState\n })\n })\n\n const data = await response.json()\n}\n"]}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateUserInfo = exports.syncAllUserInfo = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
6
+ const auth_base_1 = require("@things-factory/auth-base");
7
+ const get_access_token_1 = require("./get-access-token");
8
+ async function syncAllUserInfo(authProvider, context) {
9
+ const accessToken = await (0, get_access_token_1.getAccessToken)(authProvider);
10
+ if (!accessToken) {
11
+ throw new Error('Failed to obtain access token');
12
+ }
13
+ const latestData = await (0, node_fetch_1.default)('https://graph.microsoft.com/v1.0/users', {
14
+ headers: {
15
+ Authorization: `Bearer ${accessToken}`
16
+ }
17
+ }).then(res => res.json());
18
+ latestData.value
19
+ .filter(({ mail }) => mail)
20
+ .forEach(async (user) => {
21
+ await updateUserInfo(authProvider, user, context);
22
+ });
23
+ }
24
+ exports.syncAllUserInfo = syncAllUserInfo;
25
+ async function updateUserInfo(authProvider, userInfo, context) {
26
+ const { tx, domain, user } = context.state;
27
+ // {
28
+ // "id": "d290f1ee-6c54-4b01-90e6-d701748f0851",
29
+ // "businessPhones": [
30
+ // "+1 412 555 0109"
31
+ // ],
32
+ // "displayName": "John Doe",
33
+ // "givenName": "John",
34
+ // "jobTitle": "Developer",
35
+ // "mail": "john.doe@contoso.com",
36
+ // "mobilePhone": "+1 412 555 0109",
37
+ // "officeLocation": "Floor 2",
38
+ // "preferredLanguage": "en-US",
39
+ // "surname": "Doe",
40
+ // "userPrincipalName": "john.doe@contoso.com"
41
+ // }
42
+ const { id, businessPhones, displayName, givenName, surname, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, userPricipalName } = userInfo;
43
+ const repository = tx.getRepository(auth_base_1.User);
44
+ // 1. 사용자를 찾는다.(email 정보로)
45
+ const existingUser = await repository.findOne({
46
+ where: { email: mail },
47
+ relations: ['domains']
48
+ });
49
+ if (!existingUser) {
50
+ // 2. 사용자가 없다면, 생성한다.
51
+ const salt = auth_base_1.User.generateSalt();
52
+ /* normally they don't login with this password. */
53
+ const password = salt;
54
+ const createdUser = await repository.save({
55
+ id,
56
+ name: displayName,
57
+ email: mail,
58
+ creator: user,
59
+ updater: user,
60
+ domains: domain ? [domain] : [],
61
+ roles: [],
62
+ salt,
63
+ userType: 'user',
64
+ // ssoId: id,
65
+ locale: preferredLanguage,
66
+ status: auth_base_1.UserStatus.ACTIVATED,
67
+ passwordUpdatedAt: new Date(),
68
+ password: auth_base_1.User.encode(password, salt)
69
+ });
70
+ await tx.getRepository(auth_base_1.UsersAuthProviders).save({
71
+ domain,
72
+ user: createdUser,
73
+ authProvider,
74
+ ssoId: id
75
+ });
76
+ return createdUser;
77
+ }
78
+ else {
79
+ // 3. 사용자가 있다면, 업데이트한다.
80
+ const { domains } = existingUser;
81
+ if (!domains.find(existing => existing.id == domain.id)) {
82
+ domains.push(domain);
83
+ }
84
+ const updatedUser = await repository.save(Object.assign(Object.assign({}, existingUser), { name: displayName,
85
+ // ssoId: id,
86
+ domains, locale: preferredLanguage, updater: user }));
87
+ const usersAuthProviders = await tx.getRepository(auth_base_1.UsersAuthProviders).findOne({
88
+ where: { domain: { id: domain.id }, user: { id: updatedUser.id }, authProvider: { id: authProvider.id } }
89
+ });
90
+ await tx.getRepository(auth_base_1.UsersAuthProviders).save(Object.assign(Object.assign({}, usersAuthProviders), { domain, user: updatedUser, authProvider, ssoId: id }));
91
+ return updatedUser;
92
+ }
93
+ }
94
+ exports.updateUserInfo = updateUserInfo;
95
+ //# sourceMappingURL=sync-user-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-user-info.js","sourceRoot":"","sources":["../../server/controllers/sync-user-info.ts"],"names":[],"mappings":";;;;AAAA,oEAA8B;AAE9B,yDAA8F;AAC9F,yDAAmD;AAE5C,KAAK,UAAU,eAAe,CAAC,YAA0B,EAAE,OAAwB;IACxF,MAAM,WAAW,GAAG,MAAM,IAAA,iCAAc,EAAC,YAAY,CAAC,CAAA;IAEtD,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;KACjD;IAED,MAAM,UAAU,GAAG,MAAM,IAAA,oBAAK,EAAC,wCAAwC,EAAE;QACvE,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC;KACF,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CA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AE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,WAAW,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,EAAE,YAAY,CAAC,EAAE,EAAE,EAAE;SAC1G,CAAC,CAAA;QAEF,MAAM,EAAE,CAAC,aAAa,CAAC,8BAAkB,CAAC,CAAC,IAAI,iCAC1C,kBAAkB,KACrB,MAAM,EACN,IAAI,EAAE,WAAW,EACjB,YAAY,EACZ,KAAK,EAAE,EAAE,IACT,CAAA;QAEF,OAAO,WAAW,CAAA;KACnB;AACH,CAAC;AAvGD,wCAuGC","sourcesContent":["import fetch from 'node-fetch'\n\nimport { AuthProvider, User, UserStatus, UsersAuthProviders } from '@things-factory/auth-base'\nimport { getAccessToken } from './get-access-token'\n\nexport async function syncAllUserInfo(authProvider: AuthProvider, context: ResolverContext) {\n const accessToken = await getAccessToken(authProvider)\n\n if (!accessToken) {\n throw new Error('Failed to obtain access token')\n }\n\n const latestData = await fetch('https://graph.microsoft.com/v1.0/users', {\n headers: {\n Authorization: `Bearer ${accessToken}`\n }\n }).then(res => res.json())\n\n latestData.value\n .filter(({ mail }) => mail)\n .forEach(async user => {\n await updateUserInfo(authProvider, user, context)\n })\n}\n\nexport async function updateUserInfo(authProvider: AuthProvider, userInfo, context: ResolverContext) {\n const { tx, domain, user } = context.state\n\n // {\n // \"id\": \"d290f1ee-6c54-4b01-90e6-d701748f0851\",\n // \"businessPhones\": [\n // \"+1 412 555 0109\"\n // ],\n // \"displayName\": \"John Doe\",\n // \"givenName\": \"John\",\n // \"jobTitle\": \"Developer\",\n // \"mail\": \"john.doe@contoso.com\",\n // \"mobilePhone\": \"+1 412 555 0109\",\n // \"officeLocation\": \"Floor 2\",\n // \"preferredLanguage\": \"en-US\",\n // \"surname\": \"Doe\",\n // \"userPrincipalName\": \"john.doe@contoso.com\"\n // }\n const {\n id,\n businessPhones,\n displayName,\n givenName,\n surname,\n jobTitle,\n mail,\n mobilePhone,\n officeLocation,\n preferredLanguage,\n userPricipalName\n } = userInfo\n\n const repository = tx.getRepository(User)\n\n // 1. 사용자를 찾는다.(email 정보로)\n const existingUser = await repository.findOne({\n where: { email: mail },\n relations: ['domains']\n })\n\n if (!existingUser) {\n // 2. 사용자가 없다면, 생성한다.\n const salt = User.generateSalt()\n\n /* normally they don't login with this password. */\n const password = salt\n\n const createdUser = await repository.save({\n id,\n name: displayName,\n email: mail,\n creator: user,\n updater: user,\n domains: domain ? [domain] : [],\n roles: [],\n salt,\n userType: 'user',\n // ssoId: id,\n locale: preferredLanguage,\n status: UserStatus.ACTIVATED,\n passwordUpdatedAt: new Date(),\n password: User.encode(password, salt)\n })\n\n await tx.getRepository(UsersAuthProviders).save({\n domain,\n user: createdUser,\n authProvider,\n ssoId: id\n })\n\n return createdUser\n } else {\n // 3. 사용자가 있다면, 업데이트한다.\n const { domains } = existingUser\n\n if (!domains.find(existing => existing.id == domain.id)) {\n domains.push(domain)\n }\n\n const updatedUser = await repository.save({\n ...existingUser,\n name: displayName,\n // ssoId: id,\n domains,\n locale: preferredLanguage,\n updater: user\n })\n\n const usersAuthProviders = await tx.getRepository(UsersAuthProviders).findOne({\n where: { domain: { id: domain.id }, user: { id: updatedUser.id }, authProvider: { id: authProvider.id } }\n })\n\n await tx.getRepository(UsersAuthProviders).save({\n ...usersAuthProviders,\n domain,\n user: updatedUser,\n authProvider,\n ssoId: id\n })\n\n return updatedUser\n }\n}\n"]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./middlewares"), exports);
5
+ tslib_1.__exportStar(require("./service"), exports);
6
+ require("./routes");
7
+ const auth_base_1 = require("@things-factory/auth-base");
8
+ const sync_user_info_1 = require("./controllers/sync-user-info");
9
+ auth_base_1.AuthProvider.register('google', {
10
+ type: 'google',
11
+ description: 'Authentication Provider for Google',
12
+ help: '',
13
+ parameterSpec: null,
14
+ async synchronizeUsers(authProvider, context) {
15
+ await (0, sync_user_info_1.syncAllUserInfo)(authProvider, context);
16
+ return true;
17
+ }
18
+ });
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,wDAA6B;AAC7B,oDAAyB;AAEzB,oBAAiB;AAEjB,yDAAwD;AACxD,iEAA8D;AAE9D,wBAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE;IAC9B,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,oCAAoC;IACjD,IAAI,EAAE,EAAE;IACR,aAAa,EAAE,IAAI;IACnB,KAAK,CAAC,gBAAgB,CAAC,YAA0B,EAAE,OAAwB;QACzE,MAAM,IAAA,gCAAe,EAAC,YAAY,EAAE,OAAO,CAAC,CAAA;QAC5C,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAC,CAAA","sourcesContent":["export * from './middlewares'\nexport * from './service'\n\nimport './routes'\n\nimport { AuthProvider } from '@things-factory/auth-base'\nimport { syncAllUserInfo } from './controllers/sync-user-info'\n\nAuthProvider.register('google', {\n type: 'google',\n description: 'Authentication Provider for Google',\n help: '',\n parameterSpec: null,\n async synchronizeUsers(authProvider: AuthProvider, context: ResolverContext): Promise<boolean> {\n await syncAllUserInfo(authProvider, context)\n return true\n }\n})\n"]}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.googleSubscriptionMiddleware = exports.authGoogleMiddleware = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const koa_passport_1 = tslib_1.__importDefault(require("koa-passport"));
6
+ const passport_google_oauth20_1 = require("passport-google-oauth20");
7
+ const env_1 = require("@things-factory/env");
8
+ const auth_base_1 = require("@things-factory/auth-base");
9
+ const SSOGoogleConfig = env_1.config.get('sso/google/config');
10
+ if (SSOGoogleConfig) {
11
+ koa_passport_1.default.use(new passport_google_oauth20_1.Strategy(SSOGoogleConfig, async (token, tokenSecret, profile, done) => {
12
+ if (!profile) {
13
+ return done(new Error('No profile found'), null);
14
+ }
15
+ try {
16
+ const { email } = profile;
17
+ const user = await auth_base_1.User.checkAuthWithEmail({ email });
18
+ const { id, userType, status } = user;
19
+ return done(null, {
20
+ id,
21
+ userType,
22
+ status
23
+ });
24
+ }
25
+ catch (error) {
26
+ return done(error);
27
+ }
28
+ }));
29
+ }
30
+ async function authGoogleMiddleware(context, next) {
31
+ const { path } = context;
32
+ const { user } = context.state;
33
+ if (user) {
34
+ return await next();
35
+ }
36
+ await koa_passport_1.default.authenticate('google', {
37
+ failureRedirect: '/auth/signin',
38
+ successRedirect: '/auth/checkin'
39
+ })(context, next);
40
+ }
41
+ exports.authGoogleMiddleware = authGoogleMiddleware;
42
+ async function googleSubscriptionMiddleware(context, next) {
43
+ var _a;
44
+ const { path } = context;
45
+ const { user } = context.state;
46
+ if (user) {
47
+ return await next();
48
+ }
49
+ await koa_passport_1.default.authenticate('google', {
50
+ failureRedirect: '/auth/signin',
51
+ successRedirect: '/auth/checkin'
52
+ })(context);
53
+ /* 다음은, websocket 에서 인증을 처리하기 위한 작업임. */
54
+ const passportObject = (_a = context.session) === null || _a === void 0 ? void 0 : _a.passport;
55
+ if (passportObject) {
56
+ const userEntity = await auth_base_1.User.checkAuth(passportObject === null || passportObject === void 0 ? void 0 : passportObject.user);
57
+ context.state.user = userEntity;
58
+ }
59
+ return await next();
60
+ }
61
+ exports.googleSubscriptionMiddleware = googleSubscriptionMiddleware;
62
+ //# sourceMappingURL=google-authenticate-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-authenticate-middleware.js","sourceRoot":"","sources":["../../server/middlewares/google-authenticate-middleware.ts"],"names":[],"mappings":";;;;AAAA,wEAAmC;AACnC,qEAAoE;AAEpE,6CAA4C;AAC5C,yDAAgD;AAEhD,MAAM,eAAe,GAAG,YAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,C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OAAO,CAAC,KAAK,CAAA;IAE9B,IAAI,IAAI,EAAE;QACR,OAAO,MAAM,IAAI,EAAE,CAAA;KACpB;IAED,MAAM,sBAAQ,CAAC,YAAY,CAAC,QAAQ,EAAE;QACpC,eAAe,EAAE,cAAc;QAC/B,eAAe,EAAE,eAAe;KACjC,CAAC,CAAC,OAAO,CAAC,CAAA;IAEX,wCAAwC;IACxC,MAAM,cAAc,GAAG,MAAA,OAAO,CAAC,OAAO,0CAAE,QAAQ,CAAA;IAChD,IAAI,cAAc,EAAE;QAClB,MAAM,UAAU,GAAG,MAAM,gBAAI,CAAC,SAAS,CAAC,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,CAAC,CAAA;QAC7D,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,UAAU,CAAA;KAChC;IAED,OAAO,MAAM,IAAI,EAAE,CAAA;AACrB,CAAC;AArBD,oEAqBC","sourcesContent":["import passport from 'koa-passport'\nimport { Strategy as GoogleStrategy } from 'passport-google-oauth20'\n\nimport { config } from '@things-factory/env'\nimport { User } from '@things-factory/auth-base'\n\nconst SSOGoogleConfig = config.get('sso/google/config')\n\nif (SSOGoogleConfig) {\n passport.use(\n new GoogleStrategy(SSOGoogleConfig, async (token, tokenSecret, profile, done) => {\n if (!profile) {\n return done(new Error('No profile found'), null)\n }\n\n try {\n const { email } = profile\n\n const user = await User.checkAuthWithEmail({ email })\n\n const { id, userType, status } = user\n\n return done(null, {\n id,\n userType,\n status\n })\n } catch (error) {\n return done(error)\n }\n })\n )\n}\n\nexport async function authGoogleMiddleware(context, next) {\n const { path } = context\n const { user } = context.state\n\n if (user) {\n return await next()\n }\n\n await passport.authenticate('google', {\n failureRedirect: '/auth/signin',\n successRedirect: '/auth/checkin'\n })(context, next)\n}\n\nexport async function googleSubscriptionMiddleware(context, next) {\n const { path } = context\n const { user } = context.state\n\n if (user) {\n return await next()\n }\n\n await passport.authenticate('google', {\n failureRedirect: '/auth/signin',\n successRedirect: '/auth/checkin'\n })(context)\n\n /* 다음은, websocket 에서 인증을 처리하기 위한 작업임. */\n const passportObject = context.session?.passport\n if (passportObject) {\n const userEntity = await User.checkAuth(passportObject?.user)\n context.state.user = userEntity\n }\n\n return await next()\n}\n"]}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const env_1 = require("@things-factory/env");
5
+ const SSOGoogleConfig = env_1.config.get('sso/google/config');
6
+ const google_authenticate_middleware_1 = require("./google-authenticate-middleware");
7
+ if (SSOGoogleConfig) {
8
+ process.on('bootstrap-module-subscription', (app, subscriptionMiddleware) => {
9
+ subscriptionMiddleware.unshift(google_authenticate_middleware_1.googleSubscriptionMiddleware);
10
+ });
11
+ }
12
+ tslib_1.__exportStar(require("./google-authenticate-middleware"), exports);
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/middlewares/index.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,MAAM,eAAe,GAAG,YAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AAEvD,qFAA+E;AAE/E,IAAI,eAAe,EAAE;IACnB,OAAO,CAAC,EAAE,CAAC,+BAAsC,EAAE,CAAC,GAAG,EAAE,sBAAsB,EAAE,EAAE;QACjF,sBAAsB,CAAC,OAAO,CAAC,6DAA4B,CAAC,CAAA;IAC9D,CAAC,CAAC,CAAA;CACH;AAED,2EAAgD","sourcesContent":["import { config } from '@things-factory/env'\n\nconst SSOGoogleConfig = config.get('sso/google/config')\n\nimport { googleSubscriptionMiddleware } from './google-authenticate-middleware'\n\nif (SSOGoogleConfig) {\n process.on('bootstrap-module-subscription' as any, (app, subscriptionMiddleware) => {\n subscriptionMiddleware.unshift(googleSubscriptionMiddleware)\n })\n}\n\nexport * from './google-authenticate-middleware'\n"]}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authGoogleRouter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const koa_router_1 = tslib_1.__importDefault(require("koa-router"));
6
+ const koa_passport_1 = tslib_1.__importDefault(require("koa-passport"));
7
+ exports.authGoogleRouter = new koa_router_1.default();
8
+ exports.authGoogleRouter.get('/auth/callback-auth-google', koa_passport_1.default.authenticate('google', { failureRedirect: '/auth/signin' }), ctx => {
9
+ ctx.redirect('/auth/checkin');
10
+ });
11
+ //# sourceMappingURL=auth-google-router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-google-router.js","sourceRoot":"","sources":["../../server/router/auth-google-router.ts"],"names":[],"mappings":";;;;AAAA,oEAA+B;AAE/B,wEAAmC;AAGtB,QAAA,gBAAgB,GAAG,IAAI,oBAAM,EAAE,CAAA;AAE5C,wBAAgB,CAAC,GAAG,CAClB,4BAA4B,EAC5B,sBAAQ,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC,EACpE,GAAG,CAAC,EAAE;IACJ,GAAG,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAA;AAC/B,CAAC,CACF,CAAA","sourcesContent":["import Router from 'koa-router'\n\nimport passport from 'koa-passport'\nimport { authGoogleMiddleware } from '../middlewares'\n\nexport const authGoogleRouter = new Router()\n\nauthGoogleRouter.get(\n '/auth/callback-auth-google',\n passport.authenticate('google', { failureRedirect: '/auth/signin' }),\n ctx => {\n ctx.redirect('/auth/checkin')\n }\n)\n"]}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authGoogleWebhookRouter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const koa_router_1 = tslib_1.__importDefault(require("koa-router"));
6
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
7
+ const shell_1 = require("@things-factory/shell");
8
+ const sync_user_info_1 = require("../controllers/sync-user-info");
9
+ const get_access_token_1 = require("../controllers/get-access-token");
10
+ const auth_base_1 = require("@things-factory/auth-base");
11
+ exports.authGoogleWebhookRouter = new koa_router_1.default();
12
+ exports.authGoogleWebhookRouter.post('/webhook/google-users', async (context) => {
13
+ const notifications = context.request.body.value;
14
+ const clientState = context.request.body.clientState;
15
+ const [domainId, authProviderId] = (clientState === null || clientState === void 0 ? void 0 : clientState.split(':')) || [];
16
+ if (!domainId || !authProviderId) {
17
+ context.status = 401; // unauthorized
18
+ context.body = 'Invalid ClientState';
19
+ return;
20
+ }
21
+ await (0, shell_1.getDataSource)('tx').transaction(async (tx) => {
22
+ const wrap = context.app.createContext(context.req || {}, context.res || {});
23
+ wrap.state = Object.assign(Object.assign({}, context.state), { domain: null, tx });
24
+ wrap.t = context.t;
25
+ const authProvider = await tx.getRepository(auth_base_1.AuthProvider).findOne({
26
+ where: {
27
+ domain: { id: domainId },
28
+ id: authProviderId
29
+ }
30
+ });
31
+ if (!authProvider) {
32
+ context.status = 401; // unauthorized
33
+ context.body = 'Invalid ClientState';
34
+ return;
35
+ }
36
+ const accessToken = await (0, get_access_token_1.getAccessToken)(authProvider);
37
+ for (const notification of notifications) {
38
+ const userId = notification.resourceData.id;
39
+ try {
40
+ const userResponse = await (0, node_fetch_1.default)(`https://graph.microsoft.com/v1.0/users/${userId}`, {
41
+ headers: {
42
+ Authorization: `Bearer ${accessToken}`
43
+ }
44
+ });
45
+ if (!userResponse.ok) {
46
+ throw new Error(`Failed to fetch user data: ${userResponse.statusText}`);
47
+ }
48
+ const userInfo = await userResponse.json();
49
+ // {
50
+ // "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
51
+ // "businessPhones": ["+1 412 555 0109"],
52
+ // "displayName": "Megan Bowen",
53
+ // "givenName": "Megan",
54
+ // "jobTitle": "Auditor",
55
+ // "mail": "MeganB@M365x214355.onmicrosoft.com",
56
+ // "mobilePhone": "+1 412 555 0109",
57
+ // "officeLocation": "12/1110",
58
+ // "preferredLanguage": "en-US",
59
+ // "surname": "Bowen",
60
+ // "userPrincipalName": "MeganB@M365x214355.onmicrosoft.com",
61
+ // "id": "48d31887-5fad-4d73-a9f5-3c356e68a038"
62
+ // }
63
+ // webhook 호출로부터 호출한 tenant를 알 수 있다면, 매핑된 도메인 정보를 포함할 수 있을 것 같은데..
64
+ await (0, sync_user_info_1.updateUserInfo)(authProvider, userInfo, wrap);
65
+ }
66
+ catch (error) {
67
+ console.error('Error fetching user data from Microsoft Graph:', error);
68
+ }
69
+ }
70
+ });
71
+ context.status = 202;
72
+ });
73
+ //# sourceMappingURL=auth-google-webhook-router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-google-webhook-router.js","sourceRoot":"","sources":["../../server/router/auth-google-webhook-router.ts"],"names":[],"mappings":";;;;AAAA,oEAA+B;AAC/B,oEAA8B;AAE9B,iDAAoE;AAEpE,kEAA8D;AAC9D,sEAAgE;AAChE,yDAAwD;AAE3C,QAAA,uBAAuB,GAAG,IAAI,oBAAM,EAAE,CAAA;AASnD,+BAAuB,CAAC,IAAI,CAAC,uBAAuB,EAAE,KAAK,EAAC,OAAO,EAAC,EAAE;IACpE,MAAM,aAAa,GAAmB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAA;IAChE,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAA;IACpD,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,KAAK,CAAC,GAAG,CAAC,KAAI,EAAE,CAAA;IAEhE,IAAI,CAAC,QAAQ,IAAI,CAAC,cAAc,EAAE;QAChC,OAAO,CAAC,MAAM,GAAG,GAAG,CAAA,CAAC,eAAe;QACpC,OAAO,CAAC,IAAI,GAAG,qBAAqB,CAAA;QACpC,OAAM;KACP;IAED,MAAM,IAAA,qBAAa,EAAC,IAAI,CAAC,CAAC,WAAW,CAAC,KAAK,EAAC,EAAE,EAAC,EAAE;Q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BAA0B;gBAC1B,2BAA2B;gBAC3B,kDAAkD;gBAClD,sCAAsC;gBACtC,iCAAiC;gBACjC,kCAAkC;gBAClC,wBAAwB;gBACxB,+DAA+D;gBAC/D,iDAAiD;gBACjD,IAAI;gBAEJ,kEAAkE;gBAElE,MAAM,IAAA,+BAAc,EAAC,YAAY,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;aACnD;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,gDAAgD,EAAE,KAAK,CAAC,CAAA;aACvE;SACF;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,MAAM,GAAG,GAAG,CAAA;AACtB,CAAC,CAAC,CAAA","sourcesContent":["import Router from 'koa-router'\nimport fetch from 'node-fetch'\n\nimport { getRepository, getDataSource } from '@things-factory/shell'\n\nimport { updateUserInfo } from '../controllers/sync-user-info'\nimport { getAccessToken } from '../controllers/get-access-token'\nimport { AuthProvider } from '@things-factory/auth-base'\n\nexport const authGoogleWebhookRouter = new Router()\n\n// Microsoft Graph에서 발송되는 알림을 처리하기 위한 타입 정의\ninterface Notification {\n resourceData: {\n id: string\n }\n}\n\nauthGoogleWebhookRouter.post('/webhook/google-users', async context => {\n const notifications: Notification[] = context.request.body.value\n const clientState = context.request.body.clientState\n const [domainId, authProviderId] = clientState?.split(':') || []\n\n if (!domainId || !authProviderId) {\n context.status = 401 // unauthorized\n context.body = 'Invalid ClientState'\n return\n }\n\n await getDataSource('tx').transaction(async tx => {\n const wrap = context.app.createContext(context.req || {}, context.res || {})\n\n wrap.state = {\n ...context.state,\n domain: null,\n tx\n }\n wrap.t = context.t\n\n const authProvider = await tx.getRepository(AuthProvider).findOne({\n where: {\n domain: { id: domainId },\n id: authProviderId\n }\n })\n\n if (!authProvider) {\n context.status = 401 // unauthorized\n context.body = 'Invalid ClientState'\n return\n }\n\n const accessToken = await getAccessToken(authProvider)\n\n for (const notification of notifications) {\n const userId = notification.resourceData.id\n\n try {\n const userResponse = await fetch(`https://graph.microsoft.com/v1.0/users/${userId}`, {\n headers: {\n Authorization: `Bearer ${accessToken}`\n }\n })\n\n if (!userResponse.ok) {\n throw new Error(`Failed to fetch user data: ${userResponse.statusText}`)\n }\n\n const userInfo = await userResponse.json()\n\n // {\n // \"@odata.context\": \"https://graph.microsoft.com/v1.0/$metadata#users/$entity\",\n // \"businessPhones\": [\"+1 412 555 0109\"],\n // \"displayName\": \"Megan Bowen\",\n // \"givenName\": \"Megan\",\n // \"jobTitle\": \"Auditor\",\n // \"mail\": \"MeganB@M365x214355.onmicrosoft.com\",\n // \"mobilePhone\": \"+1 412 555 0109\",\n // \"officeLocation\": \"12/1110\",\n // \"preferredLanguage\": \"en-US\",\n // \"surname\": \"Bowen\",\n // \"userPrincipalName\": \"MeganB@M365x214355.onmicrosoft.com\",\n // \"id\": \"48d31887-5fad-4d73-a9f5-3c356e68a038\"\n // }\n\n // webhook 호출로부터 호출한 tenant를 알 수 있다면, 매핑된 도메인 정보를 포함할 수 있을 것 같은데..\n\n await updateUserInfo(authProvider, userInfo, wrap)\n } catch (error) {\n console.error('Error fetching user data from Microsoft Graph:', error)\n }\n }\n })\n\n context.status = 202\n})\n"]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./auth-google-router"), exports);
5
+ tslib_1.__exportStar(require("./auth-google-webhook-router"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/router/index.ts"],"names":[],"mappings":";;;AAAA,+DAAoC;AACpC,uEAA4C","sourcesContent":["export * from './auth-google-router'\nexport * from './auth-google-webhook-router'\n"]}