Class: BingAdsRubySdk::OAuth2::AuthorizationHandler
- Inherits:
-
Object
- Object
- BingAdsRubySdk::OAuth2::AuthorizationHandler
- Defined in:
- lib/bing_ads_ruby_sdk/oauth2/authorization_handler.rb
Overview
Adds some useful methods to Signet::OAuth2::Client
Instance Method Summary collapse
- #code_url ⇒ String?
-
#fetch_from_url(url) ⇒ Object
Once you have completed the oauth process in your browser using the code_url copy the url your browser has been redirected to and use it as argument here.
-
#fetch_or_refresh ⇒ String
Get or fetch an access token.
-
#initialize(developer_token:, client_id:, store:) ⇒ AuthorizationHandler
constructor
A new instance of AuthorizationHandler.
Constructor Details
#initialize(developer_token:, client_id:, store:) ⇒ AuthorizationHandler
Returns a new instance of AuthorizationHandler.
12 13 14 15 16 |
# File 'lib/bing_ads_ruby_sdk/oauth2/authorization_handler.rb', line 12 def initialize(developer_token:, client_id:, store:) @client = build_client(developer_token, client_id) @store = store refresh_from_store end |
Instance Method Details
#code_url ⇒ String?
20 21 22 23 24 25 |
# File 'lib/bing_ads_ruby_sdk/oauth2/authorization_handler.rb', line 20 def code_url return nil if client.client_id.nil? "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=#{client.client_id}&"\ "scope=offline_access+https://ads.microsoft.com/ads.manage&response_type=code&"\ "redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient" end |
#fetch_from_url(url) ⇒ Object
Once you have completed the oauth process in your browser using the code_url copy the url your browser has been redirected to and use it as argument here
29 30 31 32 33 34 35 36 |
# File 'lib/bing_ads_ruby_sdk/oauth2/authorization_handler.rb', line 29 def fetch_from_url(url) codes = extract_codes(url) return false if codes.none? fetch_from_code(codes.last) rescue Signet::AuthorizationError, URI::InvalidURIError false end |
#fetch_or_refresh ⇒ String
Get or fetch an access token.
40 41 42 43 44 45 46 |
# File 'lib/bing_ads_ruby_sdk/oauth2/authorization_handler.rb', line 40 def fetch_or_refresh if client.expired? client.refresh! store.write(token_data) end client.access_token end |