Skip to content

Commit cc57e8e

Browse files
committed
Authenticate using a Bearer token to support OAuth tokens
1 parent fb0bde1 commit cc57e8e

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ resource "gitlab_project" "sample_group_project" {
5757

5858
The following arguments are supported in the `provider` block:
5959

60-
* `token` - (Optional) This is the GitLab personal access token. It must be provided, but
61-
it can also be sourced from the `GITLAB_TOKEN` environment variable.
60+
* `token` - (Required) The OAuth2 token or project/personal access token used to connect to GitLab.
61+
It must be provided, but it can also be sourced from the `GITLAB_TOKEN` environment variable.
6262

6363
* `base_url` - (Optional) This is the target GitLab base API endpoint. Providing a value is a
6464
requirement when working with GitLab CE or GitLab Enterprise e.g. `https://my.gitlab.server/api/v4/`.

gitlab/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ func (c *Config) Client() (*gitlab.Client, error) {
6767
opts = append(opts, gitlab.WithBaseURL(c.BaseURL))
6868
}
6969

70-
client, err := gitlab.NewClient(c.Token, opts...)
70+
// The OAuth method is also compatible with project/personal access tokens because they are all usable as Bearer tokens.
71+
// https://docs.gitlab.com/ee/api
72+
client, err := gitlab.NewOAuthClient(c.Token, opts...)
7173
if err != nil {
7274
return nil, err
7375
}

gitlab/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var descriptions map[string]string
112112

113113
func init() {
114114
descriptions = map[string]string{
115-
"token": "The OAuth token used to connect to GitLab.",
115+
"token": "The OAuth2 token or project/personal access token used to connect to GitLab.",
116116

117117
"base_url": "The GitLab Base API URL",
118118

0 commit comments

Comments
 (0)