Skip to content

Commit efdb641

Browse files
committed
1 parent 2bedbba commit efdb641

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎controller/oauthctl.go‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package controller
1818

1919
import (
20+
"fmt"
2021
"net/http"
2122

2223
"github.com/b3log/pipe/model"
@@ -25,11 +26,11 @@ import (
2526
"github.com/gin-gonic/gin"
2627
)
2728

28-
var states map[string]string
29+
var states = map[string]string{}
2930

3031
// redirectGitHubLoginAction redirects to GitHub auth page.
3132
func redirectGitHubLoginAction(c *gin.Context) {
32-
state := util.RandString(16)
33+
state := util.RandString(16) + model.Conf.Server
3334
states[state] = state
3435
path := "https://github.com/login/oauth/authorize" + "?client_id=af7df3c80f26af88a8b3&state=" + state + "&scope=public_repo,user"
3536

@@ -53,7 +54,7 @@ func githubCallback(c *gin.Context) {
5354
return
5455
}
5556

56-
githubId := githubUser["id"].(string)
57+
githubId := fmt.Sprintf("%v", githubUser["id"])
5758
userName := githubUser["login"].(string)
5859
user := service.User.GetUserByGitHubId(githubId)
5960
if nil == user {
@@ -63,7 +64,7 @@ func githubCallback(c *gin.Context) {
6364
return
6465
}
6566

66-
user := service.User.GetUserByName(userName)
67+
user = service.User.GetUserByName(userName)
6768
if nil == user {
6869
user = &model.User{
6970
Name: userName,
@@ -95,4 +96,6 @@ func githubCallback(c *gin.Context) {
9596
logger.Errorf("saves session failed: " + err.Error())
9697
c.Status(http.StatusInternalServerError)
9798
}
99+
100+
c.Redirect(http.StatusSeeOther, model.Conf.Server+util.PathAdmin)
98101
}

‎controller/router.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func MapRoutes() *gin.Engine {
8383
api.GET("/check-version", console.CheckVersion)
8484
api.GET("/blogs/top", showTopBlogs)
8585
api.GET("/oauth/github/redirect", redirectGitHubLoginAction)
86+
api.GET("/oauth/github/callback", githubCallback)
8687

8788
consoleGroup := api.Group("/console")
8889
consoleGroup.Use(console.LoginCheck)

0 commit comments

Comments
 (0)