Merge pull request #44 from 30x/XAPID-931
XAPID-931: change expiration time to seconds
diff --git a/apigee_sync_test.go b/apigee_sync_test.go
index 60652c8..4659f9c 100644
--- a/apigee_sync_test.go
+++ b/apigee_sync_test.go
@@ -198,7 +198,7 @@
}, 3)
- It("should detect apid_cluster_id change in config yaml", func () {
+ It("should detect apid_cluster_id change in config yaml", func() {
Expect(apidInfo).ToNot(BeNil())
Expect(apidInfo.ClusterID).To(Equal("bootstrap"))
Expect(apidInfo.InstanceID).ToNot(BeEmpty())
diff --git a/mock_server.go b/mock_server.go
index 6907755..f7b3600 100644
--- a/mock_server.go
+++ b/mock_server.go
@@ -38,7 +38,7 @@
product => * app_credential
*/
-const oauthExpiresIn = 2 * 60 * 1000 // 2 minutes
+const oauthExpiresIn = 2 * 60 // 2 minutes
type MockParms struct {
ReliableAPI bool
diff --git a/token.go b/token.go
index a6c118e..424c8d4 100644
--- a/token.go
+++ b/token.go
@@ -180,7 +180,7 @@
}
if token.ExpiresIn > 0 {
- token.ExpiresAt = time.Now().Add(time.Duration(token.ExpiresIn) * time.Millisecond)
+ token.ExpiresAt = time.Now().Add(time.Duration(token.ExpiresIn) * time.Second)
} else {
// no expiration, arbitrarily expire about a year from now
token.ExpiresAt = time.Now().Add(365 * 24 * time.Hour)
@@ -205,18 +205,19 @@
}
type oauthToken struct {
- IssuedAt int64 `json:"issuedAt"`
- AppName string `json:"applicationName"`
- Scope string `json:"scope"`
- Status string `json:"status"`
- ApiProdList []string `json:"apiProductList"`
- ExpiresIn int64 `json:"expiresIn"`
- DeveloperEmail string `json:"developerEmail"`
- TokenType string `json:"tokenType"`
- ClientId string `json:"clientId"`
- AccessToken string `json:"accessToken"`
- RefreshExpIn int64 `json:"refreshTokenExpiresIn"`
- RefreshCount int64 `json:"refreshCount"`
+ IssuedAt int64 `json:"issuedAt"`
+ AppName string `json:"applicationName"`
+ Scope string `json:"scope"`
+ Status string `json:"status"`
+ ApiProdList []string `json:"apiProductList"`
+ // in seconds
+ ExpiresIn int64 `json:"expiresIn"`
+ DeveloperEmail string `json:"developerEmail"`
+ TokenType string `json:"tokenType"`
+ ClientId string `json:"clientId"`
+ AccessToken string `json:"accessToken"`
+ RefreshExpIn int64 `json:"refreshTokenExpiresIn"`
+ RefreshCount int64 `json:"refreshCount"`
ExpiresAt time.Time
}
diff --git a/token_test.go b/token_test.go
index 045b318..c8ec7ba 100644
--- a/token_test.go
+++ b/token_test.go
@@ -24,7 +24,7 @@
t := &oauthToken{
AccessToken: "x",
- ExpiresIn: 120000,
+ ExpiresIn: 120,
ExpiresAt: time.Now().Add(2 * time.Minute),
}
Expect(t.refreshIn().Seconds()).To(BeNumerically(">", 0))
@@ -48,7 +48,7 @@
t := &oauthToken{
AccessToken: "x",
- ExpiresIn: 59000,
+ ExpiresIn: 59,
ExpiresAt: time.Now().Add(time.Minute - time.Second),
}
Expect(t.refreshIn().Seconds()).To(BeNumerically("<", 0))
@@ -73,7 +73,7 @@
res := oauthToken{
AccessToken: "ABCD",
- ExpiresIn: 1000,
+ ExpiresIn: 1,
}
body, err := json.Marshal(res)
Expect(err).NotTo(HaveOccurred())
@@ -100,7 +100,7 @@
res := oauthToken{
AccessToken: generateUUID(),
- ExpiresIn: 1000,
+ ExpiresIn: 1,
}
body, err := json.Marshal(res)
Expect(err).NotTo(HaveOccurred())
@@ -139,7 +139,7 @@
res := oauthToken{
AccessToken: string(count),
- ExpiresIn: 1000,
+ ExpiresIn: 1,
}
body, err := json.Marshal(res)
Expect(err).NotTo(HaveOccurred())
@@ -180,7 +180,7 @@
}
res := oauthToken{
AccessToken: string(count),
- ExpiresIn: 200000,
+ ExpiresIn: 200,
}
body, err := json.Marshal(res)
Expect(err).NotTo(HaveOccurred())