Fix URL join (#43)

This commit is contained in:
Thomas Miceli 2023-05-29 22:39:30 +02:00 committed by GitHub
parent 62f91c5ed2
commit da970d7272
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,7 @@ import (
"gorm.io/gorm"
"io"
"net/http"
"net/url"
"strings"
)
@ -252,8 +253,6 @@ func oauth(ctx echo.Context) error {
httpProtocol = "https"
}
giteaUrl := trimGiteaUrl()
var opengistUrl string
if config.C.ExternalUrl != "" {
opengistUrl = config.C.ExternalUrl
@ -267,7 +266,8 @@ func oauth(ctx echo.Context) error {
github.New(
config.C.GithubClientKey,
config.C.GithubSecret,
opengistUrl+"/oauth/github/callback"),
urlJoin(opengistUrl, "/oauth/github/callback"),
),
)
case "gitea":
@ -275,10 +275,11 @@ func oauth(ctx echo.Context) error {
gitea.NewCustomisedURL(
config.C.GiteaClientKey,
config.C.GiteaSecret,
opengistUrl+"/oauth/gitea/callback",
giteaUrl+"/login/oauth/authorize",
giteaUrl+"/login/oauth/access_token",
giteaUrl+"/api/v1/user"),
urlJoin(opengistUrl, "/oauth/gitea/callback"),
urlJoin(config.C.GiteaUrl, "/login/oauth/authorize"),
urlJoin(config.C.GiteaUrl, "/login/oauth/access_token"),
urlJoin(config.C.GiteaUrl, "/api/v1/user"),
),
)
}
@ -335,6 +336,15 @@ func trimGiteaUrl() string {
return giteaUrl
}
func urlJoin(base string, elem ...string) string {
joined, err := url.JoinPath(base, elem...)
if err != nil {
log.Error().Err(err).Msg("Cannot join url")
}
return joined
}
func getAvatarUrlFromProvider(provider string, identifier string) string {
fmt.Println("getAvatarUrlFromProvider", provider, identifier)
switch provider {