lib/omniauth/strategies/boletosimples.rb in omniauth-boletosimples-0.0.9 vs lib/omniauth/strategies/boletosimples.rb in omniauth-boletosimples-0.1.0
- old
+ new
@@ -1,23 +1,24 @@
+# frozen_string_literal: true
+
require 'omniauth-oauth2'
module OmniAuth
module Strategies
class BoletoSimples < OmniAuth::Strategies::OAuth2
- DEFAULT_SCOPE = "profile"
+ DEFAULT_SCOPE = 'profile'
ENVIRONMENTS = {
development: 'http://localhost:5000',
sandbox: 'https://sandbox.boletosimples.com.br',
production: 'https://boletosimples.com.br'
- }
+ }.freeze
option :name, 'boletosimples'
- option :client_options, {
- :token_url => '/api/v1/oauth2/token',
- :setup => true
- }
+ option :client_options,
+ token_url: '/api/v1/oauth2/token',
+ setup: true
- option :authorize_options, [:scope, :response_type]
+ option :authorize_options, %i[scope response_type]
option :provider_ignores_state, true
option :environment, :production
uid { raw_info['id'] }
@@ -31,11 +32,11 @@
date_of_birth: raw_info['date_of_birth'],
email: raw_info['email'],
cpf: raw_info['cpf'],
mother_name: raw_info['mother_name'],
father_name: raw_info['father_name'],
- sex: raw_info['sex'],
+ sex: raw_info['sex']
}
end
extra do
{
@@ -55,15 +56,17 @@
def setup_phase
environment = options.environment || :production
options.client_options[:site] = ENVIRONMENTS[environment.to_sym]
options.client_options[:authorize_url] = "#{ENVIRONMENTS[environment.to_sym]}/api/v1/oauth2/authorize"
- options.client_options[:connection_opts] = {
- headers: {
- 'User-Agent' => options.user_agent,
+ if options.user_agent
+ options.client_options[:connection_opts] = {
+ headers: {
+ 'User-Agent' => options.user_agent
+ }
}
- } if options.user_agent
+ end
end
def raw_info
@raw_info ||= load_identity
end
@@ -77,15 +80,16 @@
params[:scope] ||= DEFAULT_SCOPE
end
end
private
- def load_identity
- access_token.options[:mode] = :query
- access_token.options[:param_name] = :access_token
- access_token.options[:grant_type] = :authorization_code
- access_token.get('/api/v1/userinfo').parsed
- end
+
+ def load_identity
+ access_token.options[:mode] = :query
+ access_token.options[:param_name] = :access_token
+ access_token.options[:grant_type] = :authorization_code
+ access_token.get('/api/v1/userinfo').parsed
+ end
end
end
end
OmniAuth.config.add_camelization 'boletosimples', 'BoletoSimples'