casdoor 1.1.0 → 1.2.0
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/README.md +4 -0
- package/img/demo.gif +0 -0
- package/package.json +1 -1
- package/src/background.js +74 -22
- package/src/content-script.js +25 -7
package/README.md
CHANGED
package/img/demo.gif
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "casdoor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "The Casdoor extension can help browser users automatically log into applications protected by Casdoor single-sign-on (SSO) system.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"semantic-release": "semantic-release"
|
package/src/background.js
CHANGED
|
@@ -14,32 +14,84 @@
|
|
|
14
14
|
|
|
15
15
|
let autoLoginTabs = new Set();
|
|
16
16
|
|
|
17
|
-
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
|
18
|
-
if (tab.url && tab.status === "complete"
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
|
|
18
|
+
if (tab.url && tab.status === "complete") {
|
|
19
|
+
const [UserLoggedIn, DisableAutoLogin] = await Promise.all([
|
|
20
|
+
isUserLoggedIn(tabId),
|
|
21
|
+
isDisableAutoLogin(tabId),
|
|
22
|
+
]);
|
|
23
|
+
if (UserLoggedIn && !DisableAutoLogin && !autoLoginTabs.has(tabId)) {
|
|
24
|
+
autoLogin(tabId, tab.url);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
async function isUserLoggedIn(tabId) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
chrome.tabs.sendMessage(
|
|
32
|
+
tabId,
|
|
33
|
+
{ action: "isUserLoggedIn" },
|
|
34
|
+
function (UserLoggedIn) {
|
|
35
|
+
if (chrome.runtime.lastError) {
|
|
36
|
+
reject(chrome.runtime.lastError.message);
|
|
37
|
+
} else {
|
|
38
|
+
resolve(UserLoggedIn);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getManagedAccounts(tabId) {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
chrome.tabs.sendMessage(
|
|
48
|
+
tabId,
|
|
49
|
+
{ action: "getManagedAccounts" },
|
|
22
50
|
function (managedAccounts) {
|
|
23
51
|
if (chrome.runtime.lastError) {
|
|
24
|
-
|
|
25
|
-
} else
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
reject(chrome.runtime.lastError.message);
|
|
53
|
+
} else {
|
|
54
|
+
resolve(managedAccounts);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function autoLogin(tabId, url) {
|
|
62
|
+
const managedAccounts = await getManagedAccounts(tabId);
|
|
63
|
+
if (managedAccounts) {
|
|
64
|
+
for (const managedAccount of managedAccounts) {
|
|
65
|
+
if (managedAccount && url.includes(managedAccount.signinUrl)) {
|
|
66
|
+
autoLoginTabs.add(tabId);
|
|
67
|
+
chrome.tabs.sendMessage(tabId, {
|
|
68
|
+
action: "autoLogin",
|
|
69
|
+
managedAccount: managedAccount,
|
|
70
|
+
});
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isDisableAutoLogin(tabId) {
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
chrome.tabs.sendMessage(
|
|
80
|
+
tabId,
|
|
81
|
+
{ action: "isDisableAutoLogin" },
|
|
82
|
+
function (DisableAutoLogin) {
|
|
83
|
+
if (chrome.runtime.lastError) {
|
|
84
|
+
reject(chrome.runtime.lastError);
|
|
85
|
+
} else {
|
|
86
|
+
resolve(DisableAutoLogin);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
40
92
|
|
|
41
93
|
function clearAutoLoginTabs() {
|
|
42
94
|
autoLoginTabs.clear();
|
|
43
95
|
}
|
|
44
96
|
|
|
45
|
-
setInterval(clearAutoLoginTabs, 10000);
|
|
97
|
+
setInterval(clearAutoLoginTabs, 10000);
|
package/src/content-script.js
CHANGED
|
@@ -98,17 +98,35 @@ window.onload = () => {
|
|
|
98
98
|
|
|
99
99
|
chrome.runtime.onMessage.addListener((message) => {
|
|
100
100
|
if (message.action === "autoLogin") {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
const managedAccount = message.managedAccount;
|
|
102
|
+
autoLogin(managedAccount.username, managedAccount.password);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
107
|
+
if (message.action === "isUserLoggedIn") {
|
|
108
|
+
chrome.storage.sync.get("accessToken", ({accessToken}) => {
|
|
109
|
+
if(accessToken){
|
|
110
|
+
sendResponse(true);
|
|
111
|
+
} else{
|
|
112
|
+
sendResponse(false);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
120
|
+
if (message.action === "isDisableAutoLogin") {
|
|
121
|
+
chrome.storage.sync.get("disableAutoLogin", ({ disableAutoLogin }) => {
|
|
122
|
+
sendResponse(disableAutoLogin);
|
|
123
|
+
});
|
|
124
|
+
return true;
|
|
107
125
|
}
|
|
108
126
|
});
|
|
109
127
|
|
|
110
128
|
chrome.runtime.onMessage.addListener(function(message, sender,sendResponse) {
|
|
111
|
-
if (message.action === "
|
|
129
|
+
if (message.action === "getManagedAccounts") {
|
|
112
130
|
chrome.storage.sync.get("accessToken", ({accessToken}) => {
|
|
113
131
|
sdk.getAccount(accessToken).then((account) => {
|
|
114
132
|
const managedAccounts = account.data.managedAccounts;
|