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 expired OAuth2 access token.
-
#token(code) ⇒ RubyLokaliseApi::Resources::OAuth2Token
Requests OAuth2 access token.
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.is_a?(Array) ? scope.join(' ') : 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 expired OAuth2 access token.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 60 def refresh(refresh_token) endpoint = oauth2_endpoint.new( self, query: :token, req: common_params.merge( grant_type: 'refresh_token', refresh_token: refresh_token ) ) RubyLokaliseApi::Resources::OAuth2RefreshedToken.new endpoint.do_post end |
#token(code) ⇒ RubyLokaliseApi::Resources::OAuth2Token
Requests OAuth2 access token. Requires OAuth2 code obtained using the ‘.auth` method
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ruby_lokalise_api/oauth2/auth.rb', line 44 def token(code) endpoint = oauth2_endpoint.new( self, query: :token, req: common_params.merge( grant_type: 'authorization_code', code: code ) ) RubyLokaliseApi::Resources::OAuth2Token.new endpoint.do_post end |