Skip to content

Commit 34bfbfe

Browse files
committed
♻️ b3log#191
1 parent ce50690 commit 34bfbfe

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎console/pages/init.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
snackModify: 'success',
3737
})
3838
if (!this.clickedGitHub) {
39-
window.location.href = `${process.env.AxiosBaseURL}/oauth/github/redirect`
39+
window.location.href = `${process.env.AxiosBaseURL}/oauth/github/redirect?referer=${document.referrer}`
4040
this.$set(this, 'clickedGitHub', true)
4141
}
4242
},

‎controller/oauthctl.go‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controller
1919
import (
2020
"fmt"
2121
"net/http"
22+
"strings"
2223

2324
"github.com/b3log/pipe/model"
2425
"github.com/b3log/pipe/service"
@@ -30,7 +31,14 @@ var states = map[string]string{}
3031

3132
// redirectGitHubLoginAction redirects to GitHub auth page.
3233
func redirectGitHubLoginAction(c *gin.Context) {
33-
state := util.RandString(16) + model.Conf.Server
34+
referer := c.Request.URL.Query().Get("referer")
35+
if "" == referer {
36+
referer = model.Conf.Server
37+
}
38+
if strings.HasSuffix(referer, "/") {
39+
referer = referer[:len(referer)-1]
40+
}
41+
state := util.RandString(16) + referer
3442
states[state] = state
3543
path := "https://github.com/login/oauth/authorize" + "?client_id=af7df3c80f26af88a8b3&state=" + state + "&scope=public_repo,user"
3644

@@ -46,6 +54,8 @@ func githubCallbackAction(c *gin.Context) {
4654
}
4755
delete(states, state)
4856

57+
referer := state[16:]
58+
4959
accessToken := c.Query("ak")
5060
githubUser := util.GitHubUserInfo(accessToken)
5161
if nil == githubUser {
@@ -119,5 +129,5 @@ func githubCallbackAction(c *gin.Context) {
119129
c.Status(http.StatusInternalServerError)
120130
}
121131

122-
c.Redirect(http.StatusSeeOther, model.Conf.Server+util.PathAdmin)
132+
c.Redirect(http.StatusSeeOther, referer)
123133
}

‎controller/router.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ func routePath(c *gin.Context) {
256256
updateSymArticleAction(c)
257257
}
258258

259+
return
260+
case "/api/oauth/github/callback":
261+
githubCallbackAction(c)
262+
259263
return
260264
}
261265

0 commit comments

Comments
 (0)