casdoor 1.0.2 → 1.1.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/.eslintrc.js +21 -5
- package/.releaserc.json +9 -9
- package/manifest.json +42 -36
- package/package.json +1 -1
- package/src/background.js +45 -0
- package/src/config.js +4 -0
- package/src/content-script.js +23 -14
- package/src/oauth.js +11 -11
- package/src/popup.html +29 -29
- package/src/popup.js +0 -4
- package/src/sdk.js +4 -3
package/.eslintrc.js
CHANGED
|
@@ -17,8 +17,14 @@ module.exports = {
|
|
|
17
17
|
"space-in-parens": ["error", "never"],
|
|
18
18
|
"object-curly-spacing": ["error", "never"],
|
|
19
19
|
"array-bracket-spacing": ["error", "never"],
|
|
20
|
-
"comma-spacing": ["error", {
|
|
21
|
-
|
|
20
|
+
"comma-spacing": ["error", {
|
|
21
|
+
before: false,
|
|
22
|
+
after: true
|
|
23
|
+
}],
|
|
24
|
+
"arrow-spacing": ["error", {
|
|
25
|
+
before: true,
|
|
26
|
+
after: true
|
|
27
|
+
}],
|
|
22
28
|
"space-before-blocks": ["error", "always"],
|
|
23
29
|
"spaced-comment": ["error", "always"],
|
|
24
30
|
"block-spacing": ["error", "never"],
|
|
@@ -43,11 +49,21 @@ module.exports = {
|
|
|
43
49
|
],
|
|
44
50
|
"no-multiple-empty-lines": [
|
|
45
51
|
"error",
|
|
46
|
-
{
|
|
52
|
+
{
|
|
53
|
+
max: 1,
|
|
54
|
+
maxBOF: 0,
|
|
55
|
+
maxEOF: 0
|
|
56
|
+
},
|
|
47
57
|
],
|
|
48
|
-
"space-unary-ops": ["error", {
|
|
58
|
+
"space-unary-ops": ["error", {
|
|
59
|
+
words: true,
|
|
60
|
+
nonwords: false
|
|
61
|
+
}],
|
|
49
62
|
"space-infix-ops": "error",
|
|
50
|
-
"key-spacing": ["error", {
|
|
63
|
+
"key-spacing": ["error", {
|
|
64
|
+
beforeColon: false,
|
|
65
|
+
afterColon: true
|
|
66
|
+
}],
|
|
51
67
|
"comma-style": ["error", "last"],
|
|
52
68
|
"comma-dangle": [
|
|
53
69
|
"error",
|
package/.releaserc.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
2
|
+
"debug": true,
|
|
3
|
+
"branches": "master",
|
|
4
|
+
"plugins": [
|
|
5
|
+
"@semantic-release/commit-analyzer",
|
|
6
|
+
"@semantic-release/release-notes-generator",
|
|
7
|
+
"@semantic-release/npm",
|
|
8
|
+
"@semantic-release/github"
|
|
9
|
+
]
|
|
10
|
+
}
|
package/manifest.json
CHANGED
|
@@ -1,40 +1,46 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"js": [
|
|
29
|
-
"/src/content-script.js",
|
|
30
|
-
"/src/sdk.js",
|
|
31
|
-
"/src/oauth.js",
|
|
32
|
-
"/src/config.js"
|
|
33
|
-
]
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
"host_permissions": [
|
|
2
|
+
"name": "Casdoor",
|
|
3
|
+
"description": "The Casdoor extension can help browser users automatically log into applications protected by Casdoor single-sign-on (SSO) system.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"manifest_version": 3,
|
|
6
|
+
"permissions": [
|
|
7
|
+
"storage",
|
|
8
|
+
"identity"
|
|
9
|
+
],
|
|
10
|
+
"action": {
|
|
11
|
+
"default_popup": "/src/popup.html",
|
|
12
|
+
"default_icon": {
|
|
13
|
+
"16": "/images/icon16.png",
|
|
14
|
+
"32": "/images/icon32.png",
|
|
15
|
+
"48": "/images/icon48.png",
|
|
16
|
+
"128": "/images/icon128.png"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"icons": {
|
|
20
|
+
"16": "/images/icon16.png",
|
|
21
|
+
"32": "/images/icon32.png",
|
|
22
|
+
"48": "/images/icon48.png",
|
|
23
|
+
"128": "/images/icon128.png"
|
|
24
|
+
},
|
|
25
|
+
"content_scripts": [
|
|
26
|
+
{
|
|
27
|
+
"matches": [
|
|
37
28
|
"https://*/*",
|
|
38
29
|
"http://*/*"
|
|
39
|
-
|
|
30
|
+
],
|
|
31
|
+
"js": [
|
|
32
|
+
"/src/content-script.js",
|
|
33
|
+
"/src/sdk.js",
|
|
34
|
+
"/src/oauth.js",
|
|
35
|
+
"/src/config.js"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"background": {
|
|
40
|
+
"service_worker": "/src/background.js"
|
|
41
|
+
},
|
|
42
|
+
"host_permissions": [
|
|
43
|
+
"https://*/*",
|
|
44
|
+
"http://*/*"
|
|
45
|
+
]
|
|
40
46
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "casdoor",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright 2024 The Casdoor Authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
let autoLoginTabs = new Set();
|
|
16
|
+
|
|
17
|
+
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
|
18
|
+
if (tab.url && tab.status === "complete" && !autoLoginTabs.has(tabId) ) {
|
|
19
|
+
const url = tab.url;
|
|
20
|
+
|
|
21
|
+
chrome.tabs.sendMessage(tabId, {action: "setManagedAccounts"},
|
|
22
|
+
function (managedAccounts) {
|
|
23
|
+
if (chrome.runtime.lastError) {
|
|
24
|
+
console.error("Error sending first message:", chrome.runtime.lastError);
|
|
25
|
+
} else if (managedAccounts) {
|
|
26
|
+
for (const managedAccount of managedAccounts) {
|
|
27
|
+
if (managedAccount && url.includes(managedAccount.signinUrl)) {
|
|
28
|
+
autoLoginTabs.add(tabId);
|
|
29
|
+
chrome.tabs.sendMessage(tabId, {
|
|
30
|
+
action: "autoLogin",
|
|
31
|
+
managedAccount: managedAccount,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function clearAutoLoginTabs() {
|
|
42
|
+
autoLoginTabs.clear();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setInterval(clearAutoLoginTabs, 10000);
|
package/src/config.js
CHANGED
|
@@ -15,8 +15,11 @@
|
|
|
15
15
|
const UsernameXpaths = [
|
|
16
16
|
"//input[contains(@id,'username')]",
|
|
17
17
|
"//input[contains(@name,'username')]",
|
|
18
|
+
"//input[contains(@name,'account')]",
|
|
19
|
+
"//input[contains(@name,'login')]",
|
|
18
20
|
"//input[contains(@placeholder,'username')]",
|
|
19
21
|
"//input[contains(@placeholder,'用户名')]",
|
|
22
|
+
"//input[contains(@placeholder,'账号')]",
|
|
20
23
|
"//input[contains(@id,'phone')]",
|
|
21
24
|
"//input[contains(@name,'phone')]",
|
|
22
25
|
"//input[contains(@placeholder,'phone')]",
|
|
@@ -37,6 +40,7 @@ const PasswordXpaths = [
|
|
|
37
40
|
|
|
38
41
|
const SubmitXpaths = [
|
|
39
42
|
"//button[@type='submit']",
|
|
43
|
+
"//input[contains(@name,'commit')]",
|
|
40
44
|
"//button[contains(string(),'Login')]",
|
|
41
45
|
"//button[contains(string(),'Sign in')]",
|
|
42
46
|
"//button[contains(string(),'登录')]",
|
package/src/content-script.js
CHANGED
|
@@ -94,18 +94,27 @@ window.onload = () => {
|
|
|
94
94
|
autoFillCasdoorConfig();
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
|
-
|
|
98
|
-
const url = window.location.href;
|
|
99
|
-
chrome.storage.sync.get("managedAccounts", ({managedAccounts}) => {
|
|
100
|
-
for (const managedAccount of managedAccounts) {
|
|
101
|
-
if (managedAccount.signinUrl === url) {
|
|
102
|
-
chrome.storage.sync.get("disableAutoLogin", ({disableAutoLogin}) => {
|
|
103
|
-
if (!disableAutoLogin) {
|
|
104
|
-
autoLogin(managedAccount.username, managedAccount.password);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
97
|
};
|
|
98
|
+
|
|
99
|
+
chrome.runtime.onMessage.addListener((message) => {
|
|
100
|
+
if (message.action === "autoLogin") {
|
|
101
|
+
chrome.storage.sync.get("disableAutoLogin", ({ disableAutoLogin }) => {
|
|
102
|
+
if (!disableAutoLogin) {
|
|
103
|
+
const managedAccount = message.managedAccount;
|
|
104
|
+
autoLogin(managedAccount.username, managedAccount.password);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
chrome.runtime.onMessage.addListener(function(message, sender,sendResponse) {
|
|
111
|
+
if (message.action === "setManagedAccounts") {
|
|
112
|
+
chrome.storage.sync.get("accessToken", ({accessToken}) => {
|
|
113
|
+
sdk.getAccount(accessToken).then((account) => {
|
|
114
|
+
const managedAccounts = account.data.managedAccounts;
|
|
115
|
+
sendResponse(managedAccounts);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
});
|
package/src/oauth.js
CHANGED
|
@@ -40,7 +40,7 @@ function login() {
|
|
|
40
40
|
.getUserProfile(accessToken)
|
|
41
41
|
.then((userProfile) => displayUserProfile(userProfile));
|
|
42
42
|
});
|
|
43
|
-
setInputDisabledState(true, "endpoint", "applicationName")
|
|
43
|
+
setInputDisabledState(true, "endpoint", "applicationName");
|
|
44
44
|
} else {
|
|
45
45
|
alert("Login failed!");
|
|
46
46
|
}
|
|
@@ -50,7 +50,7 @@ function login() {
|
|
|
50
50
|
// eslint-disable-next-line no-unused-vars
|
|
51
51
|
function logout() {
|
|
52
52
|
chrome.storage.sync.set({accessToken: ""}, () => clearUserProfile());
|
|
53
|
-
setInputDisabledState(false, "endpoint", "applicationName")
|
|
53
|
+
setInputDisabledState(false, "endpoint", "applicationName");
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
function displayUserProfile(userProfile) {
|
|
@@ -66,13 +66,13 @@ function clearUserProfile() {
|
|
|
66
66
|
document.getElementById("loginOrLogout").innerText = "Login";
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
function setInputDisabledState(disabledState, ...elementIds) {
|
|
70
|
-
elementIds.forEach(elementId => {
|
|
71
|
-
const inputElement = document.getElementById(elementId);
|
|
72
|
-
if (inputElement) {
|
|
73
|
-
inputElement.disabled = disabledState;
|
|
74
|
-
} else {
|
|
75
|
-
console.warn(`No element found with ID: ${elementId}`);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
69
|
+
function setInputDisabledState(disabledState, ...elementIds) {
|
|
70
|
+
elementIds.forEach(elementId => {
|
|
71
|
+
const inputElement = document.getElementById(elementId);
|
|
72
|
+
if (inputElement) {
|
|
73
|
+
inputElement.disabled = disabledState;
|
|
74
|
+
} else {
|
|
75
|
+
console.warn(`No element found with ID: ${elementId}`);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
78
|
}
|
package/src/popup.html
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html>
|
|
3
|
-
|
|
3
|
+
<head>
|
|
4
4
|
<link rel="stylesheet" href="popup.css">
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
</div>
|
|
14
|
-
<div class="item">
|
|
15
|
-
applicationName:
|
|
16
|
-
<input class="input" id="applicationName" name="applicationName" placeholder="your application name"/>
|
|
17
|
-
</div>
|
|
18
|
-
<div class="item">
|
|
19
|
-
Enable auto login:
|
|
20
|
-
<label class="switch">
|
|
21
|
-
<input type="checkbox" id="enableAutoLogin">
|
|
22
|
-
<span class="slider"></span>
|
|
23
|
-
</label>
|
|
24
|
-
</div>
|
|
25
|
-
<div class="control">
|
|
26
|
-
<button class="primary" id="loginOrLogout">Login</button>
|
|
27
|
-
</div>
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
<div class="background">
|
|
8
|
+
<h1 class="title" id="title">Casdoor</h1>
|
|
9
|
+
<div id="user"></div>
|
|
10
|
+
<div class="item">
|
|
11
|
+
endpoint:
|
|
12
|
+
<input class="input" id="endpoint" name="endpoint" placeholder="your casdoor server url"/>
|
|
28
13
|
</div>
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
14
|
+
<div class="item">
|
|
15
|
+
applicationName:
|
|
16
|
+
<input class="input" id="applicationName" name="applicationName" placeholder="your application name"/>
|
|
17
|
+
</div>
|
|
18
|
+
<div class="item">
|
|
19
|
+
Enable auto login:
|
|
20
|
+
<label class="switch">
|
|
21
|
+
<input type="checkbox" id="enableAutoLogin">
|
|
22
|
+
<span class="slider"></span>
|
|
23
|
+
</label>
|
|
24
|
+
</div>
|
|
25
|
+
<div class="control">
|
|
26
|
+
<button class="primary" id="loginOrLogout">Login</button>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
<script src="config.js"></script>
|
|
30
|
+
<script src="sdk.js"></script>
|
|
31
|
+
<script src="oauth.js"></script>
|
|
32
|
+
<script src="popup.js"></script>
|
|
33
|
+
</body>
|
|
34
34
|
</html>
|
package/src/popup.js
CHANGED
|
@@ -36,10 +36,6 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
|
36
36
|
sdk
|
|
37
37
|
.getUserProfile(accessToken)
|
|
38
38
|
.then((userProfile) => displayUserProfile(userProfile));
|
|
39
|
-
sdk.getAccount(accessToken).then((account) => {
|
|
40
|
-
const managedAccounts = account.data.managedAccounts;
|
|
41
|
-
chrome.storage.sync.set({managedAccounts});
|
|
42
|
-
});
|
|
43
39
|
setInputDisabledState(true, "endpoint", "applicationName")
|
|
44
40
|
} else {
|
|
45
41
|
clearUserProfile();
|
package/src/sdk.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
|
|
15
15
|
/* eslint-disable no-undef */
|
|
16
|
+
|
|
16
17
|
// eslint-disable-next-line no-unused-vars
|
|
17
18
|
class Sdk {
|
|
18
19
|
constructor(config) {
|
|
@@ -38,8 +39,8 @@ class Sdk {
|
|
|
38
39
|
|
|
39
40
|
getAccessTokenFromRedirectUrl(redirectUrl) {
|
|
40
41
|
if (redirectUrl) {
|
|
41
|
-
const accessTokenMatch
|
|
42
|
-
const accessToken = accessTokenMatch ? accessTokenMatch[1] : "";
|
|
42
|
+
const accessTokenMatch = redirectUrl.match(/#access_token=([^&]*)/);
|
|
43
|
+
const accessToken = accessTokenMatch ? accessTokenMatch[1] : "";
|
|
43
44
|
return accessToken;
|
|
44
45
|
}
|
|
45
46
|
return "";
|
|
@@ -90,7 +91,7 @@ class Sdk {
|
|
|
90
91
|
|
|
91
92
|
getAccountUrl() {
|
|
92
93
|
const endpoint = this.config.endpoint;
|
|
93
|
-
return `${endpoint}/api/get-account
|
|
94
|
+
return `${endpoint}/api/get-account`;
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
getAccount(accessToken) {
|