@@ -28,13 +28,13 @@ type GoogleProvider struct {
29 RedeemRefreshURL *url.URL
29 RedeemRefreshURL *url.URL
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
32 // session is a member of any of the configured Google groups.
32 // session is a member of any of the configured Google groups.
34 // This hits the Google API for each group, so it is called on Redeem &
34 // This hits the Google API for each group, so it is called on Redeem &
35 // Refresh. `Authorize` uses the results of this saved in `session.Groups`
35 // Refresh. `Authorize` uses the results of this saved in `session.Groups`
36 // Since it is called on every request.
36 // Since it is called on every request.
37− GroupValidator func(*sessions.SessionState) bool
37+ groupValidator func(*sessions.SessionState) bool
40var _ Provider = (*GoogleProvider)(nil)
40var _ Provider = (*GoogleProvider)(nil)
@@ -90,9 +90,9 @@ func NewGoogleProvider(p *ProviderData) *GoogleProvider {
91 return &GoogleProvider{
91 return &GoogleProvider{
92 ProviderData: p,
92 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
94 // be overwritten if we configured a Google group restriction.
94 // be overwritten if we configured a Google group restriction.
95− GroupValidator: func(*sessions.SessionState) bool {
95+ groupValidator: func(*sessions.SessionState) bool {
96 return true
96 return true
@@ -165,7 +165,8 @@ func (p *GoogleProvider) Redeem(ctx context.Context, redirectURL, code string) (
166 created := time.Now()
166 created := time.Now()
167 expires := time.Now().Add(time.Duration(jsonResponse.ExpiresIn) * time.Second).Truncate(time.Second)
167 expires := time.Now().Add(time.Duration(jsonResponse.ExpiresIn) * time.Second).Truncate(time.Second)
168− s := &sessions.SessionState{
169+ return &sessions.SessionState{
169 AccessToken: jsonResponse.AccessToken,
170 AccessToken: jsonResponse.AccessToken,
170 IDToken: jsonResponse.IDToken,
171 IDToken: jsonResponse.IDToken,
171 CreatedAt: &created,
172 CreatedAt: &created,
@@ -173,19 +174,26 @@ func (p *GoogleProvider) Redeem(ctx context.Context, redirectURL, code string) (
173 RefreshToken: jsonResponse.RefreshToken,
174 RefreshToken: jsonResponse.RefreshToken,
174 Email: c.Email,
175 Email: c.Email,
175 User: c.Subject,
176 User: c.Subject,
177− p.GroupValidator(s)
178+}
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 {
179− return s, nil
185+ return nil
182// SetGroupRestriction configures the GoogleProvider to restrict access to the
188// SetGroupRestriction configures the GoogleProvider to restrict access to the
183// specified group(s). AdminEmail has to be an administrative email on the domain that is
189// specified group(s). AdminEmail has to be an administrative email on the domain that is
184// checked. CredentialsFile is the path to a json file containing a Google service
190// checked. CredentialsFile is the path to a json file containing a Google service
185// account credentials.
191// account credentials.
193+// TODO (@NickMeves) - Unit Test this OR refactor away from groupValidator func
186func (p *GoogleProvider) SetGroupRestriction(groups []string, adminEmail string, credentialsReader io.Reader) {
194func (p *GoogleProvider) SetGroupRestriction(groups []string, adminEmail string, credentialsReader io.Reader) {
187 adminService := getAdminService(adminEmail, credentialsReader)
195 adminService := getAdminService(adminEmail, credentialsReader)
188− p.GroupValidator = func(s *sessions.SessionState) bool {
196+ p.groupValidator = func(s *sessions.SessionState) bool {
189 // Reset our saved Groups in case membership changed
197 // Reset our saved Groups in case membership changed
190 // This is used by `Authorize` on every request
198 // This is used by `Authorize` on every request
191 s.Groups = make([]string, 0, len(groups))
199 s.Groups = make([]string, 0, len(groups))
@@ -266,7 +274,7 @@ func (p *GoogleProvider) RefreshSessionIfNeeded(ctx context.Context, s *sessions
268 // re-check that the user is in the proper google group(s)
276 // re-check that the user is in the proper google group(s)
269− if !p.GroupValidator(s) {
277+ if !p.groupValidator(s) {
270 return false, fmt.Errorf("%s is no longer in the group(s)", s.Email)
278 return false, fmt.Errorf("%s is no longer in the group(s)", s.Email)