From 1c0d014a7d86b46ed875b7f6a6fd4ca12067939f Mon Sep 17 00:00:00 2001
From: Kevin Lyda <kevin@ie.suberic.net>
Date: Sun, 22 Jan 2017 14:40:39 +0000
Subject: [PATCH] Cleanup some remaining minor issues.

Make sure comments refer to Gitlab, not Github. The Exchange
function gets enough data from Gitlab OAuth that it doesn't
need the kludge the Github method required.
---
 server/auth/gitlab/gitlab.go | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/server/auth/gitlab/gitlab.go b/server/auth/gitlab/gitlab.go
index 3b8e96d8..622c6fd2 100644
--- a/server/auth/gitlab/gitlab.go
+++ b/server/auth/gitlab/gitlab.go
@@ -27,7 +27,7 @@ type Config struct {
 	allusers  bool
 }
 
-// New creates a new Github provider from a configuration.
+// New creates a new Gitlab provider from a configuration.
 func New(c *config.Auth) (auth.Provider, error) {
 	uw := make(map[string]bool)
 	for _, u := range c.UsersWhitelist {
@@ -108,14 +108,14 @@ func (c *Config) Valid(token *oauth2.Token) bool {
 	return false
 }
 
-// Revoke is a no-op revoke method. GitHub doesn't seem to allow token
-// revocation - tokens are indefinite and there are no refresh options etc.
+// Revoke is a no-op revoke method. Gitlab doesn't allow token
+// revocation - tokens live for an hour.
 // Returns nil to satisfy the Provider interface.
 func (c *Config) Revoke(token *oauth2.Token) error {
 	return nil
 }
 
-// StartSession retrieves an authentication endpoint from Github.
+// StartSession retrieves an authentication endpoint from Gitlab.
 func (c *Config) StartSession(state string) *auth.Session {
 	return &auth.Session{
 		AuthURL: c.config.AuthCodeURL(state),
@@ -124,19 +124,10 @@ func (c *Config) StartSession(state string) *auth.Session {
 
 // Exchange authorizes the session and returns an access token.
 func (c *Config) Exchange(code string) (*oauth2.Token, error) {
-	t, err := c.config.Exchange(oauth2.NoContext, code)
-	if err != nil {
-		return nil, err
-	}
-	// Github tokens don't have an expiry. Set one so that the session expires
-	// after a period.
-	if t.Expiry.Unix() <= 0 {
-		t.Expiry = time.Now().Add(1 * time.Hour)
-	}
-	return t, nil
+	return c.config.Exchange(oauth2.NoContext, code)
 }
 
-// Username retrieves the username portion of the user's email address.
+// Username retrieves the username of the Gitlab user.
 func (c *Config) Username(token *oauth2.Token) string {
 	client := gitlabapi.NewOAuthClient(nil, token.AccessToken)
 	client.SetBaseURL(c.baseurl)
-- 
GitLab