lib/rdstation/authentication.rb in rdstation-ruby-client-2.0.0 vs lib/rdstation/authentication.rb in rdstation-ruby-client-2.1.0

- old
+ new

@@ -3,10 +3,11 @@ class Authentication include HTTParty AUTH_TOKEN_URL = 'https://api.rd.services/auth/token'.freeze DEFAULT_HEADERS = { 'Content-Type' => 'application/json' }.freeze + REVOKE_URL = 'https://api.rd.services/auth/revoke'.freeze def initialize(client_id, client_secret) @client_id = client_id @client_secret = client_secret end @@ -45,10 +46,33 @@ def update_access_token(refresh_token) response = post_to_auth_endpoint(refresh_token: refresh_token) ApiResponse.build(response) end + def self.revoke(access_token:) + response = self.post( + REVOKE_URL, + body: revoke_body(access_token), + headers: revoke_headers(access_token) + ) + ApiResponse.build(response) + end + private + + def self.revoke_body(access_token) + URI.encode_www_form({ + token: access_token, + token_type_hint: 'access_token' + }) + end + + def self.revoke_headers(access_token) + { + "Authorization" => "Bearer #{access_token}", + "Content-Type" => "application/x-www-form-urlencoded" + } + end def post_to_auth_endpoint(params) default_body = { client_id: @client_id, client_secret: @client_secret } body = default_body.merge(params)