@@ -28,13 +28,13 @@ type GoogleProvider struct {
2828
2929 RedeemRefreshURL *url.URL
3030
31− // GroupValidator is a function that determines if the user in the passed
31+ // groupValidator is a function that determines if the user in the passed
3232 // session is a member of any of the configured Google groups.
3333 //
3434 // This hits the Google API for each group, so it is called on Redeem &
3535 // Refresh. `Authorize` uses the results of this saved in `session.Groups`
3636 // Since it is called on every request.
37− GroupValidator func(*sessions.SessionState) bool
37+ groupValidator func(*sessions.SessionState) bool
3838}
3939
4040var _ Provider = (*GoogleProvider)(nil)
@@ -90,9 +90,9 @@ func NewGoogleProvider(p *ProviderData) *GoogleProvider {
9090 })
9191 return &GoogleProvider{
9292 ProviderData: p,
93− // Set a default GroupValidator to just always return valid (true), it will
93+ // Set a default groupValidator to just always return valid (true), it will
9494 // be overwritten if we configured a Google group restriction.
95− GroupValidator: func(*sessions.SessionState) bool {
95+ groupValidator: func(*sessions.SessionState) bool {
9696 return true
9797 },
9898 }
@@ -165,7 +165,8 @@ func (p *GoogleProvider) Redeem(ctx context.Context, redirectURL, code string) (
165165
166166 created := time.Now()
167167 expires := time.Now().Add(time.Duration(jsonResponse.ExpiresIn) * time.Second).Truncate(time.Second)
168− s := &sessions.SessionState{
168+
169+ return &sessions.SessionState{
169170 AccessToken: jsonResponse.AccessToken,
170171 IDToken: jsonResponse.IDToken,
171172 CreatedAt: &created,
@@ -173,19 +174,26 @@ func (p *GoogleProvider) Redeem(ctx context.Context, redirectURL, code string) (
173174 RefreshToken: jsonResponse.RefreshToken,
174175 Email: c.Email,
175176 User: c.Subject,
176− }
177− p.GroupValidator(s)
177+ }, nil
178+}
179+
180+// EnrichSessionState checks the listed Google Groups configured and adds any
181+// that the user is a member of to session.Groups.
182+func (p *GoogleProvider) EnrichSessionState(ctx context.Context, s *sessions.SessionState) error {
183+ p.groupValidator(s)
178184
179− return s, nil
185+ return nil
180186}
181187
182188// SetGroupRestriction configures the GoogleProvider to restrict access to the
183189// specified group(s). AdminEmail has to be an administrative email on the domain that is
184190// checked. CredentialsFile is the path to a json file containing a Google service
185191// account credentials.
192+//
193+// TODO (@NickMeves) - Unit Test this OR refactor away from groupValidator func
186194func (p *GoogleProvider) SetGroupRestriction(groups []string, adminEmail string, credentialsReader io.Reader) {
187195 adminService := getAdminService(adminEmail, credentialsReader)
188− p.GroupValidator = func(s *sessions.SessionState) bool {
196+ p.groupValidator = func(s *sessions.SessionState) bool {
189197 // Reset our saved Groups in case membership changed
190198 // This is used by `Authorize` on every request
191199 s.Groups = make([]string, 0, len(groups))
@@ -266,7 +274,7 @@ func (p *GoogleProvider) RefreshSessionIfNeeded(ctx context.Context, s *sessions
266274 }
267275
268276 // re-check that the user is in the proper google group(s)
269− if !p.GroupValidator(s) {
277+ if !p.groupValidator(s) {
270278 return false, fmt.Errorf("%s is no longer in the group(s)", s.Email)
271279 }
272280