1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-10-08 22:51:59 +02:00

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 <magic_rb@redalder.org>

* add changelog, documentation and fix groups list

Signed-off-by: Jan Larwig <jan@larwig.com>

---------

Signed-off-by: magic_rb <magic_rb@redalder.org>
Signed-off-by: Jan Larwig <jan@larwig.com>
Co-authored-by: Jan Larwig <jan@larwig.com>
This commit is contained in:
Richard Brežák
2025-08-19 08:40:36 +02:00
committed by GitHub
parent f18a0b7b07
commit 8c1b2b63bf
3 changed files with 33 additions and 8 deletions

View File

@@ -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

View File

@@ -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`

View File

@@ -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++