Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Github & Gitea OAuth provider #13

Merged
merged 6 commits into from
Apr 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Trim gitea url
  • Loading branch information
thomiceli committed Apr 17, 2023
commit 884195aed4acefe3a280b4b385f9e3fc225645c5
18 changes: 12 additions & 6 deletions internal/web/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func oauthCallback(ctx echo.Context) error {
case "github":
resp, err = http.Get("https://github.com/" + user.NickName + ".keys")
case "gitea":
resp, err = http.Get("https://gitea.com/" + user.NickName + ".keys")
resp, err = http.Get(trimGiteaUrl() + "/" + user.NickName + ".keys")
}

if err == nil {
Expand Down Expand Up @@ -226,12 +226,8 @@ func oauth(ctx echo.Context) error {
httpProtocol = "https"
}

giteaUrl := trimGiteaUrl()
httpDomain := httpProtocol + ":https://" + ctx.Request().Host
giteaUrl := config.C.GiteaUrl
// remove trailing slash
if giteaUrl[len(giteaUrl)-1] == '/' {
giteaUrl = giteaUrl[:len(giteaUrl)-1]
}

switch provider {
case "github":
Expand Down Expand Up @@ -296,3 +292,13 @@ func logout(ctx echo.Context) error {
deleteCsrfCookie(ctx)
return redirect(ctx, "/all")
}

func trimGiteaUrl() string {
giteaUrl := config.C.GiteaUrl
// remove trailing slash
if giteaUrl[len(giteaUrl)-1] == '/' {
giteaUrl = giteaUrl[:len(giteaUrl)-1]
}

return giteaUrl
}