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
Constant Summary collapse
- SCOPE =
"https://ads.microsoft.com/msads.manage"
- AUTHORIZE_URI =
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize"
- TOKEN_URI =
"https://login.microsoftonline.com/common/oauth2/v2.0/token"
- REDIRECT_URI =
"https://login.microsoftonline.com/common/oauth2/nativeclient"
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:, client_secret: nil) ⇒ AuthorizationHandler
constructor
A new instance of AuthorizationHandler.
Constructor Details
#initialize(developer_token:, client_id:, store:, client_secret: nil) ⇒ AuthorizationHandler
Returns a new instance of AuthorizationHandler.
16 17 18 19 20 21 |
# File 'lib/bing_ads_ruby_sdk/oauth2/authorization_handler.rb', line 16 def initialize(developer_token:, client_id:, store:, client_secret: nil) @client = Signet::OAuth2::Client.new( client_params(developer_token, client_id, client_secret) ) @store = store end |
Instance Method Details
#code_url ⇒ String?
25 26 27 28 29 30 |
# File 'lib/bing_ads_ruby_sdk/oauth2/authorization_handler.rb', line 25 def code_url return nil if client.client_id.nil? "#{AUTHORIZE_URI}?client_id=#{client.client_id}&" \ "scope=offline_access+#{SCOPE}&response_type=code&" \ "redirect_uri=#{REDIRECT_URI}" 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
34 35 36 37 38 39 |
# File 'lib/bing_ads_ruby_sdk/oauth2/authorization_handler.rb', line 34 def fetch_from_url(url) codes = extract_codes(url) return false if codes.none? fetch_from_code(codes.last) end |
#fetch_or_refresh ⇒ String
Get or fetch an access token.
43 44 45 46 47 |
# File 'lib/bing_ads_ruby_sdk/oauth2/authorization_handler.rb', line 43 def fetch_or_refresh refresh_from_store fetch_and_write if client.expired? client.access_token end |