Class: RubyLokaliseApi::OAuth2::Auth
- Inherits:
-
Object
- Object
- RubyLokaliseApi::OAuth2::Auth
- Defined in:
- lib/ruby_lokalise_api/oauth2/auth.rb
Overview
This class defines OAuth2 flow
Constant Summary collapse
- OAUTH2_ENDPOINT =
RubyLokaliseApi::Endpoints::OAuth2::OAuth2Endpoint
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.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#auth(scope:, redirect_uri: nil, state: nil) ⇒ String
Builds an OAuth2 link that customers have to visit in order to obtain a special code.
-
#initialize(client_id, client_secret, params = {}) ⇒ Auth
constructor
A new instance of Auth.
-
#oauth2_endpoint ⇒ Object
Returns OAuth2 endpoint URI.
-
#refresh(refresh_token) ⇒ RubyLokaliseApi::Resources::OAuth2RefreshedToken
Refreshes an expired OAuth2 token.
-
#token(code) ⇒ RubyLokaliseApi::Resources::OAuth2Token
Requests an OAuth2 access token using a code.
Constructor Details
#initialize(client_id, client_secret, params = {}) ⇒ Auth
Returns a new instance of Auth.
11 12 13 14 15 16 |
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 11 def initialize(client_id, client_secret, params = {}) @client_id = client_id @client_secret = client_secret @timeout = params[:timeout] @open_timeout = params[:open_timeout] end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
7 8 9 |
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 7 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
7 8 9 |
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 7 def client_secret @client_secret end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
7 8 9 |
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 7 def open_timeout @open_timeout end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 7 def timeout @timeout end |
Instance Method Details
#auth(scope:, redirect_uri: nil, state: nil) ⇒ String
Builds an OAuth2 link that customers have to visit in order to obtain a special code
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 29 def auth(scope:, redirect_uri: nil, state: nil) get_params = { client_id: client_id, scope: scope_to_string(scope), state: state, redirect_uri: redirect_uri } oauth2_endpoint.new(self, query: 'auth', get: get_params).full_uri end |
#oauth2_endpoint ⇒ Object
Returns OAuth2 endpoint URI
19 20 21 |
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 19 def oauth2_endpoint self.class.const_get(:OAUTH2_ENDPOINT) end |
#refresh(refresh_token) ⇒ RubyLokaliseApi::Resources::OAuth2RefreshedToken
Refreshes an expired OAuth2 token
50 51 52 |
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 50 def refresh(refresh_token) request_token(grant_type: 'refresh_token', refresh_token: refresh_token) end |
#token(code) ⇒ RubyLokaliseApi::Resources::OAuth2Token
Requests an OAuth2 access token using a code
43 44 45 |
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 43 def token(code) request_token(grant_type: 'authorization_code', code: code) end |