Class: RDStation::Authentication
- Inherits:
-
Object
- Object
- RDStation::Authentication
- Includes:
- HTTParty
- Defined in:
- lib/rdstation/authentication.rb
Constant Summary collapse
- 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
Class Method Summary collapse
Instance Method Summary collapse
-
#auth_url(redirect_url) ⇒ Object
param redirect_url URL that the user will be redirected after confirming application authorization.
-
#authenticate(code) ⇒ Object
Public: Get the credentials from RD Station API.
-
#initialize(client_id = nil, client_secret = nil) ⇒ Authentication
constructor
A new instance of Authentication.
-
#update_access_token(refresh_token) ⇒ Object
param refresh_token parameter sent by RDStation after authenticate.
Constructor Details
#initialize(client_id = nil, client_secret = nil) ⇒ Authentication
Returns a new instance of Authentication.
10 11 12 13 14 |
# File 'lib/rdstation/authentication.rb', line 10 def initialize(client_id = nil, client_secret = nil) warn_deprecation if client_id || client_secret @client_id = client_id || RDStation.configuration&.client_id @client_secret = client_secret || RDStation.configuration&.client_secret end |
Class Method Details
.revoke(access_token:) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/rdstation/authentication.rb', line 52 def self.revoke(access_token:) response = self.post( REVOKE_URL, body: revoke_body(access_token), headers: revoke_headers(access_token) ) ApiResponse.build(response) end |
Instance Method Details
#auth_url(redirect_url) ⇒ Object
param redirect_url
URL that the user will be redirected
after confirming application
21 22 23 |
# File 'lib/rdstation/authentication.rb', line 21 def auth_url(redirect_url) "https://api.rd.services/auth/dialog?client_id=#{@client_id}&redirect_url=#{redirect_url}" end |
#authenticate(code) ⇒ Object
Public: Get the credentials from RD Station API
code - The code String sent by RDStation after the user confirms authorization.
Examples
authenticate("123")
# => { 'access_token' => '54321', 'expires_in' => 86_400, 'refresh_token' => 'refresh' }
Returns the credentials Hash. Raises RDStation::Error::ExpiredCodeGrant if the code has expired Raises RDStation::Error::InvalidCredentials if the client_id, client_secret or code is invalid.
38 39 40 41 |
# File 'lib/rdstation/authentication.rb', line 38 def authenticate(code) response = post_to_auth_endpoint(code: code) ApiResponse.build(response) end |
#update_access_token(refresh_token) ⇒ Object
param refresh_token
parameter sent by RDStation after authenticate
47 48 49 50 |
# File 'lib/rdstation/authentication.rb', line 47 def update_access_token(refresh_token) response = post_to_auth_endpoint(refresh_token: refresh_token) ApiResponse.build(response) end |