Skip to main content
Sign in
Snippets Groups Projects
Commit 6adb1056 authored by Kevin Lyda's avatar Kevin Lyda :speech_balloon:
Browse files

Switch to siteurl.

Replace authurl, tokenurl and baseurl with just the one: siteurl.
The rest can be derived.
parent 973e8f04
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ package gitlab ...@@ -2,6 +2,7 @@ package gitlab
import ( import (
"errors" "errors"
"fmt"
"net/http" "net/http"
"time" "time"
...@@ -39,17 +40,12 @@ func New(c *config.Auth) (auth.Provider, error) { ...@@ -39,17 +40,12 @@ func New(c *config.Auth) (auth.Provider, error) {
if !allUsers && c.ProviderOpts["group"] == "" && len(uw) == 0 { if !allUsers && c.ProviderOpts["group"] == "" && len(uw) == 0 {
return nil, errors.New("gitlab_opts group and the users whitelist must not be both empty if allusers isn't true") return nil, errors.New("gitlab_opts group and the users whitelist must not be both empty if allusers isn't true")
} }
authUrl := "https://gitlab.com/oauth/authorize" siteUrl := "https://gitlab.com/"
if c.ProviderOpts["authurl"] != "" { if c.ProviderOpts["siteurl"] != "" {
authUrl = c.ProviderOpts["authurl"] siteUrl = c.ProviderOpts["siteurl"]
if siteUrl[len(siteUrl)-1] != '/' {
return nil, errors.New("gitlab_opts siteurl must end in /")
} }
tokenUrl := "https://gitlab.com/oauth/token"
if c.ProviderOpts["tokenurl"] != "" {
tokenUrl = c.ProviderOpts["tokenurl"]
}
baseUrl := "https://gitlab.com/api/v3/"
if c.ProviderOpts["baseurl"] != "" {
baseUrl = c.ProviderOpts["baseurl"]
} }
return &Config{ return &Config{
config: &oauth2.Config{ config: &oauth2.Config{
...@@ -57,8 +53,8 @@ func New(c *config.Auth) (auth.Provider, error) { ...@@ -57,8 +53,8 @@ func New(c *config.Auth) (auth.Provider, error) {
ClientSecret: c.OauthClientSecret, ClientSecret: c.OauthClientSecret,
RedirectURL: c.OauthCallbackURL, RedirectURL: c.OauthCallbackURL,
Endpoint: oauth2.Endpoint{ Endpoint: oauth2.Endpoint{
AuthURL: authUrl, AuthURL: siteUrl + "oauth/authorize",
TokenURL: tokenUrl, TokenURL: siteUrl + "oauth/token",
}, },
Scopes: []string{ Scopes: []string{
"api", "api",
...@@ -67,7 +63,7 @@ func New(c *config.Auth) (auth.Provider, error) { ...@@ -67,7 +63,7 @@ func New(c *config.Auth) (auth.Provider, error) {
group: c.ProviderOpts["group"], group: c.ProviderOpts["group"],
whitelist: uw, whitelist: uw,
allusers: allUsers, allusers: allUsers,
baseurl: baseUrl, baseurl: siteUrl + "api/v3/",
}, nil }, nil
} }
...@@ -104,6 +100,7 @@ func (c *Config) Valid(token *oauth2.Token) bool { ...@@ -104,6 +100,7 @@ func (c *Config) Valid(token *oauth2.Token) bool {
return false return false
} }
for _, g := range groups { for _, g := range groups {
fmt.Printf("group: %s = '%+v'\n", g.Path, g)
if g.Path == c.group { if g.Path == c.group {
return true return true
} }
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment