Module: Schwab::Authentication
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#access_token_expires_at ⇒ Object
readonly
Returns the value of attribute access_token_expires_at.
-
#authorization_code ⇒ Object
readonly
Returns the value of attribute authorization_code.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#redirect_uri ⇒ Object
readonly
Returns the value of attribute redirect_uri.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#refresh_token_expires_at ⇒ Object
readonly
Returns the value of attribute refresh_token_expires_at.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #authorization_header_token ⇒ Object
- #default_headers ⇒ Object
- #refresh_access_token ⇒ Object
-
#request_access_token(authorization_grant_code) ⇒ Object
Return value looks like: “token_type”=>“Bearer”, “scope”=>“api”, “refresh_token”=>“LGGun…”, “access_token”=>“I0.b2F…@”, “id_token”=>“eyJ0eXA…”.
Methods included from Util
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
8 9 10 |
# File 'lib/schwab/authentication.rb', line 8 def access_token @access_token end |
#access_token_expires_at ⇒ Object (readonly)
Returns the value of attribute access_token_expires_at.
8 9 10 |
# File 'lib/schwab/authentication.rb', line 8 def access_token_expires_at @access_token_expires_at end |
#authorization_code ⇒ Object (readonly)
Returns the value of attribute authorization_code.
8 9 10 |
# File 'lib/schwab/authentication.rb', line 8 def @authorization_code end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
8 9 10 |
# File 'lib/schwab/authentication.rb', line 8 def client_id @client_id end |
#redirect_uri ⇒ Object (readonly)
Returns the value of attribute redirect_uri.
8 9 10 |
# File 'lib/schwab/authentication.rb', line 8 def redirect_uri @redirect_uri end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
8 9 10 |
# File 'lib/schwab/authentication.rb', line 8 def refresh_token @refresh_token end |
#refresh_token_expires_at ⇒ Object (readonly)
Returns the value of attribute refresh_token_expires_at.
8 9 10 |
# File 'lib/schwab/authentication.rb', line 8 def refresh_token_expires_at @refresh_token_expires_at end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
8 9 10 |
# File 'lib/schwab/authentication.rb', line 8 def secret @secret end |
Instance Method Details
#authorization_header_token ⇒ Object
11 12 13 14 |
# File 'lib/schwab/authentication.rb', line 11 def client_id_and_secret = "#{client_id}:#{secret}" Base64.strict_encode64(client_id_and_secret) end |
#default_headers ⇒ Object
16 17 18 19 20 21 |
# File 'lib/schwab/authentication.rb', line 16 def default_headers { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': "Basic #{}" } end |
#refresh_access_token ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/schwab/authentication.rb', line 56 def refresh_access_token = { body: { grant_type: 'refresh_token', refresh_token: refresh_token, }, headers: default_headers } response = HTTParty.post( 'https://api.schwabapi.com/v1/oauth/token', ) update_tokens(response) response end |
#request_access_token(authorization_grant_code) ⇒ Object
Return value looks like:
{"expires_in"=>1800,
"token_type"=>"Bearer",
"scope"=>"api",
"refresh_token"=>"LGGun...",
"access_token"=>"I0.b2F...@",
"id_token"=>"eyJ0eXA..."}
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/schwab/authentication.rb', line 30 def request_access_token() # headers = { 'Content-Type': 'application/x-www-form-urlencoded' } # turns out didn't need this = { body: { 'grant_type': 'authorization_code', 'code': , 'redirect_uri': redirect_uri }, headers: default_headers } response = HTTParty.post( 'https://api.schwabapi.com/v1/oauth/token', ) unless response_success?(response) raise Schwab::APIError.new( "Unable to retrieve access tokens from API - #{response.code} - #{response.body}" ) end update_tokens(response) response end |