casdoor 1.3.0 → 1.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "casdoor",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
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
@@ -58,17 +58,32 @@ function getManagedAccounts(tabId) {
58
58
  });
59
59
  }
60
60
 
61
+ function testUrlWithRegex(url, regexPattern) {
62
+ try {
63
+ const regex = new RegExp(regexPattern);
64
+ const isMatched = regex.test(url);
65
+ console.log(`testUrlWithRegex(), url = ${url}, regexPattern = ${regexPattern}, isMatched = ${isMatched}`);
66
+ return isMatched;
67
+ } catch (error) {
68
+ alert(`testUrlWithRegex() error, the regex pattern: "${regexPattern}" is invalid`);
69
+ return false;
70
+ }
71
+ }
72
+
61
73
  async function autoLogin(tabId, url) {
62
74
  const managedAccounts = await getManagedAccounts(tabId);
63
75
  if (managedAccounts) {
64
76
  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;
77
+ if (managedAccount && managedAccount.signinUrl && url) {
78
+ const isMatched = testUrlWithRegex(url, managedAccount.signinUrl);
79
+ if (isMatched) {
80
+ autoLoginTabs.add(tabId);
81
+ chrome.tabs.sendMessage(tabId, {
82
+ action: "autoLogin",
83
+ managedAccount: managedAccount,
84
+ });
85
+ break;
86
+ }
72
87
  }
73
88
  }
74
89
  }
package/src/oauth.js CHANGED
@@ -119,9 +119,11 @@ let accessToken;
119
119
  let applicationName;
120
120
 
121
121
  function getDomAccessToken() {
122
- if(window.location.pathname != "/src/popup.html"){
123
- accessToken = document.getElementById("CasdoorAccessToken").getAttribute("value");
124
- applicationName = document.getElementById("CasdoorApplicationName").getAttribute("value");
122
+ const accessTokenDom = document.getElementById("CasdoorAccessToken")
123
+ const applicationNameDom = document.getElementById("CasdoorApplicationName")
124
+ if(window.location.pathname != "/src/popup.html" && accessTokenDom && applicationNameDom){
125
+ accessToken = accessTokenDom.getAttribute("value");
126
+ applicationName = applicationNameDom.getAttribute("value");
125
127
  if (accessToken && applicationName) {
126
128
  sdk.getUserProfile(accessToken).then((userProfile) => {
127
129
  userProfile.applicationName = applicationName;
package/src/sdk.js CHANGED
@@ -89,13 +89,18 @@ class Sdk {
89
89
  .catch((error) => console.error(error));
90
90
  }
91
91
 
92
- getAccountUrl() {
93
- const endpoint = this.config.endpoint;
94
- return `${endpoint}/api/get-account`;
92
+ async getAccountUrl() {
93
+ try {
94
+ const endpointData = await getStorageData("endpoint");
95
+ const endpoint = endpointData.endpoint;
96
+ return `${endpoint}/api/get-account`;
97
+ } catch (error) {
98
+ console.error('Error fetching endpoint:', error);
99
+ }
95
100
  }
96
101
 
97
- getAccount(accessToken) {
98
- const accountUrl = this.getAccountUrl();
102
+ async getAccount(accessToken) {
103
+ const accountUrl = await this.getAccountUrl();
99
104
  const requestConfig = {
100
105
  method: "GET",
101
106
  async: true,