class Procore::Auth::AccessTokenCredentials
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/access_token_credentials.rb, line 7 def initialize(client_id:, client_secret:, host:) @client_id = client_id @client_secret = client_secret @host = host end
Public Instance Methods
refresh(token:, refresh:)
click to toggle source
# File lib/procore/auth/access_token_credentials.rb, line 13 def refresh(token:, refresh:) begin token = OAuth2::AccessToken.new(client, token, refresh_token: refresh) new_token = token.refresh! 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 raise OAuthError.new( "Host is not a valid URI. Check your host option to make sure it " \ "is a properly formed url", ) end end
revoke(token:)
click to toggle source
# File lib/procore/auth/access_token_credentials.rb, line 35 def revoke(token:) request = { client_id: @client_id, client_secret: @client_secret, token: token.access_token, } client.request(:post, "/oauth/revoke", body: request) rescue RestClient::ExceptionWithResponse raise OAuthError.new(e.description, response: e.response) end
Private Instance Methods
client()
click to toggle source
# File lib/procore/auth/access_token_credentials.rb, line 48 def client OAuth2::Client.new( client_id, client_secret, site: "#{host}/oauth/token", ) end