Method: Procore::Auth::ClientCredentials#refresh

Defined in:
lib/procore/auth/client_credentials.rb

#refreshObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/procore/auth/client_credentials.rb', line 17

def refresh(*)
  begin
    new_token = client
      .client_credentials
      .get_token

    Procore::Auth::Token.new(
      access_token: new_token.token,
      refresh_token: new_token.refresh_token,
      expires_at: new_token.expires_at,
    )
  rescue OAuth2::Error => e
    raise OAuthError.new(e.description, response: e.response)
  rescue Faraday::ConnectionFailed => e
    raise APIConnectionError.new("Connection Error: #{e.message}")
  rescue URI::BadURIError, URI::InvalidURIError
    raise OAuthError.new(
      "Host is not a valid URI. Check your host option to make sure it "   \
      "is a properly formed url",
    )
  end
end