Class: OpenAuth2::Token
Overview
Gets Access/Refresh tokens from OAuth server.
Instance Attribute Summary
Attributes inherited from Client
Instance Method Summary collapse
-
#build_code_url(params = {}) ⇒ Object
Packages info from config & passed in arguments into an url that user can to visit to authorize this app.
-
#get(params = {}) ⇒ Object
Makes request to OAuth server for access token & parses it by delegating to the appropriate provider.
-
#initialize(config) ⇒ Token
constructor
A new instance of Token.
-
#refresh(params = {}) ⇒ Object
Makes request to OAuth server to refresh the access token.
- #token_expired? ⇒ Boolean
Methods inherited from Client
#configure, #connection, #run_request, #token
Methods included from DelegateToConfig
Constructor Details
#initialize(config) ⇒ Token
Returns a new instance of Token.
7 8 9 10 |
# File 'lib/open_auth2/token.rb', line 7 def initialize(config) @config = config @faraday_url = end |
Instance Method Details
#build_code_url(params = {}) ⇒ Object
Packages info from config & passed in arguments into an url that user can to visit to authorize this app.
Examples:
token.build_code_url
#=> 'http://...'
# or
token.build_code_url(:scope => 'publish_stream')
Accepts:
params - (optional) Hash of additional config.
Returns: String (url).
27 28 29 30 31 32 |
# File 'lib/open_auth2/token.rb', line 27 def build_code_url(params={}) url = URI::HTTPS.build(:host => host, :path => , :query => encoded_body(params)) url.to_s end |
#get(params = {}) ⇒ Object
Makes request to OAuth server for access token & parses it by delegating to the appropriate provider.
Accepts:
params - (optional) Hash of additional config to be sent with
request.
41 42 43 44 45 46 |
# File 'lib/open_auth2/token.rb', line 41 def get(params={}) body = get_body_hash(params) raw_request = post(body) parse(raw_request) end |
#refresh(params = {}) ⇒ Object
Makes request to OAuth server to refresh the access token.
Accepts:
params - (optional) Hash of additional config to be sent with
request.
54 55 56 57 58 59 |
# File 'lib/open_auth2/token.rb', line 54 def refresh(params={}) body = refresh_body_hash(params) raw_request = post(body) parse(raw_request) end |
#token_expired? ⇒ Boolean
61 62 63 64 65 |
# File 'lib/open_auth2/token.rb', line 61 def token_expired? Time.now > token_expires_at rescue nil end |