Skip to content

Commit e2a0187

Browse files
committed
onlyPublicGroups compiled from form & in db.Find
1 parent e6fab4c commit e2a0187

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

routers/web/auth/oauth2_provider.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ func InfoOAuth(ctx *context.Context) {
104104
Picture: ctx.Doer.AvatarLink(ctx),
105105
}
106106

107-
onlyPublicGroups := ctx.IsSigned && (ctx.FormString("private") == "" || ctx.FormBool("private"))
107+
form := web.GetForm(ctx).(*forms.AuthorizationForm)
108+
onlyPublicGroups, _ := oauth2_provider.GrantAdditionalScopes(form.Scope).PublicOnly()
108109
groups, err := oauth2_provider.GetOAuthGroupsForUser(ctx, ctx.Doer, onlyPublicGroups)
109110
if err != nil {
110111
ctx.ServerError("Oauth groups for user", err)

services/oauth2_provider/access_token.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,29 +221,17 @@ func NewAccessTokenResponse(ctx context.Context, grant *auth.OAuth2Grant, server
221221

222222
// returns a list of "org" and "org:team" strings,
223223
// that the given user is a part of.
224-
func GetOAuthGroupsForUser(ctx context.Context, user *user_model.User) ([]string, error) {
224+
func GetOAuthGroupsForUser(ctx context.Context, user *user_model.User, onlyPublicGroups bool) ([]string, error) {
225225
orgs, err := db.Find[org_model.Organization](ctx, org_model.FindOrgOptions{
226226
UserID: user.ID,
227-
IncludePrivate: true,
227+
IncludePrivate: !onlyPublicGroups,
228228
})
229229
if err != nil {
230230
return nil, fmt.Errorf("GetUserOrgList: %w", err)
231231
}
232232

233233
var groups []string
234234
for _, org := range orgs {
235-
// process additional scopes only if enabled in settings
236-
// this could be removed once additional scopes get accepted
237-
if setting.OAuth2.EnableAdditionalGrantScopes {
238-
if onlyPublicGroups {
239-
if public, err := org_model.IsPublicMembership(ctx, org.ID, user.ID); err == nil {
240-
if !public || !org.Visibility.IsPublic() {
241-
continue
242-
}
243-
}
244-
}
245-
}
246-
247235
groups = append(groups, org.Name)
248236
teams, err := org.LoadTeams(ctx)
249237
if err != nil {

0 commit comments

Comments
 (0)