Skip to content

Commit

Permalink
Merge pull request #56 from NJUPT-SAST/dev-xun
Browse files Browse the repository at this point in the history
no fix and test
  • Loading branch information
Xunop authored Oct 25, 2023
2 parents 0350bf5 + 408ab07 commit b8480f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions api/v1/oauth_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import (
"github.com/sirupsen/logrus"
pg "github.com/vgarvardt/go-oauth2-pg/v4"
"github.com/vgarvardt/go-pg-adapter/pgx4adapter"
reqLog "github.com/NJUPT-SAST/sast-link-backend/log"
)

var (
srv *server.Server
pgxConn, _ = pgx.Connect(context.Background(), config.Config.Sub("oauth.server").GetString("db_uri"))
adapter = pgx4adapter.NewConn(pgxConn)
srv *server.Server
pgxConn, _ = pgx.Connect(context.Background(), config.Config.Sub("oauth.server").GetString("db_uri"))
adapter = pgx4adapter.NewConn(pgxConn)
// FIXME: tokenStore, clientStore maybe have some problem
tokenStore, _ = pg.NewTokenStore(adapter, pg.WithTokenStoreGCInterval(time.Minute))
clientStore, _ = pg.NewClientStore(adapter)
Expand Down Expand Up @@ -182,6 +183,7 @@ func Authorize(c *gin.Context) {

// Redirect user to login page if user not login or
// Get code directly if user has logged in
reqLog.LogReq(r)
err = srv.HandleAuthorizeRequest(w, r)
if err != nil {
c.JSON(http.StatusInternalServerError, result.Failed(result.InternalErr.Wrap(err)))
Expand Down Expand Up @@ -289,6 +291,7 @@ func userAuthorizeHandler(w http.ResponseWriter, r *http.Request) (userID string
}

username, err := util.GetUsername(token, model.LOGIN_TOKEN_SUB)
log.Println("Oauth2:username: ", username)
if err != nil || username == "" {
if r.Form == nil {
_ = r.ParseForm()
Expand Down
6 changes: 4 additions & 2 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"net/http"

v1 "github.com/NJUPT-SAST/sast-link-backend/api/v1"
"github.com/NJUPT-SAST/sast-link-backend/log"
"github.com/NJUPT-SAST/sast-link-backend/middleware"
"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {
r := gin.New()
// var midLog = log.Log
// r.Use(middleware.MiddlewareLogging(midLog))
var midLog = log.Log
r.Use(middleware.MiddlewareLogging(midLog))
// FIXME: need discuss on web log
// r.Use(middleware.WebLogger)
r.GET("/ping", func(c *gin.Context) {
Expand Down

0 comments on commit b8480f8

Please sign in to comment.