Added Gitea oauth to the admin dashboard and finished the oauth handling

This commit is contained in:
2025-09-15 22:24:12 +03:30
parent a84156f0a0
commit d4044b0eaf
11 changed files with 228 additions and 230 deletions
+13 -4
View File
@@ -11,22 +11,31 @@ import (
type OauthLoginHandler struct {
Jwt auth.JwtTokenGenerator
OauthLoginHandler auth.GiteaOAuth2Handler
OauthLoginHandler *auth.GiteaOAuth2Handler
}
var OauthLoginHandlerInstance *OauthLoginHandler
func InitOauthLoginHandler() {
OauthLoginHandlerInstance = &OauthLoginHandler{
Jwt: *auth.JwtTokenGeneratorInstance,
Jwt: *auth.JwtTokenGeneratorInstance,
OauthLoginHandler: auth.GiteaOauth2HandlerInstance,
}
}
func (_ *OauthLoginHandler) GoToGiteaLogin(c *gin.Context) {
c.Redirect(http.StatusFound, auth.GiteaOauth2HandlerInstance.GetGiteaLoginURL(c.Request.Host))
func (olh *OauthLoginHandler) GoToGiteaLogin(c *gin.Context) {
redirectURL, _ := olh.OauthLoginHandler.GetGiteaLoginURL(c.Request.URL.Scheme + c.Request.Host)
if redirectURL != "" {
c.Redirect(http.StatusFound, redirectURL)
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to get gitea login url"})
}
func (olh *OauthLoginHandler) LoginWithGitea(c *gin.Context) {
var input dto.GiteaLoginInput
if err := c.ShouldBindJSON(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})