Class: Webhookdb::Oauth::FrontProvider
- Includes:
- Appydays::Loggable
- Defined in:
- lib/webhookdb/oauth/front_provider.rb
Direct Known Subclasses
Instance Method Summary collapse
- #app_name ⇒ Object
- #authorization_url(state:) ⇒ Object
- #build_marketplace_integrations(organization:, tokens:) ⇒ Object
- #callback_url ⇒ Object
- #client_id ⇒ Object
- #client_secret ⇒ Object
- #exchange_authorization_code(code:) ⇒ Object
- #key ⇒ Object
- #supports_webhooks? ⇒ Boolean
Instance Method Details
#app_name ⇒ Object
9 |
# File 'lib/webhookdb/oauth/front_provider.rb', line 9 def app_name = "Front" |
#authorization_url(state:) ⇒ Object
15 16 17 |
# File 'lib/webhookdb/oauth/front_provider.rb', line 15 def (state:) return "https://app.frontapp.com/oauth/authorize?response_type=code&redirect_uri=#{self.callback_url}&state=#{state}&client_id=#{self.client_id}" end |
#build_marketplace_integrations(organization:, tokens:) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/webhookdb/oauth/front_provider.rb', line 39 def build_marketplace_integrations(organization:, tokens:, **) # I asked the dev team at front specifically how to differentiate between instances when receiving webhooks, # and they said to look at the root url of the link provided for the resource in every response. In order to # retrieve that value for the integrations that we'll be finding or creating, we look at this token info # response. front_token_info_resp = Webhookdb::Http.get( "https://api2.frontapp.com/me", headers: Webhookdb::Front.auth_headers(tokens.access_token), logger: self.logger, timeout: Webhookdb::Front.http_timeout, ) front_token_info = front_token_info_resp.parsed_response resource_url = front_token_info.dig("_links", "self") instance_root_url = resource_url.nil? ? nil : URI.parse(resource_url).host root_sint = Webhookdb::ServiceIntegration.create_disambiguated( "front_marketplace_root_v1", organization:, api_url: instance_root_url, backfill_key: tokens.refresh_token, ) root_sint.replicator.build_dependents return root_sint end |
#callback_url ⇒ Object
19 |
# File 'lib/webhookdb/oauth/front_provider.rb', line 19 def callback_url = Webhookdb.api_url + "/v1/install/#{self.key}/callback" |
#client_id ⇒ Object
10 |
# File 'lib/webhookdb/oauth/front_provider.rb', line 10 def client_id = Webhookdb::Front.client_id |
#client_secret ⇒ Object
11 |
# File 'lib/webhookdb/oauth/front_provider.rb', line 11 def client_secret = Webhookdb::Front.client_secret |
#exchange_authorization_code(code:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/webhookdb/oauth/front_provider.rb', line 21 def (code:) token = Webhookdb::Http.post( "https://app.frontapp.com/oauth/token", { "code" => code, "redirect_uri" => self.callback_url, "grant_type" => "authorization_code", }, logger: self.logger, timeout: Webhookdb::Front.http_timeout, basic_auth: {username: self.client_id, password: self.client_secret}, ) return Webhookdb::Oauth::Tokens.new( access_token: token.parsed_response["access_token"], refresh_token: token.parsed_response["refresh_token"], ) end |
#key ⇒ Object
8 |
# File 'lib/webhookdb/oauth/front_provider.rb', line 8 def key = "front" |
#supports_webhooks? ⇒ Boolean
13 |
# File 'lib/webhookdb/oauth/front_provider.rb', line 13 def supports_webhooks? = true |