Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
ca75470a
Commit
ca75470a
authored
7 years ago
by
Eric Stroczynski
Browse files
Options
Downloads
Patches
Plain Diff
connector/gitlab: correct scope strings, better default
parent
e361bc6c
Branches
isis
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
connector/gitlab/gitlab.go
+10
-5
10 additions, 5 deletions
connector/gitlab/gitlab.go
with
10 additions
and
5 deletions
connector/gitlab/gitlab.go
+
10
−
5
View file @
ca75470a
...
@@ -17,8 +17,9 @@ import (
...
@@ -17,8 +17,9 @@ import (
)
)
const
(
const
(
scopeEmail
=
"user:email"
// https://docs.gitlab.com/ee/integration/oauth_provider.html#authorized-applications
scopeOrgs
=
"read:org"
scopeUser
=
"read_user"
scopeAPI
=
"api"
)
)
// Config holds configuration options for gilab logins.
// Config holds configuration options for gilab logins.
...
@@ -78,7 +79,11 @@ type gitlabConnector struct {
...
@@ -78,7 +79,11 @@ type gitlabConnector struct {
}
}
func
(
c
*
gitlabConnector
)
oauth2Config
(
scopes
connector
.
Scopes
)
*
oauth2
.
Config
{
func
(
c
*
gitlabConnector
)
oauth2Config
(
scopes
connector
.
Scopes
)
*
oauth2
.
Config
{
gitlabScopes
:=
[]
string
{
"api"
}
gitlabScopes
:=
[]
string
{
scopeUser
}
if
scopes
.
Groups
{
gitlabScopes
=
[]
string
{
scopeAPI
}
}
gitlabEndpoint
:=
oauth2
.
Endpoint
{
AuthURL
:
c
.
baseURL
+
"/oauth/authorize"
,
TokenURL
:
c
.
baseURL
+
"/oauth/token"
}
gitlabEndpoint
:=
oauth2
.
Endpoint
{
AuthURL
:
c
.
baseURL
+
"/oauth/authorize"
,
TokenURL
:
c
.
baseURL
+
"/oauth/token"
}
return
&
oauth2
.
Config
{
return
&
oauth2
.
Config
{
ClientID
:
c
.
clientID
,
ClientID
:
c
.
clientID
,
...
@@ -198,7 +203,7 @@ func (c *gitlabConnector) Refresh(ctx context.Context, s connector.Scopes, ident
...
@@ -198,7 +203,7 @@ func (c *gitlabConnector) Refresh(ctx context.Context, s connector.Scopes, ident
// a bearer token as part of the request.
// a bearer token as part of the request.
func
(
c
*
gitlabConnector
)
user
(
ctx
context
.
Context
,
client
*
http
.
Client
)
(
gitlabUser
,
error
)
{
func
(
c
*
gitlabConnector
)
user
(
ctx
context
.
Context
,
client
*
http
.
Client
)
(
gitlabUser
,
error
)
{
var
u
gitlabUser
var
u
gitlabUser
req
,
err
:=
http
.
NewRequest
(
"GET"
,
c
.
baseURL
+
"/api/v
3
/user"
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
c
.
baseURL
+
"/api/v
4
/user"
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
u
,
fmt
.
Errorf
(
"gitlab: new req: %v"
,
err
)
return
u
,
fmt
.
Errorf
(
"gitlab: new req: %v"
,
err
)
}
}
...
@@ -229,7 +234,7 @@ func (c *gitlabConnector) user(ctx context.Context, client *http.Client) (gitlab
...
@@ -229,7 +234,7 @@ func (c *gitlabConnector) user(ctx context.Context, client *http.Client) (gitlab
// which inserts a bearer token as part of the request.
// which inserts a bearer token as part of the request.
func
(
c
*
gitlabConnector
)
groups
(
ctx
context
.
Context
,
client
*
http
.
Client
)
([]
string
,
error
)
{
func
(
c
*
gitlabConnector
)
groups
(
ctx
context
.
Context
,
client
*
http
.
Client
)
([]
string
,
error
)
{
apiURL
:=
c
.
baseURL
+
"/api/v
3
/groups"
apiURL
:=
c
.
baseURL
+
"/api/v
4
/groups"
reNext
:=
regexp
.
MustCompile
(
"<(.*)>; rel=
\"
next
\"
"
)
reNext
:=
regexp
.
MustCompile
(
"<(.*)>; rel=
\"
next
\"
"
)
reLast
:=
regexp
.
MustCompile
(
"<(.*)>; rel=
\"
last
\"
"
)
reLast
:=
regexp
.
MustCompile
(
"<(.*)>; rel=
\"
last
\"
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment