Skip to content

Commit 925e671

Browse files
authored
feat: add SilentSignin (#23)
* feat: add SilentSignin * chore: add API doc in README
1 parent f4e6be8 commit 925e671

4 files changed

Lines changed: 73 additions & 12 deletions

File tree

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,48 @@ export default {
131131
</script>
132132
```
133133

134+
## API reference interface
135+
### Get sign up url
136+
```javascript
137+
getSignupUrl()
138+
```
139+
Return the casdoor url that navigates to the registration screen
140+
141+
### Get sign in url
142+
```javascript
143+
getSigninUrl()
144+
```
145+
Return the casdoor url that navigates to the login screen
146+
147+
### Get user profile page url
148+
```javascript
149+
getUserProfileUrl(userName, account)
150+
```
151+
Return the url to navigate to a specific user's casdoor personal page
152+
153+
### Get my profile page url
154+
```javascript
155+
getMyProfileUrl(account)
156+
```
157+
158+
### Sign in
159+
```javascript
160+
signin(serverUrl, signinPath)
161+
```
162+
Handle the callback url from casdoor, call the back-end api to complete the login process
163+
164+
### Determine whether silent sign-in is being used
165+
```javascript
166+
isSilentSigninRequired()
167+
```
168+
We usually use this method to determine if silent login is being used. By default, if the silentSignin parameter is included in the URL and equals one, this method will return true. Of course, you can also use any method you prefer.
169+
170+
### silentSignin
171+
```javascript
172+
silentSignin(onSuccess, onFailure)
173+
```
174+
`onSuccess` and `onFailure` are the callback methods for successful and failed login.
175+
134176
## Q & A
135177

136178
Q1: How to solve "...index.js implicitly has an 'any' type..." error in typescript project?

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lint": "vue-cli-service lint"
1111
},
1212
"dependencies": {
13-
"casdoor-js-sdk": "^0.2.7",
13+
"casdoor-js-sdk": "^0.7.0",
1414
"core-js": "^3.8.3",
1515
"vue-demi": "latest"
1616
},

src/CasdoorSDK.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,17 @@ export default {
3737
return CasdoorSDK.getMyProfileUrl(account);
3838
};
3939

40-
app.prototype.signin = (ServerUrl) => {
41-
return CasdoorSDK.signin(ServerUrl);
40+
app.prototype.signin = (ServerUrl, signinPath) => {
41+
return CasdoorSDK.signin(ServerUrl, signinPath);
4242
};
43+
44+
app.prototype.isSilentSigninRequired = () => {
45+
return CasdoorSDK.isSilentSigninRequired();
46+
}
47+
48+
app.prototype.silentSignin = (isLoggedIn, onSuccess, onFailure) => {
49+
return CasdoorSDK.silentSignin(isLoggedIn, onSuccess, onFailure);
50+
}
4351
}else{
4452

4553
app.provide(CASDOOR_SDK_INJECTION_KEY,
@@ -48,7 +56,9 @@ export default {
4856
getSigninUrl: CasdoorSDK.getSigninUrl.bind(CasdoorSDK),
4957
getUserProfileUrl: CasdoorSDK.getUserProfileUrl.bind(CasdoorSDK),
5058
getMyProfileUrl: CasdoorSDK.getMyProfileUrl.bind(CasdoorSDK),
51-
signin: CasdoorSDK.signin.bind(CasdoorSDK)
59+
signin: CasdoorSDK.signin.bind(CasdoorSDK),
60+
isSilentSigninRequired: CasdoorSDK.isSilentSigninRequired.bind(CasdoorSDK),
61+
silentSignin: CasdoorSDK.silentSignin.bind(CasdoorSDK)
5262
}
5363
);
5464

@@ -68,13 +78,22 @@ export default {
6878
return CasdoorSDK.getMyProfileUrl(account);
6979
};
7080

71-
app.config.globalProperties.signin = (ServerUrl) => {
81+
app.config.globalProperties.signin = async (ServerUrl) => {
7282
const code = window.location.href.split('code=')[1].split('&')[0];
7383
const state = window.location.href.split('state=')[1].split('&')[0];
74-
return fetch(`${ServerUrl}/api/signin?code=${code}&state=${state}`, {
84+
const res = await fetch(`${ServerUrl}/api/signin?code=${code}&state=${state}`, {
7585
method: "POST",
76-
credentials: "include",
77-
}).then(res => res.json());
86+
credentials: "include"
87+
})
88+
return await res.json()
89+
};
90+
91+
app.config.globalProperties.isSilentSigninRequired = () => {
92+
return CasdoorSDK.isSilentSigninRequired();
93+
};
94+
95+
app.config.globalProperties.silentSignin = (isLoggedIn, onSuccess, onFailure) => {
96+
return CasdoorSDK.silentSignin(isLoggedIn, onSuccess, onFailure);
7897
};
7998
}
8099

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,10 +3251,10 @@ cardinal@^2.1.1:
32513251
ansicolors "~0.3.2"
32523252
redeyed "~2.1.0"
32533253

3254-
casdoor-js-sdk@^0.2.7:
3255-
version "0.2.7"
3256-
resolved "https://registry.yarnpkg.com/casdoor-js-sdk/-/casdoor-js-sdk-0.2.7.tgz#09342f6715977bc1991222d04dd36c93b5f0872b"
3257-
integrity sha512-pEI7chd6KWDa7dhBxl3zDY+LagG40bBPoxdPMOZ5OG2gFMTXwRQ4Ka1do0giJsd2YTeAU3u6vwP62YmiQVzgSQ==
3254+
casdoor-js-sdk@^0.7.0:
3255+
version "0.7.0"
3256+
resolved "https://registry.yarnpkg.com/casdoor-js-sdk/-/casdoor-js-sdk-0.7.0.tgz#ee6d8eea138210f26a14452a534cec6c4759b4cd"
3257+
integrity sha512-CcYf1YmdkCPmAbIn+RtQIHpLxq2H3UeOTmm+3ljg5bLBiESAJHhc0uGVpm7crWy/uAJJhQRgLXTPuoQQsgYCvQ==
32583258

32593259
case-sensitive-paths-webpack-plugin@^2.3.0:
32603260
version "2.4.0"

0 commit comments

Comments
 (0)