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

Commit 5b259d7

Browse files
committed
Support keystone v3 scoped token auth.
1 parent 680aa02 commit 5b259d7

File tree

3 files changed

+64
-13
lines changed

3 files changed

+64
-13
lines changed

openstack/client_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ import (
99
th "github.com/rackspace/gophercloud/testhelper"
1010
)
1111

12-
func TestAuthenticatedClientV3(t *testing.T) {
12+
func TestPasswordAuthenticatedClientV3(t *testing.T) {
13+
testAuthenticatedClientV3(t, false)
14+
}
15+
16+
func TestTokenAuthenticatedClientV3(t *testing.T) {
17+
testAuthenticatedClientV3(t, true)
18+
}
19+
20+
func testAuthenticatedClientV3(t *testing.T, tokenAuth bool) {
1321
th.SetupHTTP()
1422
defer th.TeardownHTTP()
1523

@@ -48,10 +56,14 @@ func TestAuthenticatedClientV3(t *testing.T) {
4856
})
4957

5058
options := gophercloud.AuthOptions{
51-
UserID: "me",
52-
Password: "secret",
5359
IdentityEndpoint: th.Endpoint(),
5460
}
61+
if tokenAuth {
62+
options.TokenID = ID
63+
} else {
64+
options.UserID = "me"
65+
options.Password = "secret"
66+
}
5567
client, err := AuthenticatedClient(options)
5668
th.AssertNoErr(t, err)
5769
th.CheckEquals(t, ID, client.TokenID)

openstack/identity/v3/tokens/requests.go

Lines changed: 3 additions & 6 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.
@@ -93,12 +96,6 @@ func Create(c *gophercloud.ServiceClient, options gophercloud.AuthOptions, scope
9396
if options.UserID != "" {
9497
return createErr(ErrUserIDWithToken)
9598
}
96-
if options.DomainID != "" {
97-
return createErr(ErrDomainIDWithToken)
98-
}
99-
if options.DomainName != "" {
100-
return createErr(ErrDomainNameWithToken)
101-
}
10299

103100
// Configure the request for Token authentication.
104101
req.Auth.Identity.Methods = []string{"token"}

openstack/identity/v3/tokens/requests_test.go

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,54 @@ func TestCreateFailureTokenIDUserID(t *testing.T) {
296296
authTokenPostErr(t, gophercloud.AuthOptions{UserID: "something"}, nil, true, ErrUserIDWithToken)
297297
}
298298

299-
func TestCreateFailureTokenIDDomainID(t *testing.T) {
300-
authTokenPostErr(t, gophercloud.AuthOptions{DomainID: "something"}, nil, true, ErrDomainIDWithToken)
299+
func TestCreateTokenIDDomainID(t *testing.T) {
300+
scope := &Scope{ProjectName: "world-domination", DomainID: "1000"}
301+
authTokenPost(t, gophercloud.AuthOptions{DomainID: "something"}, scope, `
302+
{
303+
"auth": {
304+
"identity": {
305+
"methods": [
306+
"token"
307+
],
308+
"token": {
309+
"id": "12345abcdef"
310+
}
311+
},
312+
"scope": {
313+
"project": {
314+
"domain": {
315+
"id": "1000"
316+
},
317+
"name": "world-domination"
318+
}
319+
}
320+
}
321+
}`)
301322
}
302323

303-
func TestCreateFailureTokenIDDomainName(t *testing.T) {
304-
authTokenPostErr(t, gophercloud.AuthOptions{DomainName: "something"}, nil, true, ErrDomainNameWithToken)
324+
func TestCreateTokenIDDomainName(t *testing.T) {
325+
scope := &Scope{ProjectName: "world-domination", DomainName: "evil-plans"}
326+
authTokenPost(t, gophercloud.AuthOptions{DomainName: "something"}, scope, `
327+
{
328+
"auth": {
329+
"identity": {
330+
"methods": [
331+
"token"
332+
],
333+
"token": {
334+
"id": "12345abcdef"
335+
}
336+
},
337+
"scope": {
338+
"project": {
339+
"domain": {
340+
"name": "evil-plans"
341+
},
342+
"name": "world-domination"
343+
}
344+
}
345+
}
346+
}`)
305347
}
306348

307349
func TestCreateFailureMissingUser(t *testing.T) {

0 commit comments

Comments
 (0)