Update config to support OIDC and oauth2
This commit is contained in:
parent
430f46ffee
commit
4c1b402137
8 changed files with 92 additions and 42 deletions
|
@ -294,14 +294,16 @@ func (h *Handler) thirdPartyAuthCallback(c *gin.Context) {
|
|||
}
|
||||
|
||||
token, err := h.identityProvider.ExchangeToken(c, req.Code)
|
||||
|
||||
if err != nil {
|
||||
logger.Errorw("account.handler.thirdPartyAuthCallback (oauth2) failed to exchange token", "err", err)
|
||||
logger.Error("account.handler.thirdPartyAuthCallback (oauth2) failed to exchange token", "err", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to exchange token"})
|
||||
return
|
||||
}
|
||||
|
||||
claims, err := h.identityProvider.GetUserInfo(c, token)
|
||||
if err != nil {
|
||||
logger.Errorw("account.handler.thirdPartyAuthCallback (oauth2) failed to get claims", "err", err)
|
||||
logger.Error("account.handler.thirdPartyAuthCallback (oauth2) failed to get claims", "err", err)
|
||||
}
|
||||
|
||||
acc, err := h.userRepo.FindByEmail(c, claims.Email)
|
||||
|
@ -310,7 +312,7 @@ func (h *Handler) thirdPartyAuthCallback(c *gin.Context) {
|
|||
password := auth.GenerateRandomPassword(12)
|
||||
encodedPassword, err := auth.EncodePassword(password)
|
||||
if err != nil {
|
||||
logger.Errorw("account.handler.thirdPartyAuthCallback (oauth2) password encoding failed", "err", err)
|
||||
logger.Error("account.handler.thirdPartyAuthCallback (oauth2) password encoding failed", "err", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Password encoding failed"})
|
||||
return
|
||||
}
|
||||
|
@ -370,7 +372,7 @@ func (h *Handler) thirdPartyAuthCallback(c *gin.Context) {
|
|||
h.jwtAuth.Authenticator(c)
|
||||
tokenString, expire, err := h.jwtAuth.TokenGenerator(acc)
|
||||
if err != nil {
|
||||
logger.Errorw("Unable to Generate a Token")
|
||||
logger.Error("Unable to Generate a Token")
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": "Unable to Generate a Token",
|
||||
})
|
||||
|
@ -378,9 +380,6 @@ func (h *Handler) thirdPartyAuthCallback(c *gin.Context) {
|
|||
}
|
||||
c.JSON(http.StatusOK, gin.H{"token": tokenString, "expire": expire})
|
||||
return
|
||||
default:
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid provider"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -713,13 +712,4 @@ func Routes(router *gin.Engine, h *Handler, auth *jwt.GinJWTMiddleware, limiter
|
|||
authRoutes.POST("reset", h.resetPassword)
|
||||
authRoutes.POST("password", h.updateUserPassword)
|
||||
}
|
||||
pingRoutes := router.Group("api/v1/ping")
|
||||
pingRoutes.Use(utils.RateLimitMiddleware(limiter))
|
||||
{
|
||||
pingRoutes.GET("/", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"message": "pong",
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue