Skip to content

Commit

Permalink
fix: redirect for non-built-in app logout (beego#587)
Browse files Browse the repository at this point in the history
Signed-off-by: Steve0x2a <[email protected]>
  • Loading branch information
Steve0x2a authored Mar 19, 2022
1 parent a95c5b0 commit 8080927
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
7 changes: 6 additions & 1 deletion controllers/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,15 @@ func (c *ApiController) Logout() {
user := c.GetSessionUsername()
util.LogInfo(c.Ctx, "API: [%s] logged out", user)

application := c.GetSessionApplication()
c.SetSessionUsername("")
c.SetSessionData(nil)

c.ResponseOk(user)
if application == nil || application.Name == "app-built-in" || application.HomepageUrl == "" {
c.ResponseOk(user)
return
}
c.ResponseOk(user, application.HomepageUrl)
}

// GetAccount
Expand Down
9 changes: 9 additions & 0 deletions controllers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ func (c *ApiController) GetSessionUsername() string {
return user.(string)
}

func (c *ApiController) GetSessionApplication() *object.Application {
clientId := c.GetSession("aud")
if clientId == nil {
return nil
}
application := object.GetApplicationByClientId(clientId.(string))
return application
}

func (c *ApiController) GetSessionOidc() (string, string) {
sessionData := c.GetSessionData()
if sessionData != nil &&
Expand Down
8 changes: 6 additions & 2 deletions web/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,12 @@ class App extends Component {
});

Setting.showMessage("success", `Logged out successfully`);

Setting.goToLinkSoft(this, "/");
let redirectUri = res.data2;
if (redirectUri !== null && redirectUri !== undefined && redirectUri !== "") {
Setting.goToLink(redirectUri);
}else{
Setting.goToLinkSoft(this, "/");
}
} else {
Setting.showMessage("error", `Failed to log out: ${res.msg}`);
}
Expand Down
5 changes: 4 additions & 1 deletion web/src/auth/PromptPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ class PromptPage extends React.Component {
if (res.status === 'ok') {
this.onUpdateAccount(null);

const redirectUrl = this.getRedirectUrl();
let redirectUrl = this.getRedirectUrl();
if (redirectUrl === "") {
redirectUrl = res.data2
}
if (redirectUrl !== "") {
Setting.goToLink(redirectUrl);
} else {
Expand Down

0 comments on commit 8080927

Please sign in to comment.