@tapni/auth 1.0.12 → 1.0.14

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.
@@ -1397,7 +1397,7 @@ function pa(n, e, t, r, o, i) {
1397
1397
  const ao = /* @__PURE__ */ _t(oa, [["render", pa], ["__scopeId", "data-v-7aad6400"]]), ha = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1398
1398
  __proto__: null,
1399
1399
  default: ao
1400
- }, Symbol.toStringTag, { value: "Module" })), fa = "1.0.12", cr = {
1400
+ }, Symbol.toStringTag, { value: "Module" })), fa = "1.0.14", cr = {
1401
1401
  getMe() {
1402
1402
  return le().get("/users/me");
1403
1403
  },
@@ -5563,7 +5563,7 @@ Tanıştığınız herkesi etkileyin 😎 <br> Kendinize bir tane ayırın 👇`
5563
5563
  choose_other_login_methods: "다른 로그인 방법 선택하기",
5564
5564
  no_sso_logins: "귀하의 회사는 SSO 로그인을 사용하지 않습니다. 관리자에게 문의하십시오."
5565
5565
  }
5566
- }, To = () => Promise.resolve().then(() => ha), ma = () => Promise.resolve().then(() => mc), _a = () => Promise.resolve().then(() => cl), va = () => Promise.resolve().then(() => Xu), ya = () => Promise.resolve().then(() => zc), wa = () => Promise.resolve().then(() => Cl), ba = () => Promise.resolve().then(() => od), ka = () => import("./QR-ShTn8gSL.js"), Ca = () => Promise.resolve().then(() => Cu), Ea = () => import("./Apps-DeRIQjBx.js"), Ta = () => import("./Billing-DsilesKo.js"), Sa = () => import("./CustomApp-CEzhE2YM.js"), Ia = () => import("./General-C9CUD54h.js"), Aa = [
5566
+ }, To = () => Promise.resolve().then(() => ha), ma = () => Promise.resolve().then(() => mc), _a = () => Promise.resolve().then(() => cl), va = () => Promise.resolve().then(() => Xu), ya = () => Promise.resolve().then(() => zc), wa = () => Promise.resolve().then(() => Cl), ba = () => Promise.resolve().then(() => od), ka = () => import("./QR-BfTMaaLP.js"), Ca = () => Promise.resolve().then(() => Cu), Ea = () => import("./Apps-CFXAriI4.js"), Ta = () => import("./Billing-JwfACI7M.js"), Sa = () => import("./CustomApp---b2SbIq.js"), Ia = () => import("./General-kIEcVs4A.js"), Aa = [
5567
5567
  {
5568
5568
  path: "/welcome",
5569
5569
  name: "AuthWelcome",
@@ -5686,6 +5686,7 @@ Tanıştığınız herkesi etkileyin 😎 <br> Kendinize bir tane ayırın 👇`
5686
5686
  "https://designer-dev.tapni.com",
5687
5687
  "http://localhost:8082",
5688
5688
  "http://localhost:7777",
5689
+ "https://localhost:7777",
5689
5690
  "http://localhost:8086",
5690
5691
  "https://localhost:8085",
5691
5692
  "http://localhost:8085"
@@ -15198,46 +15199,66 @@ const xs = Ir("MsAuthPlugin", {
15198
15199
  data() {
15199
15200
  return {
15200
15201
  code_verifier: "",
15201
- code_challenge: ""
15202
+ code_challenge: "",
15203
+ shouldCloseWindow: !1,
15204
+ popupWindow: null,
15205
+ checkInterval: null
15202
15206
  };
15203
15207
  },
15204
15208
  computed: {},
15205
15209
  watch: {
15206
- /*
15207
- '$route.path': async function(routePath) {
15208
- await this.handleSamlRedirect(routePath)
15210
+ "$route.path"(n) {
15211
+ n === "/callback/saml" && this.handleSamlRedirect(n);
15209
15212
  }
15210
- */
15211
15213
  },
15212
15214
  methods: {
15215
+ closeWindow() {
15216
+ try {
15217
+ window.close();
15218
+ } catch (n) {
15219
+ console.log("Window close error", n);
15220
+ }
15221
+ },
15213
15222
  async samlLogin(n) {
15214
15223
  this.code_verifier = Bn.generateRandomString(28), localStorage.setItem("pkce_code_verifier", this.code_verifier), this.code_challenge = await Bn.pkceChallengeFromVerifier(this.code_verifier);
15215
15224
  const e = Kn.getPlatform();
15216
- let t = `code_challenge=${this.code_challenge}&platform=${e}&redirect_uri=${location.origin + "/callback/saml"}&realm=${this.$storex.realm}`, r = btoa(t);
15225
+ let t = `code_challenge=${this.code_challenge}&platform=${e}&redirect_uri=${location.origin + "/callback/saml"}&realm=${this.realm}&display=${this.display}`, r = btoa(t);
15217
15226
  n = `${n}&RelayState=${r}`;
15218
15227
  let o = this;
15219
- window.addEventListener("message", async (i) => {
15220
- var a;
15221
- if (!this.allowedOriginsAuth.includes(i.origin)) return console.log("Origin is not allowed! " + i.origin);
15222
- if (i.data.type === "saml" && i.data.code) {
15223
- if (this.display === "popup")
15224
- return (a = window.parent) == null ? void 0 : a.postMessage({ code: i.data.code, state: this.$route.query.state, code_verifier: localStorage.getItem("pkce_code_verifier") }, "*");
15225
- await o.exchangeAuthCode({ code: i.data.code, code_verifier: localStorage.getItem("pkce_code_verifier") }), localStorage.removeItem("pkce_code_verifier");
15226
- }
15227
- }, { once: !0 }), this.isNative ? await fr.open({ url: n, presentationStyle: "popover" }) : window.open(n, "popup", "width=600,height=600");
15228
+ window.addEventListener(
15229
+ "message",
15230
+ async (i) => {
15231
+ var a;
15232
+ if (!this.allowedOriginsAuth.includes(i.origin)) return console.log("Origin is not allowed! " + i.origin);
15233
+ if (i.data.code) {
15234
+ if (console.log("post message from opener", i.data, o.display), o.display === "popup")
15235
+ return (a = window.parent) == null ? void 0 : a.postMessage({ code: i.data.code, state: i.data.state, code_verifier: localStorage.getItem("pkce_code_verifier") }, "*");
15236
+ await o.exchangeAuthCode({ code: i.data.code, code_verifier: localStorage.getItem("pkce_code_verifier") }), localStorage.removeItem("pkce_code_verifier");
15237
+ }
15238
+ },
15239
+ { once: !0 }
15240
+ ), this.isNative ? this.popupWindow = await fr.open({ url: n, presentationStyle: "popover" }) : (this.checkInterval = setInterval(() => {
15241
+ var s;
15242
+ const i = localStorage.getItem("auth_code"), a = localStorage.getItem("pkce_code_verifier");
15243
+ console.log("interval", i, a), i && (clearInterval(this.checkInterval), localStorage.removeItem("auth_code"), localStorage.removeItem("pkce_code_verifier"), (s = window.parent) == null || s.postMessage({ code: i, state: this.$route.query.state, code_verifier: a }, "*"));
15244
+ }, 500), this.popupWindow = window.open(window.location.origin + "/callback/redirect?uri=" + btoa(n), "popup", "width=600,height=600")), this.popupWindow && this.popupWindow.addEventListener("beforeunload", () => {
15245
+ console.log("popup window closed");
15246
+ });
15228
15247
  },
15229
15248
  async handleSamlRedirect() {
15230
- var t;
15231
- let n, e = { type: "saml" };
15232
- if (this.$route.query.code && (e.code = this.$route.query.code), window.opener)
15233
- window.opener.postMessage(e, location.origin), window.close();
15249
+ var e;
15250
+ let n;
15251
+ if (this.$route.query.code && (n = this.$route.query.code), console.log("window1", window.opener), console.log("window2", window.parent), window.opener)
15252
+ window.opener.postMessage({ type: "saml", code: n }, "*"), this.closeWindow();
15234
15253
  else {
15235
- if (this.isNative && this.isiOS && await fr.close(), Y.$emit("ssoEvent", { name: "setLoading", data: !0 }), this.$route.query.code && (n = this.$route.query.code), console.log(this.display, { code: n }), n) {
15236
- if (this.display === "popup")
15237
- return (t = window.parent) == null ? void 0 : t.postMessage({ code: n, state: this.$route.query.state }, "*");
15254
+ if (this.isNative && this.isiOS && await fr.close(), Y.$emit("ssoEvent", { name: "setLoading", data: !0 }), console.log(this.display, { code: n }, window.parent, window.opener), n) {
15255
+ if (this.display === "popup" && (localStorage.setItem("auth_code", n), this.shouldCloseWindow = !0, (e = window.parent) == null || e.postMessage({ code: n, state: this.$route.query.state }, "*"), this.closeWindow()), this.display === "redirect" || location.host === "auth.tapni.com") {
15256
+ let t = "https://auth.tapni.com/callback/auth";
15257
+ return this.realm === "dashboard" && (t = "https://business.tapni.com/login"), location.href = t + "?code=" + n + "&code_verifier=" + localStorage.getItem("pkce_code_verifier");
15258
+ }
15238
15259
  await this.exchangeAuthCode({ code: n, code_verifier: localStorage.getItem("pkce_code_verifier") });
15239
15260
  }
15240
- localStorage.removeItem("pkce_code_verifier"), Y.$emit("ssoEvent", { name: "setLoading", data: !1 });
15261
+ Y.$emit("ssoEvent", { name: "setLoading", data: !1 });
15241
15262
  }
15242
15263
  }
15243
15264
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapni/auth",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "type": "module",
5
5
  "main": "./dist/TapniAuth.umd.js",
6
6
  "module": "./dist/TapniAuth.es.js",
@@ -6,21 +6,30 @@ export default {
6
6
  data () {
7
7
  return {
8
8
  code_verifier: '',
9
- code_challenge: ''
10
- }
9
+ code_challenge: '',
10
+ shouldCloseWindow: false,
11
+ popupWindow: null,
12
+ checkInterval: null
13
+ };
11
14
  },
12
15
  computed: {
13
16
  },
14
17
  watch: {
15
- /*
16
- '$route.path': async function(routePath) {
17
- await this.handleSamlRedirect(routePath)
18
+ '$route.path' (nv) {
19
+ if (nv === '/callback/saml') {
20
+ this.handleSamlRedirect(nv)
21
+ }
18
22
  }
19
- */
20
23
  },
21
24
  methods: {
22
- async samlLogin (loginUrl) {
23
-
25
+ closeWindow() {
26
+ try {
27
+ window.close()
28
+ } catch (e) {
29
+ console.log('Window close error', e);
30
+ }
31
+ },
32
+ async samlLogin(loginUrl) {
24
33
  // Create and store a new PKCE code_verifier (the plaintext random secret)
25
34
  this.code_verifier = UtilService.generateRandomString(28);
26
35
  localStorage.setItem("pkce_code_verifier", this.code_verifier);
@@ -31,57 +40,98 @@ export default {
31
40
  const platform = Capacitor.getPlatform();
32
41
 
33
42
  // append public key as relayState
34
- let dataString = `code_challenge=${this.code_challenge}&platform=${platform}&redirect_uri=${(location.origin + '/callback/saml')}&realm=${this.$storex.realm}`;
43
+ let dataString = `code_challenge=${this.code_challenge}&platform=${platform}&redirect_uri=${location.origin + '/callback/saml'}&realm=${this.realm}&display=${this.display}`;
35
44
  let relayState = btoa(dataString);
36
45
 
37
46
  loginUrl = `${loginUrl}&RelayState=${relayState}`
38
47
 
39
48
  let self = this;
40
49
 
41
- window.addEventListener("message", async (message)=> {
42
- if (!this.allowedOriginsAuth.includes(message.origin)) return console.log('Origin is not allowed! ' + message.origin);
43
- if(message.data.type === 'saml' && message.data.code) {
44
- if (this.display === 'popup') {
45
- return window.parent?.postMessage({ code: message.data.code, state: this.$route.query.state, code_verifier: localStorage.getItem("pkce_code_verifier") }, '*');
50
+ window.addEventListener(
51
+ 'message',
52
+ async (message) => {
53
+ if (!this.allowedOriginsAuth.includes(message.origin)) return console.log('Origin is not allowed! ' + message.origin);
54
+ if (message.data.code) {
55
+ console.log('post message from opener', message.data, self.display);
56
+
57
+ if (self.display === 'popup') {
58
+ return window.parent?.postMessage({ code: message.data.code, state: message.data.state, code_verifier: localStorage.getItem('pkce_code_verifier') }, '*');
59
+ }
60
+ await self.exchangeAuthCode({ code: message.data.code, code_verifier: localStorage.getItem('pkce_code_verifier') });
61
+ localStorage.removeItem('pkce_code_verifier');
46
62
  }
47
- await self.exchangeAuthCode({code: message.data.code, code_verifier: localStorage.getItem("pkce_code_verifier")});
48
- localStorage.removeItem("pkce_code_verifier");
49
- }
50
- }, { once: true });
63
+ },
64
+ { once: true }
65
+ );
66
+
67
+ if (this.isNative) {
68
+ this.popupWindow = await Browser.open({ url: loginUrl, presentationStyle: 'popover' });
69
+ } else {
70
+ this.checkInterval = setInterval(() => {
71
+ // check localStorage
72
+ const code = localStorage.getItem('auth_code');
73
+ const pkce = localStorage.getItem('pkce_code_verifier');
51
74
 
52
- let popupWindow;
53
- if(this.isNative) {
54
- popupWindow = await Browser.open({ url: loginUrl, presentationStyle: 'popover'});
75
+ console.log('interval', code, pkce);
76
+
77
+ if (code) {
78
+ clearInterval(this.checkInterval);
79
+ localStorage.removeItem('auth_code');
80
+ localStorage.removeItem('pkce_code_verifier');
81
+
82
+ // handle code exchange
83
+ window.parent?.postMessage({ code: code, state: this.$route.query.state, code_verifier: pkce }, '*');
84
+
85
+ // attempt to close child if possible
86
+ // if (this.popupWindow?.closed === false) this.popupWindow.close();
87
+ }
88
+ }, 500);
89
+
90
+ this.popupWindow = window.open(window.location.origin + '/callback/redirect?uri=' + btoa(loginUrl), 'popup', 'width=600,height=600');
55
91
  }
56
- else popupWindow = window.open(loginUrl, 'popup','width=600,height=600')
57
- /*
58
- popupWindow.addEventListener('beforeunload', () => {
59
- console.log('window closed')
60
- })
61
- */
92
+
93
+ if (this.popupWindow) {
94
+ this.popupWindow.addEventListener('beforeunload', () => {
95
+ console.log('popup window closed');
96
+ })
97
+ }
98
+
62
99
  },
63
100
  async handleSamlRedirect() {
64
101
  let code;
65
- let postMessageData = {type: 'saml'}
66
- if (this.$route.query.code) postMessageData.code = this.$route.query.code;
67
- if(window.opener) {
68
- window.opener.postMessage(postMessageData, location.origin);
69
- window.close()
102
+ if (this.$route.query.code) {
103
+ code = this.$route.query.code
104
+ }
105
+ console.log('window1', window.opener);
106
+ console.log('window2', window.parent);
107
+ if (window.opener) {
108
+ window.opener.postMessage({ type: 'saml', code }, '*');
109
+ this.closeWindow();
70
110
  } else {
71
- if(this.isNative && this.isiOS) await Browser.close();
72
- EventBus.$emit('ssoEvent', {name: 'setLoading', data: true})
73
- if (this.$route.query.code) code = this.$route.query.code
111
+ if (this.isNative && this.isiOS) await Browser.close();
112
+ EventBus.$emit('ssoEvent', { name: 'setLoading', data: true });
74
113
 
75
- console.log(this.display, {code});
114
+ console.log(this.display, { code }, window.parent, window.opener);
76
115
 
77
116
  if (code) {
78
117
  if (this.display === 'popup') {
79
- return window.parent?.postMessage({ code: code, state: this.$route.query.state }, '*');
118
+ localStorage.setItem('auth_code', code);
119
+ this.shouldCloseWindow = true;
120
+ window.parent?.postMessage({ code: code, state: this.$route.query.state }, '*');
121
+ this.closeWindow()
122
+ }
123
+ // TODO: Replace URLs with .env variables to support staging
124
+ if (this.display === 'redirect' || location.host === 'auth.tapni.com') {
125
+ let redirect_url = 'https://auth.tapni.com/callback/auth';
126
+ if (this.realm === 'dashboard') {
127
+ redirect_url = 'https://business.tapni.com/login'
128
+ }
129
+ return location.href = redirect_url + '?code=' + code + '&code_verifier=' + localStorage.getItem('pkce_code_verifier');
80
130
  }
81
- await this.exchangeAuthCode({code, code_verifier: localStorage.getItem("pkce_code_verifier")});
131
+ await this.exchangeAuthCode({ code, code_verifier: localStorage.getItem('pkce_code_verifier') });
82
132
  }
83
- localStorage.removeItem("pkce_code_verifier");
84
- EventBus.$emit('ssoEvent', {name: 'setLoading', data: false})
133
+ // localStorage.removeItem('pkce_code_verifier');
134
+ EventBus.$emit('ssoEvent', { name: 'setLoading', data: false });
85
135
  }
86
136
  }
87
137
  },
package/src/store/auth.js CHANGED
@@ -64,6 +64,7 @@ export default {
64
64
  "https://designer-dev.tapni.com",
65
65
  "http://localhost:8082",
66
66
  "http://localhost:7777",
67
+ "https://localhost:7777",
67
68
  "http://localhost:8086",
68
69
  "https://localhost:8085",
69
70
  "http://localhost:8085"