Skip to content
Snippets Groups Projects
Commit 1c0d014a authored by Kevin Lyda's avatar Kevin Lyda :speech_balloon:
Browse files

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.
parent a3692e76
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -27,7 +27,7 @@ type Config struct { ...@@ -27,7 +27,7 @@ type Config struct {
allusers bool 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) { func New(c *config.Auth) (auth.Provider, error) {
uw := make(map[string]bool) uw := make(map[string]bool)
for _, u := range c.UsersWhitelist { for _, u := range c.UsersWhitelist {
...@@ -108,14 +108,14 @@ func (c *Config) Valid(token *oauth2.Token) bool { ...@@ -108,14 +108,14 @@ func (c *Config) Valid(token *oauth2.Token) bool {
return false return false
} }
// Revoke is a no-op revoke method. GitHub doesn't seem to allow token // Revoke is a no-op revoke method. Gitlab doesn't allow token
// revocation - tokens are indefinite and there are no refresh options etc. // revocation - tokens live for an hour.
// Returns nil to satisfy the Provider interface. // Returns nil to satisfy the Provider interface.
func (c *Config) Revoke(token *oauth2.Token) error { func (c *Config) Revoke(token *oauth2.Token) error {
return nil return nil
} }
// StartSession retrieves an authentication endpoint from Github. // StartSession retrieves an authentication endpoint from Gitlab.
func (c *Config) StartSession(state string) *auth.Session { func (c *Config) StartSession(state string) *auth.Session {
return &auth.Session{ return &auth.Session{
AuthURL: c.config.AuthCodeURL(state), AuthURL: c.config.AuthCodeURL(state),
...@@ -124,19 +124,10 @@ func (c *Config) StartSession(state string) *auth.Session { ...@@ -124,19 +124,10 @@ func (c *Config) StartSession(state string) *auth.Session {
// Exchange authorizes the session and returns an access token. // Exchange authorizes the session and returns an access token.
func (c *Config) Exchange(code string) (*oauth2.Token, error) { func (c *Config) Exchange(code string) (*oauth2.Token, error) {
t, err := c.config.Exchange(oauth2.NoContext, code) return 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
} }
// 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 { func (c *Config) Username(token *oauth2.Token) string {
client := gitlabapi.NewOAuthClient(nil, token.AccessToken) client := gitlabapi.NewOAuthClient(nil, token.AccessToken)
client.SetBaseURL(c.baseurl) client.SetBaseURL(c.baseurl)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment