@tapni/auth 0.0.54 → 0.0.56
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.
- package/dist/TapniAuth.es.js +189 -197
- package/dist/TapniAuth.umd.js +3 -3
- package/package.json +1 -1
- package/src/install.js +3 -7
- package/src/mixins/auth.mixin.js +11 -15
- package/src/services/Api.js +58 -50
- package/src/services/AuthService.js +22 -20
- package/src/services/CompanyService.js +5 -4
- package/src/services/DeviceService.js +4 -3
- package/src/services/UserService.js +12 -11
- package/src/views/Callback.vue +0 -1
- package/.vscode/extensions.json +0 -3
package/package.json
CHANGED
package/src/install.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import App from "./App.vue";
|
|
2
2
|
import ReactiveStorage from '@tapni/capacitor-reactive-localstorage-vue3'
|
|
3
|
+
import Api from './services/Api'
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
// Export the component by default
|
|
5
7
|
export default {
|
|
6
8
|
TapniAuth: App,
|
|
7
9
|
install: (app, options) => {
|
|
8
|
-
if (options && options.API_ROOT)
|
|
9
|
-
app.mixin({
|
|
10
|
-
created() {
|
|
11
|
-
this.API_ROOT = options.API_ROOT;
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
}
|
|
10
|
+
if (options && options.API_ROOT) Api.setApiRootFromOptions(options.API_ROOT);
|
|
15
11
|
app.component('TapniAuth', App);
|
|
16
12
|
}
|
|
17
13
|
};
|
package/src/mixins/auth.mixin.js
CHANGED
|
@@ -94,9 +94,6 @@ export default {
|
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
methods: {
|
|
97
|
-
apiRootGet(){
|
|
98
|
-
return this.API_ROOT;
|
|
99
|
-
},
|
|
100
97
|
errorHandler(error) {
|
|
101
98
|
if (
|
|
102
99
|
error &&
|
|
@@ -283,7 +280,7 @@ export default {
|
|
|
283
280
|
this.redirect_uri.startsWith(domain)
|
|
284
281
|
)
|
|
285
282
|
) {
|
|
286
|
-
return console.
|
|
283
|
+
return console.error("Redirect URI not allowed");
|
|
287
284
|
}
|
|
288
285
|
|
|
289
286
|
location.href = this.redirect_uri +
|
|
@@ -331,13 +328,8 @@ export default {
|
|
|
331
328
|
}
|
|
332
329
|
},
|
|
333
330
|
async exchangeAuthCode(data) {
|
|
334
|
-
console.log({data});
|
|
335
331
|
const [err, response] = await to(AuthService.exchangeAuthCode(data, this.$storage));
|
|
336
|
-
if (err)
|
|
337
|
-
console.log({err});
|
|
338
|
-
return this.errorHandler(err);
|
|
339
|
-
}
|
|
340
|
-
console.log(response);
|
|
332
|
+
if (err) return this.errorHandler(err);
|
|
341
333
|
await this.loginSetup(response);
|
|
342
334
|
await this.getLoggedInAccounts();
|
|
343
335
|
this.loginSuccess(response);
|
|
@@ -403,9 +395,11 @@ export default {
|
|
|
403
395
|
AuthService.logout({ token: this.refreshToken }, this.$storage);
|
|
404
396
|
}
|
|
405
397
|
|
|
406
|
-
this.$storage
|
|
407
|
-
|
|
408
|
-
|
|
398
|
+
if (this.$storage) {
|
|
399
|
+
this.$storage.username = '';
|
|
400
|
+
this.$storage.ssoUser = '';
|
|
401
|
+
this.$storage.UserId = '';
|
|
402
|
+
}
|
|
409
403
|
this.setLoggedInUserId('');
|
|
410
404
|
this.setToken('');
|
|
411
405
|
this.setRefreshToken('');
|
|
@@ -419,8 +413,10 @@ export default {
|
|
|
419
413
|
id: this.loggedInAccounts[username].id,
|
|
420
414
|
}).then(() => {
|
|
421
415
|
this.setLoggedInUserId(this.loggedInAccounts[username].id);
|
|
422
|
-
this.$storage
|
|
423
|
-
|
|
416
|
+
if (this.$storage) {
|
|
417
|
+
this.$storage.username = username;
|
|
418
|
+
this.$storage.UserId = this.loggedInAccounts[username].id;
|
|
419
|
+
}
|
|
424
420
|
this.getLoggedInAccounts();
|
|
425
421
|
return this.$router.push("/" + username);
|
|
426
422
|
});
|
package/src/services/Api.js
CHANGED
|
@@ -3,64 +3,72 @@ import { jwtDecode } from "jwt-decode";
|
|
|
3
3
|
import { version } from "../../package.json"
|
|
4
4
|
import AuthMixin from "../mixins/auth.mixin"
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
const appInfo = version;
|
|
8
|
-
let baseURL = import.meta.env.VITE_APP_API_ROOT + '/v1/';
|
|
6
|
+
let apiRootFromOptions;
|
|
9
7
|
|
|
10
|
-
const apiRoot = AuthMixin.methods.apiRootGet();
|
|
11
|
-
if (apiRoot) {
|
|
12
|
-
baseURL = apiRoot
|
|
13
|
-
}
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"X-Client-Version": appInfo.version
|
|
21
|
-
}
|
|
22
|
-
})
|
|
9
|
+
export default {
|
|
10
|
+
setApiRootFromOptions(apiRoot) {
|
|
11
|
+
apiRootFromOptions = apiRoot
|
|
12
|
+
},
|
|
13
|
+
instance(storage, refreshTokenAction = false) {
|
|
23
14
|
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
const appInfo = version;
|
|
16
|
+
let baseURL = import.meta.env.VITE_APP_API_ROOT + '/v1/';
|
|
26
17
|
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
if (apiRootFromOptions) {
|
|
19
|
+
baseURL = apiRootFromOptions;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let apiInstance = axios.create({
|
|
23
|
+
baseURL,
|
|
24
|
+
headers: {
|
|
25
|
+
...(storage ? { Authorization: `Bearer ${storage.token}` } : {}),
|
|
26
|
+
"X-Client-Name": "sso-" + appInfo.platform,
|
|
27
|
+
"X-Client-Version": appInfo.version
|
|
34
28
|
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// Add a request interceptor
|
|
32
|
+
apiInstance.interceptors.request.use(async function (config) {
|
|
33
|
+
|
|
34
|
+
if (['post', 'put', 'delete'].includes(config.method.toLowerCase())) {
|
|
35
|
+
config.data = {
|
|
36
|
+
...config.data,
|
|
37
|
+
...(storage ? {
|
|
38
|
+
lang: storage.appLanguage,
|
|
39
|
+
realm: storage.realm || 'app'
|
|
40
|
+
} : {}),
|
|
41
|
+
}
|
|
42
|
+
} else if (config.method.toLowerCase() === 'get') {
|
|
43
|
+
config.params = {
|
|
44
|
+
...config.params,
|
|
45
|
+
...(storage ? {
|
|
46
|
+
lang: storage.appLanguage,
|
|
47
|
+
realm: storage.realm || 'app'
|
|
48
|
+
} : {}),
|
|
49
|
+
}
|
|
42
50
|
}
|
|
43
|
-
}
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
// Check refresh token expiration before request is sent
|
|
53
|
+
if (storage && storage.token && !refreshTokenAction) {
|
|
54
|
+
const decoded = jwtDecode(storage.token)
|
|
48
55
|
|
|
49
|
-
|
|
50
|
-
|
|
56
|
+
// Check if access token expired
|
|
57
|
+
if (decoded.exp - 30 < Math.floor(Date.now() / 1000)) {
|
|
51
58
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
return AuthMixin.methods.refreshTokenAction(decoded)
|
|
60
|
+
.then(() => {
|
|
61
|
+
config.headers = {
|
|
62
|
+
...config.headers,
|
|
63
|
+
Authorization: `Bearer ${storage.token}`
|
|
64
|
+
}
|
|
65
|
+
return config;
|
|
66
|
+
})
|
|
67
|
+
}
|
|
60
68
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
69
|
+
return config;
|
|
70
|
+
});
|
|
64
71
|
|
|
65
|
-
|
|
66
|
-
}
|
|
72
|
+
return apiInstance;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -1,74 +1,76 @@
|
|
|
1
|
-
import Api from './Api'
|
|
1
|
+
import Api from './Api';
|
|
2
2
|
import { Device } from '@capacitor/device';
|
|
3
|
-
|
|
3
|
+
const api = Api.instance;
|
|
4
|
+
|
|
4
5
|
let deviceID;
|
|
5
6
|
Device.getId().then((DeviceId)=> deviceID = DeviceId.uuid)
|
|
7
|
+
|
|
6
8
|
export default {
|
|
7
9
|
register (data, storage) {
|
|
8
10
|
data.device_id = deviceID
|
|
9
|
-
return
|
|
11
|
+
return api(storage).post('/users/register', data)
|
|
10
12
|
},
|
|
11
13
|
login (data, storage) {
|
|
12
14
|
data.device_id = deviceID
|
|
13
|
-
return
|
|
15
|
+
return api(storage).post('/users/login', data)
|
|
14
16
|
},
|
|
15
17
|
logout (data, storage) {
|
|
16
18
|
data.device_id = deviceID
|
|
17
|
-
return
|
|
19
|
+
return api(storage).post('/users/logout', data)
|
|
18
20
|
},
|
|
19
21
|
refreshToken (data, storage) {
|
|
20
|
-
return
|
|
22
|
+
return api(storage, true).get(`/users/refresh-token?UserId=${data.id}&token=${data.refreshToken}`)
|
|
21
23
|
},
|
|
22
24
|
getLoggedInAccounts(data, storage) {
|
|
23
|
-
return
|
|
25
|
+
return api(storage).post(`/users/tokens`, data);
|
|
24
26
|
},
|
|
25
27
|
sendResetEmail (data, storage) {
|
|
26
28
|
data.device_id = deviceID
|
|
27
|
-
return
|
|
29
|
+
return api(storage).post('/users/reset', data)
|
|
28
30
|
},
|
|
29
31
|
changePassword (data, storage) {
|
|
30
|
-
return
|
|
32
|
+
return api(storage).put('/users/password', data, {
|
|
31
33
|
headers: { Authorization: 'Bearer ' + data.token }
|
|
32
34
|
})
|
|
33
35
|
},
|
|
34
36
|
verify (data, storage) {
|
|
35
|
-
return
|
|
37
|
+
return api(storage).get('/users/verify?c=' + data.code + '&e=' + data.email + '&captchatoken=' + data.captchaToken)
|
|
36
38
|
},
|
|
37
39
|
googleUrl (storage) {
|
|
38
|
-
return
|
|
40
|
+
return api(storage).get('/users/google/url')
|
|
39
41
|
},
|
|
40
42
|
google (data, storage) {
|
|
41
43
|
data.device_id = deviceID
|
|
42
|
-
return
|
|
44
|
+
return api(storage).post('/users/google', data)
|
|
43
45
|
},
|
|
44
46
|
facebook (data, storage) {
|
|
45
47
|
data.device_id = deviceID
|
|
46
|
-
return
|
|
48
|
+
return api(storage).post('/users/facebook', data)
|
|
47
49
|
},
|
|
48
50
|
googleSDK (data, storage) {
|
|
49
51
|
data.device_id = deviceID
|
|
50
|
-
return
|
|
52
|
+
return api(storage).post('/users/google/sdk', data)
|
|
51
53
|
},
|
|
52
54
|
facebookSDK (data, storage) {
|
|
53
55
|
data.device_id = deviceID
|
|
54
|
-
return
|
|
56
|
+
return api(storage).post('/users/facebook/sdk', data)
|
|
55
57
|
},
|
|
56
58
|
appleSDK (data, storage) {
|
|
57
59
|
data.device_id = deviceID
|
|
58
|
-
return
|
|
60
|
+
return api(storage).post('/users/apple/sdk', data)
|
|
59
61
|
},
|
|
60
62
|
microsoftSDK (data, storage) {
|
|
61
63
|
data.device_id = deviceID
|
|
62
|
-
return
|
|
64
|
+
return api(storage).post('/users/microsoft/sdk', data)
|
|
63
65
|
},
|
|
64
66
|
oktaSDK (data, storage) {
|
|
65
67
|
data.device_id = deviceID
|
|
66
|
-
return
|
|
68
|
+
return api(storage).post('/users/okta/sdk', data)
|
|
67
69
|
},
|
|
68
70
|
samlLoginUrl (data, storage) {
|
|
69
|
-
return
|
|
71
|
+
return api(storage).post('/saml/url', data)
|
|
70
72
|
},
|
|
71
73
|
exchangeAuthCode (data, storage) {
|
|
72
|
-
return
|
|
74
|
+
return api(storage).post('/users/auth-code', data)
|
|
73
75
|
},
|
|
74
76
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import Api from './Api'
|
|
1
|
+
import Api from './Api';
|
|
2
|
+
const api = Api.instance;
|
|
2
3
|
|
|
3
4
|
export default {
|
|
4
5
|
getBySSOEmail (email, storage) {
|
|
5
|
-
return
|
|
6
|
+
return api(storage).get(`/company/sso/${email}`)
|
|
6
7
|
},
|
|
7
8
|
acceptCompanyInvitation (code, storage) {
|
|
8
|
-
return
|
|
9
|
+
return api(storage).get(`/users/invitation?ic=${code}`)
|
|
9
10
|
},
|
|
10
11
|
qrCodePooling(payload, storage) {
|
|
11
|
-
return
|
|
12
|
+
return api(storage).post("/company/login/qr", payload);
|
|
12
13
|
},
|
|
13
14
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import Api from './Api'
|
|
1
|
+
import Api from './Api';
|
|
2
|
+
const api = Api.instance;
|
|
2
3
|
|
|
3
4
|
export default {
|
|
4
5
|
registerDevice(data, storage) {
|
|
5
|
-
return
|
|
6
|
+
return api(storage).post(`/devices/add`, data)
|
|
6
7
|
},
|
|
7
8
|
addFcmToken(data, storage) {
|
|
8
|
-
return
|
|
9
|
+
return api(storage).post(`/devices/fcm/add`, data)
|
|
9
10
|
}
|
|
10
11
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import Api from
|
|
1
|
+
import Api from './Api';
|
|
2
|
+
const api = Api.instance;
|
|
2
3
|
|
|
3
4
|
export default {
|
|
4
5
|
getMe() {
|
|
@@ -8,7 +9,7 @@ export default {
|
|
|
8
9
|
let referrer = document.referrer || "";
|
|
9
10
|
let params = data.utmParams || {};
|
|
10
11
|
if (data.dontTap) params.dontTap = true;
|
|
11
|
-
return
|
|
12
|
+
return api(storage).get(`/users/${data.username}`, {
|
|
12
13
|
params,
|
|
13
14
|
headers: { "X-Referer": referrer },
|
|
14
15
|
});
|
|
@@ -17,33 +18,33 @@ export default {
|
|
|
17
18
|
let referrer = document.referrer || "";
|
|
18
19
|
let params = data.utmParams || {};
|
|
19
20
|
if (data.dontTap) params.dontTap = true;
|
|
20
|
-
return
|
|
21
|
+
return api(storage).get(`/users/tag/${data.serial}`, {
|
|
21
22
|
params,
|
|
22
23
|
headers: { "X-Referer": referrer },
|
|
23
24
|
});
|
|
24
25
|
},
|
|
25
26
|
save(data, storage) {
|
|
26
|
-
return
|
|
27
|
+
return api(storage).put(`/users`, data);
|
|
27
28
|
},
|
|
28
29
|
newPassword(data, storage) {
|
|
29
|
-
return
|
|
30
|
+
return api(storage).put(`/users/new-password`, data);
|
|
30
31
|
},
|
|
31
32
|
connect(data, storage) {
|
|
32
|
-
return
|
|
33
|
+
return api(storage).post(`/users/connect`, data);
|
|
33
34
|
},
|
|
34
35
|
eventLog(data, storage) {
|
|
35
|
-
return
|
|
36
|
+
return api(storage).post(`/users/log`, data);
|
|
36
37
|
},
|
|
37
38
|
deleteAccount(data, storage) {
|
|
38
|
-
return
|
|
39
|
+
return api(storage).post(`/users/profile/delete`, data);
|
|
39
40
|
},
|
|
40
41
|
registerDevice(data, storage) {
|
|
41
|
-
return
|
|
42
|
+
return api(storage).post(`/users/device/register`, data);
|
|
42
43
|
},
|
|
43
44
|
addFcmToken(data, storage) {
|
|
44
|
-
return
|
|
45
|
+
return api(storage).post(`/users/device/fcm`, data);
|
|
45
46
|
},
|
|
46
47
|
loginUsingQR(data, storage) {
|
|
47
|
-
return
|
|
48
|
+
return api(storage).post("/users/qr/login", data);
|
|
48
49
|
}
|
|
49
50
|
};
|
package/src/views/Callback.vue
CHANGED
package/.vscode/extensions.json
DELETED