class Procore::Auth::ClientCredentials
Attributes
client_id[R]
client_secret[R]
host[R]
Public Class Methods
new(client_id:, client_secret:, host:)
click to toggle source
# File lib/procore/auth/client_credentials.rb, line 7 def initialize(client_id:, client_secret:, host:) unless client_id && client_secret raise OAuthError.new("No client_id or client_secret provided.") end @client_id = client_id @client_secret = client_secret @host = host end
Public Instance Methods
refresh(*)
click to toggle source
# File lib/procore/auth/client_credentials.rb, line 17 def refresh(*) begin new_token = client .client_credentials .get_token({}, auth_scheme: :request_body) 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
Private Instance Methods
client()
click to toggle source
# File lib/procore/auth/client_credentials.rb, line 42 def client OAuth2::Client.new( client_id, client_secret, site: "#{host}/oauth/token", ) end