From ea624f2b479839868a71737a8417d07ef96827d4 Mon Sep 17 00:00:00 2001 From: Matt Whitslar Date: Wed, 17 May 2017 18:32:58 -0400 Subject: [PATCH] Adding better token lifetime management --- lib/zimbra.rb | 12 ++---------- lib/zimbra/handsoap_account_service.rb | 2 +- lib/zimbra/handsoap_service.rb | 2 +- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/zimbra.rb b/lib/zimbra.rb index ba4b258..8ad80a2 100644 --- a/lib/zimbra.rb +++ b/lib/zimbra.rb @@ -53,19 +53,11 @@ def debug # Authorization token - obtained after successful login def auth_token - @@auth_token.token + @@auth_token ||= nil end def account_auth_token - @@account_auth_token.token - end - - def auth_token_expired? - @@auth_token.expired? - end - - def account_auth_token_expired? - @@account_auth_token.expired? + @@account_auth_token ||= nil end # Log into the zimbra SOAP service. This is required before any other action is performed diff --git a/lib/zimbra/handsoap_account_service.rb b/lib/zimbra/handsoap_account_service.rb index bcb118a..3edc221 100644 --- a/lib/zimbra/handsoap_account_service.rb +++ b/lib/zimbra/handsoap_account_service.rb @@ -34,7 +34,7 @@ def on_create_document(doc) header = doc.find("Header") header.add "n1:context" do |s| s.set_attr "env:mustUnderstand", "0" - s.add "n1:authToken", Zimbra.account_auth_token + s.add "n1:authToken", Zimbra.account_auth_token.token end end def on_response_document(doc) diff --git a/lib/zimbra/handsoap_service.rb b/lib/zimbra/handsoap_service.rb index 72785d3..a811beb 100644 --- a/lib/zimbra/handsoap_service.rb +++ b/lib/zimbra/handsoap_service.rb @@ -62,7 +62,7 @@ def on_create_document(doc) header = doc.find("Header") header.add "n1:context" do |s| s.set_attr "env:mustUnderstand", "0" - s.add "n1:authToken", Zimbra.auth_token + s.add "n1:authToken", Zimbra.auth_token.token end end def on_response_document(doc)