Skip to content

Commit efddd2b

Browse files
authored
Check MSEntraID group access permissions (#89)
Current user group membership always returns, with User.Read.All the list of groups, but without their details. To access their details, we need to list all groups that the user has potentially access too. Add a check for it to return a better error for those use cases.
2 parents 277bf03 + f48f470 commit efddd2b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

authd-oidc-brokers/internal/providers/msentraid/msentraid.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/k0kubun/pp"
1515
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
1616
msauth "github.com/microsoftgraph/msgraph-sdk-go-core/authentication"
17+
msgraphgroups "github.com/microsoftgraph/msgraph-sdk-go/groups"
1718
"github.com/microsoftgraph/msgraph-sdk-go/models"
1819
"github.com/ubuntu/authd-oidc-brokers/internal/providers/group"
1920
"golang.org/x/oauth2"
@@ -53,6 +54,17 @@ func (p Provider) GetGroups(token *oauth2.Token) ([]group.Info, error) {
5354

5455
client := msgraphsdk.NewGraphServiceClient(adapter)
5556

57+
// Check GroupMember.Read.All access
58+
var topOne int32 = 1
59+
requestOptions := &msgraphgroups.GroupsRequestBuilderGetRequestConfiguration{
60+
QueryParameters: &msgraphgroups.GroupsRequestBuilderGetQueryParameters{
61+
Top: &topOne, // Limit to only one group
62+
},
63+
}
64+
if _, err = client.Groups().Get(context.Background(), requestOptions); err != nil {
65+
return nil, fmt.Errorf("could not access user's groups: %v", err)
66+
}
67+
5668
m, err := client.Me().MemberOf().Get(context.Background(), nil)
5769
if err != nil {
5870
return nil, err

0 commit comments

Comments
 (0)