mirror of
https://github.com/thomiceli/opengist.git
synced 2025-01-03 16:22:40 +00:00
Fix URL join (#43)
This commit is contained in:
parent
62f91c5ed2
commit
da970d7272
1 changed files with 17 additions and 7 deletions
|
@ -19,6 +19,7 @@ import (
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -252,8 +253,6 @@ func oauth(ctx echo.Context) error {
|
||||||
httpProtocol = "https"
|
httpProtocol = "https"
|
||||||
}
|
}
|
||||||
|
|
||||||
giteaUrl := trimGiteaUrl()
|
|
||||||
|
|
||||||
var opengistUrl string
|
var opengistUrl string
|
||||||
if config.C.ExternalUrl != "" {
|
if config.C.ExternalUrl != "" {
|
||||||
opengistUrl = config.C.ExternalUrl
|
opengistUrl = config.C.ExternalUrl
|
||||||
|
@ -267,7 +266,8 @@ func oauth(ctx echo.Context) error {
|
||||||
github.New(
|
github.New(
|
||||||
config.C.GithubClientKey,
|
config.C.GithubClientKey,
|
||||||
config.C.GithubSecret,
|
config.C.GithubSecret,
|
||||||
opengistUrl+"/oauth/github/callback"),
|
urlJoin(opengistUrl, "/oauth/github/callback"),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
case "gitea":
|
case "gitea":
|
||||||
|
@ -275,10 +275,11 @@ func oauth(ctx echo.Context) error {
|
||||||
gitea.NewCustomisedURL(
|
gitea.NewCustomisedURL(
|
||||||
config.C.GiteaClientKey,
|
config.C.GiteaClientKey,
|
||||||
config.C.GiteaSecret,
|
config.C.GiteaSecret,
|
||||||
opengistUrl+"/oauth/gitea/callback",
|
urlJoin(opengistUrl, "/oauth/gitea/callback"),
|
||||||
giteaUrl+"/login/oauth/authorize",
|
urlJoin(config.C.GiteaUrl, "/login/oauth/authorize"),
|
||||||
giteaUrl+"/login/oauth/access_token",
|
urlJoin(config.C.GiteaUrl, "/login/oauth/access_token"),
|
||||||
giteaUrl+"/api/v1/user"),
|
urlJoin(config.C.GiteaUrl, "/api/v1/user"),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,6 +336,15 @@ func trimGiteaUrl() string {
|
||||||
return giteaUrl
|
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 {
|
func getAvatarUrlFromProvider(provider string, identifier string) string {
|
||||||
fmt.Println("getAvatarUrlFromProvider", provider, identifier)
|
fmt.Println("getAvatarUrlFromProvider", provider, identifier)
|
||||||
switch provider {
|
switch provider {
|
||||||
|
|
Loading…
Reference in a new issue