Skip to content

Commit 8080927

Browse files
authored
fix: redirect for non-built-in app logout (beego#587)
Signed-off-by: Steve0x2a <[email protected]>
1 parent a95c5b0 commit 8080927

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

controllers/account.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,15 @@ func (c *ApiController) Logout() {
225225
user := c.GetSessionUsername()
226226
util.LogInfo(c.Ctx, "API: [%s] logged out", user)
227227

228+
application := c.GetSessionApplication()
228229
c.SetSessionUsername("")
229230
c.SetSessionData(nil)
230231

231-
c.ResponseOk(user)
232+
if application == nil || application.Name == "app-built-in" || application.HomepageUrl == "" {
233+
c.ResponseOk(user)
234+
return
235+
}
236+
c.ResponseOk(user, application.HomepageUrl)
232237
}
233238

234239
// GetAccount

controllers/base.go

+9
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ func (c *ApiController) GetSessionUsername() string {
7272
return user.(string)
7373
}
7474

75+
func (c *ApiController) GetSessionApplication() *object.Application {
76+
clientId := c.GetSession("aud")
77+
if clientId == nil {
78+
return nil
79+
}
80+
application := object.GetApplicationByClientId(clientId.(string))
81+
return application
82+
}
83+
7584
func (c *ApiController) GetSessionOidc() (string, string) {
7685
sessionData := c.GetSessionData()
7786
if sessionData != nil &&

web/src/App.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,12 @@ class App extends Component {
235235
});
236236

237237
Setting.showMessage("success", `Logged out successfully`);
238-
239-
Setting.goToLinkSoft(this, "/");
238+
let redirectUri = res.data2;
239+
if (redirectUri !== null && redirectUri !== undefined && redirectUri !== "") {
240+
Setting.goToLink(redirectUri);
241+
}else{
242+
Setting.goToLinkSoft(this, "/");
243+
}
240244
} else {
241245
Setting.showMessage("error", `Failed to log out: ${res.msg}`);
242246
}

web/src/auth/PromptPage.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ class PromptPage extends React.Component {
147147
if (res.status === 'ok') {
148148
this.onUpdateAccount(null);
149149

150-
const redirectUrl = this.getRedirectUrl();
150+
let redirectUrl = this.getRedirectUrl();
151+
if (redirectUrl === "") {
152+
redirectUrl = res.data2
153+
}
151154
if (redirectUrl !== "") {
152155
Setting.goToLink(redirectUrl);
153156
} else {

0 commit comments

Comments
 (0)