Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 6b9e1ae

Browse files
committed
Support keystone v3 token auth.
1 parent 231898e commit 6b9e1ae

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

openstack/identity/v3/tokens/errors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ var (
5252
// It may also indicate that both a DomainID and a DomainName were provided at once.
5353
ErrDomainIDOrDomainName = errors.New("You must provide exactly one of DomainID or DomainName to authenticate by Username")
5454

55-
// ErrMissingPassword indicates that no password was provided and no token is available.
56-
ErrMissingPassword = errors.New("You must provide a password to authenticate")
55+
// ErrMissingPassword indicates that no password and no token were provided and no token is available.
56+
ErrMissingPassword = errors.New("You must provide a password or a token to authenticate")
5757

5858
// ErrScopeDomainIDOrDomainName indicates that a domain ID or Name was required in a Scope, but not present.
5959
ErrScopeDomainIDOrDomainName = errors.New("You must provide exactly one of DomainID or DomainName in a Scope with ProjectName")

openstack/identity/v3/tokens/requests.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func Create(c *gophercloud.ServiceClient, options gophercloud.AuthOptions, scope
8484
}
8585

8686
if options.Password == "" {
87+
if options.TokenID != "" {
88+
c.TokenID = options.TokenID
89+
}
8790
if c.TokenID != "" {
8891
// Because we aren't using password authentication, it's an error to also provide any of the user-based authentication
8992
// parameters.

openstack/identity/v3/tokens/requests_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ func TestCreateTokenID(t *testing.T) {
135135
`)
136136
}
137137

138+
func TestCreateNewTokenID(t *testing.T) {
139+
authTokenPost(t, gophercloud.AuthOptions{TokenID: "asdf"}, nil, `
140+
{
141+
"auth": {
142+
"identity": {
143+
"methods": ["token"],
144+
"token": {
145+
"id": "asdf"
146+
}
147+
}
148+
}
149+
}
150+
`)
151+
}
152+
138153
func TestCreateProjectIDScope(t *testing.T) {
139154
options := gophercloud.AuthOptions{UserID: "fenris", Password: "g0t0h311"}
140155
scope := &Scope{ProjectID: "123456"}

0 commit comments

Comments
 (0)