Compare commits
1 Commits
gists-john
...
fix/gitea-
| Author | SHA1 | Date | |
|---|---|---|---|
|
a22475d692
|
@@ -2,16 +2,15 @@ package oauth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
gocontext "context"
|
||||||
gojson "encoding/json"
|
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/markbates/goth"
|
"github.com/markbates/goth"
|
||||||
"github.com/markbates/goth/gothic"
|
"github.com/markbates/goth/gothic"
|
||||||
"github.com/markbates/goth/providers/gitea"
|
"github.com/markbates/goth/providers/gitea"
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/thomiceli/opengist/internal/config"
|
"github.com/thomiceli/opengist/internal/config"
|
||||||
"github.com/thomiceli/opengist/internal/db"
|
"github.com/thomiceli/opengist/internal/db"
|
||||||
"github.com/thomiceli/opengist/internal/web/context"
|
"github.com/thomiceli/opengist/internal/web/context"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GiteaProvider struct {
|
type GiteaProvider struct {
|
||||||
@@ -80,34 +79,7 @@ func (p *GiteaCallbackProvider) GetProviderUserSSHKeys() ([]string, error) {
|
|||||||
|
|
||||||
func (p *GiteaCallbackProvider) UpdateUserDB(user *db.User) {
|
func (p *GiteaCallbackProvider) UpdateUserDB(user *db.User) {
|
||||||
user.GiteaID = p.User.UserID
|
user.GiteaID = p.User.UserID
|
||||||
|
user.AvatarURL = p.User.AvatarURL
|
||||||
resp, err := http.Get(urlJoin(config.C.GiteaUrl, "/api/v1/users/", p.User.UserID))
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msg("Cannot get user from Gitea")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msg("Cannot read Gitea response body")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var result map[string]interface{}
|
|
||||||
err = gojson.Unmarshal(body, &result)
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msg("Cannot unmarshal Gitea response body")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
field, ok := result["avatar_url"]
|
|
||||||
if !ok {
|
|
||||||
log.Error().Msg("Field 'avatar_url' not found in Gitea JSON response")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
user.AvatarURL = field.(string)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGiteaCallbackProvider(user *goth.User) CallbackProvider {
|
func NewGiteaCallbackProvider(user *goth.User) CallbackProvider {
|
||||||
|
|||||||
Reference in New Issue
Block a user