Added Gitea oauth to the admin dashboard and finished the oauth handling
This commit is contained in:
@@ -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()})
|
||||
|
||||
Reference in New Issue
Block a user