add validate user's token method for v2 and bug fix for reauth
diff --git a/openstack/client.go b/openstack/client.go
index 1193b19..62855f0 100644
--- a/openstack/client.go
+++ b/openstack/client.go
@@ -167,6 +167,7 @@
if options.AllowReauth {
client.ReauthFunc = func() error {
+ client.TokenID = ""
return AuthenticateV3(client, options)
}
}
diff --git a/openstack/identity/v2/tokens/requests.go b/openstack/identity/v2/tokens/requests.go
index 074a89e..193847b 100644
--- a/openstack/identity/v2/tokens/requests.go
+++ b/openstack/identity/v2/tokens/requests.go
@@ -88,3 +88,15 @@
})
return result
}
+
+// Validates and retrieves information for user's token.
+func Get(client *gophercloud.ServiceClient, token string) GetResult {
+ var result GetResult
+ _, result.Err = client.Get(CreateGetURL(client, token), &result.Body, &gophercloud.RequestOpts{
+ OkCodes: []int{200, 203},
+ })
+ if result.Err != nil {
+ return result
+ }
+ return result
+}
\ No newline at end of file
diff --git a/openstack/identity/v2/tokens/results.go b/openstack/identity/v2/tokens/results.go
index 1eddb9d..dc09357 100644
--- a/openstack/identity/v2/tokens/results.go
+++ b/openstack/identity/v2/tokens/results.go
@@ -74,6 +74,11 @@
gophercloud.Result
}
+// GetResult is the deferred response from a Get call.
+type GetResult struct {
+ gophercloud.Result
+}
+
// ExtractToken returns the just-created Token from a CreateResult.
func (result CreateResult) ExtractToken() (*Token, error) {
if result.Err != nil {
diff --git a/openstack/identity/v2/tokens/urls.go b/openstack/identity/v2/tokens/urls.go
index cd4c696..0bc51de 100644
--- a/openstack/identity/v2/tokens/urls.go
+++ b/openstack/identity/v2/tokens/urls.go
@@ -6,3 +6,8 @@
func CreateURL(client *gophercloud.ServiceClient) string {
return client.ServiceURL("tokens")
}
+
+// CreateGetURL generates the URL used to Validate Tokens.
+func CreateGetURL(client *gophercloud.ServiceClient, token string) string {
+ return client.ServiceURL("tokens", token)
+}
\ No newline at end of file
diff --git a/provider_client.go b/provider_client.go
index e813e0e..ef028cf 100644
--- a/provider_client.go
+++ b/provider_client.go
@@ -185,10 +185,21 @@
if resp.StatusCode == http.StatusUnauthorized {
if client.ReauthFunc != nil {
- err = client.ReauthFunc()
+ // make sure ReauthFunc only exec one time, or will occur endless recursive loop when admin reauth fail
+ execFunc := client.ReauthFunc
+ client.ReauthFunc = nil
+ err = execFunc()
+ client.ReauthFunc = execFunc
if err != nil {
return nil, fmt.Errorf("Error trying to re-authenticate: %s", err)
}
+
+ if options.MoreHeaders != nil {
+ options.MoreHeaders["X-Auth-Token"] = client.TokenID
+ } else {
+ options.MoreHeaders = client.AuthenticatedHeaders()
+ }
+
if options.RawBody != nil {
options.RawBody.Seek(0, 0)
}