allow token/tenantID authentication
diff --git a/openstack/identity/v2/tokens/requests.go b/openstack/identity/v2/tokens/requests.go
index efa054f..356bf87 100644
--- a/openstack/identity/v2/tokens/requests.go
+++ b/openstack/identity/v2/tokens/requests.go
@@ -1,6 +1,10 @@
package tokens
-import "github.com/rackspace/gophercloud"
+import (
+ "fmt"
+
+ "github.com/rackspace/gophercloud"
+)
// AuthOptionsBuilder describes any argument that may be passed to the Create call.
type AuthOptionsBuilder interface {
@@ -38,20 +42,24 @@
return nil, ErrDomainNameProvided
}
- // Username and Password are always required.
- if auth.Username == "" {
- return nil, ErrUsernameRequired
- }
- if auth.Password == "" {
- return nil, ErrPasswordRequired
- }
-
// Populate the request map.
authMap := make(map[string]interface{})
- authMap["passwordCredentials"] = map[string]interface{}{
- "username": auth.Username,
- "password": auth.Password,
+ if auth.Username != "" {
+ if auth.Password != "" {
+ authMap["passwordCredentials"] = map[string]interface{}{
+ "username": auth.Username,
+ "password": auth.Password,
+ }
+ } else {
+ return nil, ErrPasswordRequired
+ }
+ } else if auth.Token != "" {
+ authMap["token"] = map[string]interface{}{
+ "id": auth.Token,
+ }
+ } else {
+ return nil, fmt.Errorf("You must provide either username/password or tenantID/token values.")
}
if auth.TenantID != "" {