@tapni/auth 1.0.11 → 1.0.13

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.11", cr = {
1400
+ }, Symbol.toStringTag, { value: "Module" })), fa = "1.0.12", 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-BxHBi2nV.js"), Ca = () => Promise.resolve().then(() => Cu), Ea = () => import("./Apps-D903yvip.js"), Ta = () => import("./Billing-CQp6b4tB.js"), Sa = () => import("./CustomApp-h6WA5um0.js"), Ia = () => import("./General-DA3IgC3X.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-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 = [
5567
5567
  {
5568
5568
  path: "/welcome",
5569
5569
  name: "AuthWelcome",
@@ -15218,7 +15218,7 @@ const xs = Ir("MsAuthPlugin", {
15218
15218
  let o = this;
15219
15219
  window.addEventListener("message", async (i) => {
15220
15220
  var a;
15221
- if (!this.allowedOriginsAuth.includes(i.origin)) return console.log("Origin is not allowed!");
15221
+ if (!this.allowedOriginsAuth.includes(i.origin)) return console.log("Origin is not allowed! " + i.origin);
15222
15222
  if (i.data.type === "saml" && i.data.code) {
15223
15223
  if (this.display === "popup")
15224
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") }, "*");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapni/auth",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
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!');
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('https://auth.tapni.com/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
  },