Class: Procore::Auth::AccessTokenCredentials
- Inherits:
-
Object
- Object
- Procore::Auth::AccessTokenCredentials
- Defined in:
- lib/procore/auth/access_token_credentials.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Instance Method Summary collapse
-
#initialize(client_id:, client_secret:, host:) ⇒ AccessTokenCredentials
constructor
A new instance of AccessTokenCredentials.
- #refresh(token:, refresh:) ⇒ Object
- #revoke(token:) ⇒ Object
Constructor Details
#initialize(client_id:, client_secret:, host:) ⇒ AccessTokenCredentials
Returns a new instance of AccessTokenCredentials.
7 8 9 10 11 |
# 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 |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
6 7 8 |
# File 'lib/procore/auth/access_token_credentials.rb', line 6 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
6 7 8 |
# File 'lib/procore/auth/access_token_credentials.rb', line 6 def client_secret @client_secret end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/procore/auth/access_token_credentials.rb', line 6 def host @host end |
Instance Method Details
#refresh(token:, refresh:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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.}") 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:) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# 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 |