add validate user's token method for v2 and bug fix for reauth
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)
}