Class: Webhookdb::Oauth::FrontProvider

Inherits:
Provider
  • Object
show all
Includes:
Appydays::Loggable
Defined in:
lib/webhookdb/oauth/front_provider.rb

Direct Known Subclasses

FrontSignalwireChannelProvider

Instance Method Summary collapse

Methods inherited from Provider

#find_or_create_customer

Instance Method Details

#app_nameObject



10
# File 'lib/webhookdb/oauth/front_provider.rb', line 10

def app_name = "Front"

#authorization_url(state:) ⇒ Object



17
18
19
# File 'lib/webhookdb/oauth/front_provider.rb', line 17

def authorization_url(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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/webhookdb/oauth/front_provider.rb', line 41

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
end

#callback_urlObject



21
# File 'lib/webhookdb/oauth/front_provider.rb', line 21

def callback_url = Webhookdb.api_url + "/v1/install/#{self.key}/callback"

#client_idObject



11
# File 'lib/webhookdb/oauth/front_provider.rb', line 11

def client_id = Webhookdb::Front.client_id

#client_secretObject



12
# File 'lib/webhookdb/oauth/front_provider.rb', line 12

def client_secret = Webhookdb::Front.client_secret

#exchange_authorization_code(code:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/webhookdb/oauth/front_provider.rb', line 23

def exchange_authorization_code(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

#keyObject

Override these for custom OAuth of different apps



9
# File 'lib/webhookdb/oauth/front_provider.rb', line 9

def key = "front"

#requires_webhookdb_auth?Boolean

Returns:

  • (Boolean)


14
# File 'lib/webhookdb/oauth/front_provider.rb', line 14

def requires_webhookdb_auth? = true

#supports_webhooks?Boolean

Returns:

  • (Boolean)


15
# File 'lib/webhookdb/oauth/front_provider.rb', line 15

def supports_webhooks? = true