From 8c1b2b63bfdba1118f55464a1554a672be9637d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Bre=C5=BE=C3=A1k?= Date: Tue, 19 Aug 2025 08:40:36 +0200 Subject: [PATCH] fix: Gitea team membership (#3150) * bugfix: Gitaa team membership Gitea doesn't properly fill in all the fields like GitHub, so implement a series of fallbacks. Signed-off-by: magic_rb * add changelog, documentation and fix groups list Signed-off-by: Jan Larwig --------- Signed-off-by: magic_rb Signed-off-by: Jan Larwig Co-authored-by: Jan Larwig --- CHANGELOG.md | 1 + docs/docs/configuration/providers/gitea.md | 4 +-- providers/github.go | 36 ++++++++++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dce52ba7..faecde02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - [#2273](https://github.com/oauth2-proxy/oauth2-proxy/pull/2273) feat: add Cidaas provider (@Bibob7, @Teko012) - [#3166](https://github.com/oauth2-proxy/oauth2-proxy/pull/3166) chore(dep): upgrade to latest golang 1.24.6 (@tuunit) - [#3156](https://github.com/oauth2-proxy/oauth2-proxy/pull/3156) feat: allow disable-keep-alives configuration for upstream (@jet-go) +- [#3150](https://github.com/oauth2-proxy/oauth2-proxy/pull/3150) fix: Gitea team membership (@MagicRB, @tuunit) # V7.11.0 diff --git a/docs/docs/configuration/providers/gitea.md b/docs/docs/configuration/providers/gitea.md index 996a5ddb..6c679dd0 100644 --- a/docs/docs/configuration/providers/gitea.md +++ b/docs/docs/configuration/providers/gitea.md @@ -1,10 +1,10 @@ --- id: gitea -title: Gitea +title: Gitea / Forgejo --- :::note -This is not actually its own provider. For more details and options please refer to the [GitHub Provider Options](github.md) +This is not actually a fully serparate provider. For more details and options please refer to the [GitHub Provider Options](github.md) ::: 1. Create a new application: `https://< your gitea host >/user/settings/applications` diff --git a/providers/github.go b/providers/github.go index 749fcc03..09f10083 100644 --- a/providers/github.go +++ b/providers/github.go @@ -460,10 +460,14 @@ func (p *GitHubProvider) getOrgAndTeam(ctx context.Context, s *sessions.SessionS } func (p *GitHubProvider) getOrgs(ctx context.Context, s *sessions.SessionState) error { - // https://docs.github.com/en/rest/orgs/orgs#list-organizations-for-the-authenticated-user type Organization struct { - Login string `json:"login"` + // Support for Github organizations + // https://docs.github.com/en/rest/orgs/orgs#list-organizations-for-the-authenticated-user + Login string `json:"login,omitempty"` + // Support for Gitea organizations + // https://docs.gitea.com/api/1.24/#tag/organization/operation/orgGetAll + Name string `json:"name,omitempty"` } pn := 1 @@ -490,8 +494,16 @@ func (p *GitHubProvider) getOrgs(ctx context.Context, s *sessions.SessionState) } for _, org := range orgs { - logger.Printf("Member of Github Organization:%q", org.Login) - s.Groups = append(s.Groups, org.Login) + var orgName string + if len(org.Login) > 0 { + orgName = org.Login + logger.Printf("Member of Github Organization: %q", orgName) + } else { + orgName = org.Name + logger.Printf("Member of Gitea Organization: %q", orgName) + } + + s.Groups = append(s.Groups, orgName) } pn++ } @@ -506,6 +518,7 @@ func (p *GitHubProvider) getTeams(ctx context.Context, s *sessions.SessionState) Slug string `json:"slug"` Org struct { Login string `json:"login"` + Name string `json:"name"` } `json:"organization"` } @@ -533,8 +546,19 @@ func (p *GitHubProvider) getTeams(ctx context.Context, s *sessions.SessionState) } for _, team := range teams { - logger.Printf("Member of Github Organization/Team: %q/%q", team.Org.Login, team.Slug) - s.Groups = append(s.Groups, fmt.Sprintf("%s%s%s", team.Org.Login, orgTeamSeparator, team.Slug)) + var orgName, teamName string + + if len(team.Org.Login) > 0 { + orgName = team.Org.Login + teamName = team.Slug + logger.Printf("Member of Github Organization/Team: %q/%q", orgName, teamName) + } else { + orgName = team.Org.Name + teamName = team.Name + logger.Printf("Member of Gitea Organization/Team: %q/%q", orgName, teamName) + } + + s.Groups = append(s.Groups, fmt.Sprintf("%s%s%s", orgName, orgTeamSeparator, teamName)) } pn++