omniauth-gov 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 829aa13e5c71fc5063a31135b0300dcf748f0fdd5cc4451e6160d57b8e9e20d5
4
- data.tar.gz: e3fae85613ff0d66feb47ed29e66e1b3203481223912fe3c53a4e00ed5e55abc
3
+ metadata.gz: 5f61ded70b39a992b1829063689b6529d37f7cf3f0195c2b3cde665e4a9ac0bb
4
+ data.tar.gz: 6734621bde137d885c77260a7e6e24da4f378535393f6095c60d72cee1503d92
5
5
  SHA512:
6
- metadata.gz: 7b5ea3b42e416f91c8ff2a0a46dc2a32fc23b23793396f47d6d3818aa0824ff1dbe5b6326b82365c448b28971b80d266185c1d6c99737285dd3d65fc0b6a4682
7
- data.tar.gz: 47de0c020b5864231ab58f0300b0805396c8074d563c52f9c2c06377a70a88d60bd5263b978fe15750ac502a44f08f80949e64891cbca9604ee29b45fb98ddba
6
+ metadata.gz: f06678dda02ff695ea546bb8b79da8d3738ab8f2d9380388fa96e797015122cf0f3836f4939672fd3b0fefe2766343f033e52984fef9ab26a4796b9d11d76057
7
+ data.tar.gz: a647188a26fe0a9443db04e380a99da5711357c11bf36e3085608baa0eb14d5de959e3e1f2a8fa0129dc3210d2dfc9471cfd88f2faa14ddc011915e0f2550ba9
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-gov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Ricardo
@@ -9,22 +9,28 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-08-04 00:00:00.000000000 Z
12
+ date: 2025-09-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '='
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 1.9.2
21
+ - - "<"
19
22
  - !ruby/object:Gem::Version
20
- version: 1.9.1
23
+ version: '2.0'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - '='
28
+ - - ">="
26
29
  - !ruby/object:Gem::Version
27
- version: 1.9.1
30
+ version: 1.9.2
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: omniauth-oauth2
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -109,27 +115,29 @@ dependencies:
109
115
  - - ">="
110
116
  - !ruby/object:Gem::Version
111
117
  version: '0'
112
- description: Official OmniAuth strategy for GitHub.
118
+ - !ruby/object:Gem::Dependency
119
+ name: uri
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ description: OmniAuth strategy for integrating authentication with Brazilian Gov.br
133
+ using OmniAuth and OAuth2.
113
134
  email:
114
135
  - jonas.campos@yahoo.com.br
115
136
  - renatocdesouza@gmail.com
116
137
  executables: []
117
138
  extensions: []
118
139
  extra_rdoc_files: []
119
- files:
120
- - ".github/workflows/ruby.yml"
121
- - ".gitignore"
122
- - ".rspec"
123
- - Gemfile
124
- - Guardfile
125
- - LICENSE.txt
126
- - README.md
127
- - Rakefile
128
- - lib/gov_br/params_encoder.rb
129
- - lib/omniauth-gov.rb
130
- - lib/omniauth-gov/version.rb
131
- - lib/omniauth/strategies/gov.rb
132
- - omniauth-gov.gemspec
140
+ files: []
133
141
  homepage: https://github.com/jonasrscampos/omniauth-gov
134
142
  licenses:
135
143
  - MIT
@@ -149,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
157
  - !ruby/object:Gem::Version
150
158
  version: '0'
151
159
  requirements: []
152
- rubygems_version: 3.4.19
160
+ rubygems_version: 3.5.20
153
161
  signing_key:
154
162
  specification_version: 4
155
163
  summary: Official OmniAuth strategy for GitHub.
@@ -1,24 +0,0 @@
1
- name: Ruby
2
-
3
- on:
4
- push:
5
- branches: [ main ]
6
- pull_request:
7
- branches: [ main ]
8
-
9
- jobs:
10
- test:
11
- runs-on: ubuntu-latest
12
- strategy:
13
- matrix:
14
- ruby-version: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2', 'truffleruby-head']
15
-
16
- steps:
17
- - uses: actions/checkout@v3
18
- - name: Set up Ruby ${{ matrix.ruby-version }}
19
- uses: ruby/setup-ruby@v1
20
- with:
21
- ruby-version: ${{ matrix.ruby-version }}
22
- bundler-cache: true
23
- - name: Build and test with Rake
24
- run: bundle exec rake
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- /pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --colour
data/Gemfile DELETED
@@ -1,13 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in omniauth-gov.gemspec
4
- gemspec
5
-
6
- group :development, :test do
7
- gem 'guard'
8
- gem 'guard-rspec'
9
- gem 'guard-bundler'
10
- gem 'rb-fsevent'
11
- gem 'growl'
12
- gem 'rake'
13
- end
data/Guardfile DELETED
@@ -1,10 +0,0 @@
1
- guard 'rspec', :version => 2 do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
- watch('spec/spec_helper.rb') { "spec" }
5
- end
6
-
7
- guard 'bundler' do
8
- watch('Gemfile')
9
- watch('omniauth-gov.gemspec')
10
- end
data/LICENSE.txt DELETED
@@ -1,7 +0,0 @@
1
- Copyright (c) 2011 Michael Bleigh and Intridea, Inc.
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,144 +0,0 @@
1
- ![Ruby](https://github.com/omniauth/omniauth-gov/workflows/Ruby/badge.svg?branch=main)
2
-
3
- # OmniAuth Gov
4
-
5
- Estratégia omniauth para integração do Login Único do governo brasileiro ao autentiador devise.
6
-
7
- ## Instalação
8
-
9
- ```ruby
10
- gem 'omniauth', '1.9.1'
11
- gem "omniauth-rails_csrf_protection", '0.1.2'
12
- gem 'omniauth-oauth2'
13
- gem 'omniauth-gov', '~> 0.1.5'
14
- ```
15
-
16
- ## Configuração devise
17
-
18
- Em `config/initializers/devise.rb.rb`
19
-
20
- ```ruby
21
- Devise.setup do |config|
22
- # ...
23
- config.omniauth :gov,
24
- ENV['client_id'],
25
- ENV['client_secret'],
26
- scope: 'openid+email+profile+govbr_confiabilidades+',
27
- callback_path: '/callback-da-aplicacao',
28
- client_options: {
29
- site: 'https://sso.acesso.gov.br', # Ambiente de produção.
30
- authorize_url: 'https://sso.acesso.gov.br/authorize', # Ambiente de produção.
31
- token_url: 'https://sso.acesso.gov.br/token' # Ambiente de produção.
32
- }
33
-
34
- config.omniauth_path_prefix = '/prefixo-devise/prefixo-omniauth'
35
- end
36
- ```
37
-
38
- ## Initializer
39
- Em `config/initializer/omniauth.rb`
40
-
41
- ```ruby
42
- OmniAuth.config.full_host = "https://endereco-do-app.gov.br"
43
- OmniAuth.config.logger = Rails.logger
44
- ```
45
-
46
- ## Route
47
- Em `config/routes.rb`
48
- ```ruby
49
- # ...
50
- devise_for :users, controllers: {
51
- # ...
52
- :omniauth_callbacks => 'auth/omniauth_callbacks'
53
- }
54
-
55
- # opcional: redirecionar url de callback para o callback do devise
56
- devise_scope :user do
57
- get 'url-de-callback', to: 'auth/omniauth_callbacks#gov'
58
- end
59
-
60
- ```
61
-
62
- ## Controller
63
- Em `controllers/auth/omniauth_callbacks_controller.rb`
64
-
65
- ```ruby
66
- # frozen_string_literal: true
67
-
68
- class Auth::OmniauthCallbacksController < Devise::OmniauthCallbacksController
69
- skip_before_action :verify_authenticity_token
70
-
71
- def gov
72
- @user = User.from_gov_br_omniauth(request.env["omniauth.auth"]["info"])
73
-
74
- if @user.id.present?
75
- sign_in_and_redirect @user, :event => :authentication
76
- set_flash_message(:notice, :success, :kind => "Login Unico") if is_navigational_format?
77
- else
78
- end
79
- end
80
-
81
- def failure
82
- redirect_to root_path
83
- end
84
-
85
- end
86
- ```
87
-
88
- ## Model User
89
- Em `model/user.rb`
90
- ```ruby
91
- devise :database_authenticatable,
92
- # ...
93
- :omniauthable, omniauth_providers: %i[gov]
94
-
95
- # ...
96
- def self.from_gov_br_omniauth(info)
97
- # Exemplo hash info
98
- # {
99
- # "id": 1702579345,
100
- # "cpf": '99999999999',
101
- # "nome_social": 'Nome Social',
102
- # "email_verified": true,
103
- # "profile": 'https://servicos.staging.acesso.gov.br/',
104
- # "username": '99999999999',
105
- # "picture": raw_info["picture"],
106
- # "name": raw_info["name"],
107
- # "email": raw_info["email"],
108
- # }
109
- user = User.find_by_email(info["email"]) # ou outra chave
110
-
111
- unless user.nil?
112
- user.update_attributes(provider: 'login-unico', uid: info["id"])
113
- else
114
- name = info["name"]
115
- email = info["email"]
116
- user = User.new do |user|
117
- user.name = name
118
- user.email = email
119
- end
120
- user.skip_confirmation!
121
- user.save
122
- end
123
-
124
- return user
125
- end
126
-
127
- ```
128
-
129
- ## View
130
- Em `sessions/new.html.erb`
131
- ```ruby
132
- <%= button_to omniauth_authorize_path(resource_name, :gov), class: 'gov-br-btn sign-in br-button middle sign-in w-100 is-primary mt-3 mb-3', data: { turbo: false } do %>
133
- <i class="icon fa fa-user fa-lg" style="color: rgb(255, 255, 255);"></i>&nbsp;
134
- <span style="font-weight: normal;">Entrar com</span>&nbsp;
135
- <span style="font-size: 20px; font-weight: bold;"> gov.br</span>
136
- <% end %>
137
- ```
138
-
139
- ## Licença
140
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
141
-
142
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
143
-
144
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
3
- require 'rspec/core/rake_task'
4
-
5
- RSpec::Core::RakeTask.new
6
-
7
- desc 'Run specs'
8
- task :default => :spec
@@ -1,105 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GovBr
4
- # FlatParamsEncoder manages URI params as a flat hash. Any Array values repeat
5
- # the parameter multiple times.
6
- module ParamsEncoder
7
- class << self
8
- extend Forwardable
9
- def_delegators :'Faraday::Utils', :escape, :unescape
10
- end
11
-
12
- # Encode converts the given param into a URI querystring. Keys and values
13
- # will converted to strings and appropriately escaped for the URI.
14
- #
15
- # @param params [Hash] query arguments to convert.
16
- #
17
- # @example
18
- #
19
- # encode({a: %w[one two three], b: true, c: "C"})
20
- # # => 'a=one&a=two&a=three&b=true&c=C'
21
- #
22
- # @return [String] the URI querystring (without the leading '?')
23
- def self.encode(params)
24
- return nil if params.nil?
25
-
26
- unless params.is_a?(Array)
27
- unless params.respond_to?(:to_hash)
28
- raise TypeError,
29
- "Can't convert #{params.class} into Hash."
30
- end
31
- params = params.to_hash
32
- params = params.map do |key, value|
33
- key = key.to_s if key.is_a?(Symbol)
34
- [key, value]
35
- end
36
-
37
- # Only to be used for non-Array inputs. Arrays should preserve order.
38
- params.sort! if @sort_params
39
- end
40
-
41
- # The params have form [['key1', 'value1'], ['key2', 'value2']].
42
- buffer = +''
43
- params.each do |key, value|
44
- encoded_key = escape(key)
45
- if value.nil?
46
- buffer << "#{encoded_key}&"
47
- elsif value.is_a?(Array)
48
- if value.empty?
49
- buffer << "#{encoded_key}=&"
50
- else
51
- value.each do |sub_value|
52
- encoded_value = escape(sub_value)
53
- buffer << "#{encoded_key}=#{encoded_value}&"
54
- end
55
- end
56
- else
57
- encoded_value = (key == 'scope') ? value : escape(value)
58
- buffer << "#{encoded_key}=#{encoded_value}&"
59
- end
60
- end
61
- buffer.chop
62
- end
63
-
64
- # Decode converts the given URI querystring into a hash.
65
- #
66
- # @param query [String] query arguments to parse.
67
- #
68
- # @example
69
- #
70
- # decode('a=one&a=two&a=three&b=true&c=C')
71
- # # => {"a"=>["one", "two", "three"], "b"=>"true", "c"=>"C"}
72
- #
73
- # @return [Hash] parsed keys and value strings from the querystring.
74
- def self.decode(query)
75
- return nil if query.nil?
76
-
77
- empty_accumulator = {}
78
-
79
- split_query = (query.split('&').map do |pair|
80
- pair.split('=', 2) if pair && !pair.empty?
81
- end).compact
82
- split_query.each_with_object(empty_accumulator.dup) do |pair, accu|
83
- pair[0] = unescape(pair[0])
84
- pair[1] = true if pair[1].nil?
85
- if pair[1].respond_to?(:to_str)
86
- pair[1] = unescape(pair[1].to_str.tr('+', ' '))
87
- end
88
- if accu[pair[0]].is_a?(Array)
89
- accu[pair[0]] << pair[1]
90
- elsif accu[pair[0]]
91
- accu[pair[0]] = [accu[pair[0]], pair[1]]
92
- else
93
- accu[pair[0]] = pair[1]
94
- end
95
- end
96
- end
97
-
98
- class << self
99
- attr_accessor :sort_params
100
- end
101
-
102
- # Useful default for OAuth and caching.
103
- @sort_params = true
104
- end
105
- end
@@ -1,88 +0,0 @@
1
- require 'omniauth-oauth2'
2
-
3
- module Omniauth
4
- module Strategies
5
- class Gov < OmniAuth::Strategies::OAuth2
6
- option :pkce, true
7
-
8
- credentials do
9
- hash = {"access_token" => access_token.token}
10
- hash["id_token"] = access_token.params["id_token"]
11
- hash["refresh_token"] = access_token.refresh_token if access_token.expires? && access_token.refresh_token
12
- hash["expires_at"] = access_token.expires_at if access_token.expires?
13
- hash["expires"] = access_token.expires?
14
- hash
15
- end
16
-
17
- info do
18
- prune!({
19
- "id": raw_info['auth_time'],
20
- "cpf": raw_info["sub"],
21
- "nome_social": raw_info["social_name"],
22
- "email_verified": raw_info["email_verified"],
23
- "profile": raw_info["profile"],
24
- "username": raw_info["preferred_username"],
25
- "picture": raw_info["picture"],
26
- "name": raw_info["name"],
27
- "email": raw_info["email"],
28
- })
29
- end
30
-
31
- uid { raw_info['auth_time'] }
32
-
33
- extra do
34
- {
35
- 'raw_info': raw_info
36
- }
37
- end
38
-
39
- def client
40
- options.client_options.merge!({connection_opts: {request: {params_encoder: GovBr::ParamsEncoder}}})
41
- ::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
42
- end
43
-
44
- def request_phase
45
- redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
46
- end
47
-
48
- def raw_info
49
- @raw_info ||= JWT.decode(credentials["id_token"], nil, false)[0]
50
- end
51
-
52
- def prune!(hash)
53
- hash.delete_if do |_, value|
54
- prune!(value) if value.is_a?(Hash)
55
- value.nil? || (value.respond_to?(:empty?) && value.empty?)
56
- end
57
- end
58
-
59
- def authorize_params # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
60
- options.authorize_params[:state] = SecureRandom.hex(24)
61
- options.authorize_params[:client_id] = options[:client_id]
62
- options.authorize_params[:scope] = options[:scope]
63
- options.authorize_params[:response_type] = 'code'
64
- options.authorize_params[:nonce] = SecureRandom.hex[0..11]
65
- params = options.authorize_params
66
- .merge(options_for("authorize"))
67
- .merge(pkce_authorize_params)
68
-
69
- session["omniauth.pkce.verifier"] = options.pkce_verifier if options.pkce
70
- session["omniauth.state"] = params[:state]
71
-
72
- params
73
- end
74
-
75
- def build_access_token
76
- verifier = request.params["code"]
77
-
78
- atoken = client.auth_code.get_token(
79
- verifier,
80
- {"grant_type": "authorization_code", "code": verifier, "redirect_uri": OmniAuth.config.full_host+options.callback_path, "code_verifier": session["omniauth.pkce.verifier"]},
81
- {"Content-Type" => "application/x-www-form-urlencoded", "Authorization" => "Basic #{Base64.strict_encode64(options.client_id+":"+options.client_secret)}" })
82
- atoken
83
- end
84
- end
85
- end
86
- end
87
-
88
- OmniAuth.config.add_camelization 'gov', 'Gov'
@@ -1,5 +0,0 @@
1
- module OmniAuth
2
- module Gov
3
- VERSION = "0.1.8"
4
- end
5
- end
data/lib/omniauth-gov.rb DELETED
@@ -1,3 +0,0 @@
1
- require "omniauth-gov/version"
2
- require 'gov_br/params_encoder'
3
- require 'omniauth/strategies/gov'
data/omniauth-gov.gemspec DELETED
@@ -1,26 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/omniauth-gov/version', __FILE__)
3
-
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["Jonas Ricardo", "Renato de Souza"]
6
- gem.email = ["jonas.campos@yahoo.com.br", "renatocdesouza@gmail.com"]
7
- gem.description = %q{Official OmniAuth strategy for GitHub.}
8
- gem.summary = %q{Official OmniAuth strategy for GitHub.}
9
- gem.homepage = "https://github.com/jonasrscampos/omniauth-gov"
10
- gem.license = "MIT"
11
-
12
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
- gem.files = `git ls-files`.split("\n")
14
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
- gem.name = "omniauth-gov"
16
- gem.require_paths = ["lib"]
17
- gem.version = OmniAuth::Gov::VERSION
18
-
19
- gem.add_dependency 'omniauth', '1.9.1'
20
- gem.add_dependency 'omniauth-oauth2'
21
- gem.add_development_dependency 'rspec', '~> 3.5'
22
- gem.add_development_dependency 'faraday', '~> 2.9'
23
- gem.add_development_dependency 'rack-test'
24
- gem.add_development_dependency 'simplecov'
25
- gem.add_development_dependency 'webmock'
26
- end