casdoor 1.2.0 → 1.2.1

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/manifest.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
- "name": "Casdoor",
3
- "description": "The Casdoor extension can help browser users automatically log into applications protected by Casdoor single-sign-on (SSO) system.",
2
+ "name": "Casdoor Browser Plugin",
3
+ "description": "Casdoor Browser Plugin can help the users automatically log into applications protected by Casdoor identity provider.",
4
4
  "version": "1.0.0",
5
5
  "manifest_version": 3,
6
6
  "permissions": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "casdoor",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
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/oauth.js CHANGED
@@ -29,22 +29,57 @@ chrome.storage.sync.get("endpoint", ({endpoint}) => {
29
29
  }
30
30
  });
31
31
 
32
- const sdk = new Sdk(CasdoorConfig);
32
+ let sdk;
33
+
34
+ function getStorageData(keys) {
35
+ return new Promise((resolve, reject) => {
36
+ chrome.storage.sync.get(keys, (data) => {
37
+ if (chrome.runtime.lastError) {
38
+ reject(chrome.runtime.lastError.message);
39
+ } else {
40
+ resolve(data);
41
+ }
42
+ });
43
+ });
44
+ }
45
+
46
+ function initInputParamSdk(){
47
+ return new Promise((resolve, reject) => {
48
+ Promise.all([getStorageData("applicationName"), getStorageData("endpoint")])
49
+ .then(([applicationData, endpointData]) => {
50
+ const applicationName = applicationData.applicationName;
51
+ const endpoint = endpointData.endpoint;
52
+
53
+ if (applicationName && endpoint) {
54
+ CasdoorConfig.applicationName = applicationName;
55
+ CasdoorConfig.endpoint = endpoint;
56
+ }
57
+ sdk = new Sdk(CasdoorConfig);
58
+ resolve(sdk);
59
+ })
60
+ .catch((error) => {
61
+ console.error("init SDK failed:", error);
62
+ reject(error);
63
+ });
64
+ });
65
+ }
33
66
 
34
67
  // eslint-disable-next-line no-unused-vars
35
68
  function login() {
36
- sdk.login((accessToken) => {
37
- if (accessToken) {
38
- chrome.storage.sync.set({accessToken}, () => {
39
- sdk
40
- .getUserProfile(accessToken)
41
- .then((userProfile) => displayUserProfile(userProfile));
42
- });
43
- setInputDisabledState(true, "endpoint", "applicationName");
44
- } else {
45
- alert("Login failed!");
46
- }
47
- });
69
+ initInputParamSdk().then((sdk) => {
70
+ sdk.login((accessToken) => {
71
+ if (accessToken) {
72
+ chrome.storage.sync.set({accessToken}, () => {
73
+ sdk
74
+ .getUserProfile(accessToken)
75
+ .then((userProfile) => displayUserProfile(userProfile));
76
+ });
77
+ setInputDisabledState(true, "endpoint", "applicationName");
78
+ } else {
79
+ alert("Login failed!");
80
+ }
81
+ });
82
+ })
48
83
  }
49
84
 
50
85
  // eslint-disable-next-line no-unused-vars
package/src/popup.js CHANGED
@@ -47,7 +47,11 @@ document.addEventListener("DOMContentLoaded", function() {
47
47
  if (accessToken) {
48
48
  logout();
49
49
  } else {
50
- login();
50
+ setInput()
51
+ .then(login())
52
+ .catch(error => {
53
+ console.error('Error login:', error);
54
+ });
51
55
  }
52
56
  });
53
57
  });
@@ -60,9 +64,6 @@ document.addEventListener("DOMContentLoaded", function() {
60
64
  applicationNameDom.value = applicationName;
61
65
  }
62
66
  });
63
- applicationNameDom.addEventListener("input", function(e) {
64
- chrome.storage.sync.set({applicationName: e.target.value});
65
- });
66
67
 
67
68
  const endpointDom = document.getElementById("endpoint");
68
69
  chrome.storage.sync.get("endpoint", ({endpoint}) => {
@@ -70,7 +71,18 @@ document.addEventListener("DOMContentLoaded", function() {
70
71
  endpointDom.value = endpoint;
71
72
  }
72
73
  });
73
- endpointDom.addEventListener("input", function(e) {
74
- chrome.storage.sync.set({endpoint: e.target.value});
75
- });
76
74
  });
75
+
76
+ function setInput() {
77
+ return new Promise((resolve, reject) => {
78
+ const endpointDom = document.getElementById("endpoint");
79
+ const applicationNameDom = document.getElementById("applicationName");
80
+ chrome.storage.sync.set({ endpoint: endpointDom.value, applicationName: applicationNameDom.value }, function() {
81
+ if (chrome.runtime.lastError) {
82
+ reject(chrome.runtime.lastError.message);
83
+ } else {
84
+ resolve();
85
+ }
86
+ });
87
+ });
88
+ }
package/src/sdk.js CHANGED
@@ -125,6 +125,9 @@ class Sdk {
125
125
  };
126
126
  return fetch(applicationUrl, requestConfig)
127
127
  .then((response) => response.json())
128
- .catch((error) => console.error(error));
128
+ .catch((error) => {
129
+ console.error(error)
130
+ alert("failed to get application");
131
+ });
129
132
  }
130
133
  }