-
Notifications
You must be signed in to change notification settings - Fork 1
Configure your Twitter OAuth Consumer tokens and secrets using YAML
License
peteonrails/yaml_twitter_oauth
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
= Important Note
There are now better choices for capturing this functionality within config.yml in Rails apps.
The pattern is now to use a monolithic config.yml file and load it with an initializer. It has the
benefit of letting you set application and environment specific config parameters other than Twitter creds.
This plugin will be maintained until at least Rails 5, but it is not that useful anymore. See below for a better
implementation.
= YAML Twitter OAuth
YAML Twitter OAuth makes it easy to keep track of your Twitter OAuth
consumer tokens and secrets declaratively using YAML. It is designed for
applications that either:
1. Need to maintain multiple Consumer Key/Secret pairs for different environments
2. Need to change the secret from time to time and wwant to do so in YML instead of code
Install with:
script/plugin install git://github.com/peteonrails/yaml_twitter_oauth.git
To use, simply create a <tt>config/twitter_oauth.yml</tt> file that follows the sample
pattern below. (A sample twitter_oauth.yml template file is found in the templates/
directory of this plugin.)
Sample:
defaults: &defaults
request_token_url: http://twitter.com/oauth/request_token
access_token_url: http://twitter.com/oauth/access_token
authorize_url: http://twitter.com/oauth/authorize
development:
<<: *defaults
consumer_key: 12345678
consumer_secret: this-is-your-application-secret
staging:
<<: *defaults
consumer_key: 12345678
consumer_secret: this-is-your-application-secret
production:
<<: *defaults
consumer_key: 12345678
consumer_secret: this-is-your-application-secret
Then in your client code that you use to generate Request and Access Tokens, you can do this:
Twitter::OAuth.new(YamlTwitter.oauth[:consumer_key], YamlTwitter.oauth[:consumer_secret])
= Using Rails with config/config.yml instead
The convention has become to use a config/config.yml file to configure application specific
settings. To duplicate the functionality of this plugin, create a config.yml like this (also found
in the file templates/config.yml.example).
development:
twitter:
request_token_url: http://twitter.com/oauth/request_token
access_token_url: http://twitter.com/oauth/access_token
authorize_url: http://twitter.com/oauth/authorize
consumer_key: 12345678
consumer_secret: this-is-your-application-secret
test:
twitter:
request_token_url: http://twitter.com/oauth/request_token
access_token_url: http://twitter.com/oauth/access_token
authorize_url: http://twitter.com/oauth/authorize
consumer_key: 12345678
consumer_secret: this-is-your-application-secret
Then, in the file config/initializers/load_config.rb:
APP_CONFIG = YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env]
Then, your code to authorize against Twitter could be:
Twitter::OAuth.new(APP_CONFIG[:twitter][:consumer_key], APP_CONFIG[:twitter][[:consumer_secret])
NOTE: This example was kept to map to the README example code. I'd recommend you check out OmniAuth
if you are authenticating aginst Twitter OAuth.
About
Configure your Twitter OAuth Consumer tokens and secrets using YAML
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published