@@ -117,29 +117,39 @@ func (p *MicrosoftEntraIDProvider) addGraphGroupsToSession(ctx context.Context,
117117 groupsHeaders := makeAuthorizationHeader (tokenTypeBearer , s .AccessToken , nil )
118118 groupsHeaders .Add ("ConsistencyLevel" , "eventual" )
119119
120- groupsURL := fmt .Sprintf ("%s/transitiveMemberOf?$select=id&$top=999" , p .microsoftGraphURL )
120+ var allGroups []string
121+ var nextLink string
121122
122- jsonRequest , err := requests .New (groupsURL ).
123- WithContext (ctx ).
124- WithHeaders (groupsHeaders ).
125- Do ().
126- UnmarshalSimpleJSON ()
123+ for {
124+ if nextLink == "" {
125+ nextLink = fmt .Sprintf ("%s/transitiveMemberOf?$select=id&$top=100" , p .microsoftGraphURL )
126+ }
127127
128- if err != nil {
129- logger .Errorf ("invalid response from microsoft graph, no groups added to session: %v" , err )
130- return nil
131- }
128+ response , err := requests .New (nextLink ).
129+ WithContext (ctx ).
130+ WithHeaders (groupsHeaders ).
131+ Do ().
132+ UnmarshalSimpleJSON ()
132133
133- reqGroups := jsonRequest .Get ("value" ).MustArray ()
134- groups := make ([]string , len (reqGroups ))
134+ if err != nil {
135+ return fmt .Errorf ("invalid response from microsoft graph, no groups added to session: %v" , err )
136+ }
137+ reqGroups := response .Get ("value" ).MustArray ()
135138
136- for i := range reqGroups {
137- value := jsonRequest .Get ("value" ).GetIndex (i ).Get ("id" ).MustString ()
138- groups = append (groups , value )
139- }
139+ for i := range reqGroups {
140+ value := response .Get ("value" ).GetIndex (i ).Get ("id" ).MustString ()
141+ allGroups = append (allGroups , value )
142+ }
143+
144+ // https://learn.microsoft.com/en-us/graph/paging?view=graph-rest-1.0&tabs=http#how-paging-works
145+ nextLink = response .Get ("@odata.nextLink" ).MustString ()
140146
141- s .Groups = util .RemoveDuplicateStr (append (s .Groups , groups ... ))
147+ if nextLink == "" {
148+ break
149+ }
150+ }
142151
152+ s .Groups = util .RemoveDuplicateStr (append (s .Groups , allGroups ... ))
143153 return nil
144154}
145155
0 commit comments