Skip to content

Commit

Permalink
Removes Configuration#access_token to avoid stale/duplicate tokens (#14)
Browse files Browse the repository at this point in the history
* Removes Configuration#access_token to avoid stale tokens in the env

Rather than allowing the Access Token to be set via Configuration, we'll
always either grab it from the cache (if configured) or generate a new
token from the Help Scout API. This also prevents the situation where
the configuration instance and the api instance have competing tokens.

We can still manually set the token for testing purposes via
`HelpScout.api.access_token=`.

* Adds CHANGELOG
  • Loading branch information
prsimp authored Jul 19, 2019
1 parent 0a3b933 commit 00a6d93
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
### master (unreleased)

Breaking Changes:

* Removes HelpScout::Configuration#access_token and writer to avoid multiple sources
of truth for access token values (#14)

Enhancements:

* Adds support for `HelpScout::Thread.create`, `HelpScout::Thread.get`, and
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ And then execute:
HelpScout.configure do |config|
config.app_id = ENV["HELP_SCOUT_APP_ID"]
config.app_secret = ENV["HELP_SCOUT_APP_SECRET"]

config.access_token = HelpScout::API::AccessToken.create
end
```

Expand Down
1 change: 0 additions & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ HelpScout.configure do |config|
config.app_id = ENV.fetch('HELP_SCOUT_APP_ID')
config.app_secret = ENV.fetch('HELP_SCOUT_APP_SECRET')
config.default_mailbox = ENV.fetch('HELP_SCOUT_DEFAULT_MAILBOX')
config.access_token = ENV.fetch('HELP_SCOUT_ACCESS_TOKEN', nil)
end

begin
Expand Down
1 change: 0 additions & 1 deletion lib/help_scout-sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def configuration

def configure
yield(configuration)
api.access_token = HelpScout.configuration.access_token
end

def default_mailbox
Expand Down
2 changes: 1 addition & 1 deletion lib/help_scout/api/access_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create
end

def refresh!
return HelpScout.api.access_token unless HelpScout.access_token.nil? || HelpScout.access_token.stale?
return HelpScout.access_token unless HelpScout.access_token.nil? || HelpScout.access_token.stale?

HelpScout.api.access_token = create
end
Expand Down
7 changes: 0 additions & 7 deletions lib/help_scout/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
module HelpScout
class Configuration
attr_accessor :app_id, :app_secret, :default_mailbox, :token_cache
attr_reader :access_token
attr_writer :token_cache_key

DEFAULT_CACHE_KEY = 'help_scout_token_cache'

def access_token=(token_value)
return unless token_value

@access_token = HelpScout::API::AccessToken.new(access_token: token_value)
end

def token_cache_key
return @token_cache_key if defined?(@token_cache_key)

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def with_config(new_configs = {})
HelpScout.configure do |config|
config.app_id = ENV.fetch('HELP_SCOUT_APP_ID')
config.app_secret = ENV.fetch('HELP_SCOUT_APP_SECRET')
config.access_token = ENV.fetch('HELP_SCOUT_ACCESS_TOKEN', nil)
config.default_mailbox = ENV.fetch('TEST_MAILBOX_ID')
end
HelpScout.api.access_token = ENV.fetch('HELP_SCOUT_ACCESS_TOKEN', 'bogustoken')

VCR.configure do |config|
config.cassette_library_dir = 'spec/cassettes'
Expand Down

0 comments on commit 00a6d93

Please sign in to comment.