omniauth-gov 0.1.0 → 0.1.2
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 +4 -4
- data/.github/workflows/ruby.yml +24 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +7 -0
- data/README.md +129 -0
- data/Rakefile +8 -0
- data/lib/omniauth/strategies/gov.rb +84 -0
- data/lib/omniauth-gov/version.rb +5 -0
- data/lib/omniauth-gov.rb +2 -0
- data/omniauth-gov.gemspec +25 -0
- data/spec/omniauth/strategies/github_spec.rb +183 -0
- data/spec/spec_helper.rb +16 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59fc74ddbc0e9597ed857fb5e0d81d23ba1cc39d68bf53df937cc1c6ac550fdd
|
4
|
+
data.tar.gz: cb6cbb1cf394fa99880afdba93b0dbf12b53a5f1a3853ba944dcb2ff1509d773
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d40363557839ba4743fef89876c43e66280f9d659641771ac8dd9ec577732f3de6e807672025416b355aac3ddb2ec2a413e012e9ae9daf8286ceea8747325f2
|
7
|
+
data.tar.gz: 78b60e07c8ffffe0c4ac3e5d9348d7a6c2b7a38fb7adbad9e3fe1b99ba43daf21918ec5f9bd16a3add1bfd3dc033254fbde8c33833b46682d9a32ea88cabd93b
|
@@ -0,0 +1,24 @@
|
|
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
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
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
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+

|
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.2'
|
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
|
+
|
29
|
+
config.omniauth_path_prefix = '/prefixo-devise/prefixo-omniauth'
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Initializer
|
34
|
+
Em `config/initializer/omniauth.rb`
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
OmniAuth.config.full_host = "<host-da-aplicacao-com-protocolo>"
|
38
|
+
OmniAuth.config.logger = Rails.logger
|
39
|
+
```
|
40
|
+
|
41
|
+
## Route
|
42
|
+
Em `config/routes.rb`
|
43
|
+
```ruby
|
44
|
+
# ...
|
45
|
+
devise_for :users, controllers: {
|
46
|
+
# ...
|
47
|
+
:omniauth_callbacks => 'auth/omniauth_callbacks'
|
48
|
+
}
|
49
|
+
|
50
|
+
# opcional: redirecionar url de callback para o callback do devise
|
51
|
+
devise_scope :user do
|
52
|
+
get 'url-de-callback', to: 'auth/omniauth_callbacks#gov'
|
53
|
+
end
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
## Controller
|
58
|
+
Em `controllers/auth/omniauth_callbacks_controller.rb`
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
# frozen_string_literal: true
|
62
|
+
|
63
|
+
class Auth::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
64
|
+
skip_before_action :verify_authenticity_token
|
65
|
+
|
66
|
+
def gov
|
67
|
+
@user = User.from_gov_br_omniauth(request.env["omniauth.auth"]["info"])
|
68
|
+
|
69
|
+
if @user.id.present?
|
70
|
+
sign_in_and_redirect @user, :event => :authentication
|
71
|
+
set_flash_message(:notice, :success, :kind => "Login Unico") if is_navigational_format?
|
72
|
+
else
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def failure
|
77
|
+
redirect_to root_path
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
## Model User
|
84
|
+
Em `model/user.rb`
|
85
|
+
```ruby
|
86
|
+
devise :database_authenticatable,
|
87
|
+
# ...
|
88
|
+
:omniauthable, omniauth_providers: %i[gov]
|
89
|
+
|
90
|
+
# ...
|
91
|
+
def self.from_gov_br_omniauth(info)
|
92
|
+
# Exemplo hash info
|
93
|
+
# {
|
94
|
+
# "id": 1702579345,
|
95
|
+
# "cpf": '99999999999',
|
96
|
+
# "nome_social": 'Nome Social',
|
97
|
+
# "email_verified": true,
|
98
|
+
# "profile": 'https://servicos.staging.acesso.gov.br/',
|
99
|
+
# "username": '99999999999',
|
100
|
+
# "picture": raw_info["picture"],
|
101
|
+
# "name": raw_info["name"],
|
102
|
+
# "email": raw_info["email"],
|
103
|
+
# }
|
104
|
+
user = User.find_by_email(info["email"]) # ou outra chave
|
105
|
+
|
106
|
+
unless user.nil?
|
107
|
+
user.update_attributes(provider: 'login-unico', uid: info["id"])
|
108
|
+
else
|
109
|
+
name = info["name"]
|
110
|
+
email = info["email"]
|
111
|
+
user = User.new do |user|
|
112
|
+
user.name = name
|
113
|
+
user.email = email
|
114
|
+
end
|
115
|
+
user.skip_confirmation!
|
116
|
+
user.save
|
117
|
+
end
|
118
|
+
|
119
|
+
return user
|
120
|
+
end
|
121
|
+
|
122
|
+
```
|
123
|
+
|
124
|
+
## Licença
|
125
|
+
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:
|
126
|
+
|
127
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
128
|
+
|
129
|
+
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
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module Omniauth
|
4
|
+
module Strategies
|
5
|
+
class Gov < OmniAuth::Strategies::OAuth2
|
6
|
+
option :client_options, {
|
7
|
+
site: 'https://sso.staging.acesso.gov.br',
|
8
|
+
authorize_url: 'https://sso.staging.acesso.gov.br/authorize',
|
9
|
+
token_url: 'https://sso.staging.acesso.gov.br/token'
|
10
|
+
}
|
11
|
+
option :pkce, true
|
12
|
+
|
13
|
+
credentials do
|
14
|
+
hash = {"access_token" => access_token.token}
|
15
|
+
hash["id_token"] = access_token.params["id_token"]
|
16
|
+
hash["refresh_token"] = access_token.refresh_token if access_token.expires? && access_token.refresh_token
|
17
|
+
hash["expires_at"] = access_token.expires_at if access_token.expires?
|
18
|
+
hash["expires"] = access_token.expires?
|
19
|
+
hash
|
20
|
+
end
|
21
|
+
|
22
|
+
info do
|
23
|
+
prune!({
|
24
|
+
"id": raw_info['auth_time'],
|
25
|
+
"cpf": raw_info["sub"],
|
26
|
+
"nome_social": raw_info["social_name"],
|
27
|
+
"email_verified": raw_info["email_verified"],
|
28
|
+
"profile": raw_info["profile"],
|
29
|
+
"username": raw_info["preferred_username"],
|
30
|
+
"picture": raw_info["picture"],
|
31
|
+
"name": raw_info["name"],
|
32
|
+
"email": raw_info["email"],
|
33
|
+
})
|
34
|
+
end
|
35
|
+
|
36
|
+
uid { raw_info['auth_time'] }
|
37
|
+
|
38
|
+
extra do
|
39
|
+
{
|
40
|
+
'raw_info': raw_info
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def raw_info
|
45
|
+
@raw_info ||= JWT.decode(credentials["id_token"], nil, false)[0]
|
46
|
+
end
|
47
|
+
|
48
|
+
def prune!(hash)
|
49
|
+
hash.delete_if do |_, value|
|
50
|
+
prune!(value) if value.is_a?(Hash)
|
51
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def authorize_params # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
56
|
+
options.authorize_params[:state] = SecureRandom.hex(24)
|
57
|
+
options.authorize_params[:client_id] = options[:client_id]
|
58
|
+
options.authorize_params[:scope] = options[:scope]
|
59
|
+
options.authorize_params[:response_type] = 'code'
|
60
|
+
options.authorize_params[:nonce] = SecureRandom.hex[0..11]
|
61
|
+
params = options.authorize_params
|
62
|
+
.merge(options_for("authorize"))
|
63
|
+
.merge(pkce_authorize_params)
|
64
|
+
|
65
|
+
session["omniauth.pkce.verifier"] = options.pkce_verifier if options.pkce
|
66
|
+
session["omniauth.state"] = params[:state]
|
67
|
+
|
68
|
+
params
|
69
|
+
end
|
70
|
+
|
71
|
+
def build_access_token
|
72
|
+
verifier = request.params["code"]
|
73
|
+
|
74
|
+
atoken = client.auth_code.get_token(
|
75
|
+
verifier,
|
76
|
+
{"grant_type": "authorization_code", "code": verifier, "redirect_uri": OmniAuth.config.full_host+options.callback_path, "code_verifier": session["omniauth.pkce.verifier"]},
|
77
|
+
{"Content-Type" => "application/x-www-form-urlencoded", "Authorization" => "Basic #{Base64.strict_encode64(Settings.reload!.omniauth.client_id+":"+Settings.reload!.omniauth.client_secret)}" })
|
78
|
+
atoken
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
OmniAuth.config.add_camelization 'gov', 'Gov'
|
data/lib/omniauth-gov.rb
ADDED
@@ -0,0 +1,25 @@
|
|
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"]
|
6
|
+
gem.email = ["jonas.campos@yahoo.com.br"]
|
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 'rack-test'
|
23
|
+
gem.add_development_dependency 'simplecov'
|
24
|
+
gem.add_development_dependency 'webmock'
|
25
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::GitHub do
|
4
|
+
let(:access_token) { instance_double('AccessToken', :options => {}, :[] => 'user') }
|
5
|
+
let(:parsed_response) { instance_double('ParsedResponse') }
|
6
|
+
let(:response) { instance_double('Response', :parsed => parsed_response) }
|
7
|
+
|
8
|
+
let(:enterprise_site) { 'https://some.other.site.com/api/v3' }
|
9
|
+
let(:enterprise_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' }
|
10
|
+
let(:enterprise_token_url) { 'https://some.other.site.com/login/oauth/access_token' }
|
11
|
+
let(:enterprise) do
|
12
|
+
OmniAuth::Strategies::GitHub.new('GITHUB_KEY', 'GITHUB_SECRET',
|
13
|
+
{
|
14
|
+
:client_options => {
|
15
|
+
:site => enterprise_site,
|
16
|
+
:authorize_url => enterprise_authorize_url,
|
17
|
+
:token_url => enterprise_token_url
|
18
|
+
}
|
19
|
+
}
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
subject do
|
24
|
+
OmniAuth::Strategies::GitHub.new({})
|
25
|
+
end
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
allow(subject).to receive(:access_token).and_return(access_token)
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'client options' do
|
32
|
+
it 'should have correct site' do
|
33
|
+
expect(subject.options.client_options.site).to eq('https://api.github.com')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should have correct authorize url' do
|
37
|
+
expect(subject.options.client_options.authorize_url).to eq('https://github.com/login/oauth/authorize')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should have correct token url' do
|
41
|
+
expect(subject.options.client_options.token_url).to eq('https://github.com/login/oauth/access_token')
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'should be overrideable' do
|
45
|
+
it 'for site' do
|
46
|
+
expect(enterprise.options.client_options.site).to eq(enterprise_site)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'for authorize url' do
|
50
|
+
expect(enterprise.options.client_options.authorize_url).to eq(enterprise_authorize_url)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'for token url' do
|
54
|
+
expect(enterprise.options.client_options.token_url).to eq(enterprise_token_url)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context '#email_access_allowed?' do
|
60
|
+
it 'should not allow email if scope is nil' do
|
61
|
+
expect(subject.options['scope']).to be_nil
|
62
|
+
expect(subject).to_not be_email_access_allowed
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should allow email if scope is user' do
|
66
|
+
subject.options['scope'] = 'user'
|
67
|
+
expect(subject).to be_email_access_allowed
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should allow email if scope is a bunch of stuff including user' do
|
71
|
+
subject.options['scope'] = 'public_repo,user,repo,delete_repo,gist'
|
72
|
+
expect(subject).to be_email_access_allowed
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should not allow email if scope does not grant email access' do
|
76
|
+
subject.options['scope'] = 'repo,user:follow'
|
77
|
+
expect(subject).to_not be_email_access_allowed
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should assume email access not allowed if scope is something currently not documented' do
|
81
|
+
subject.options['scope'] = 'currently_not_documented'
|
82
|
+
expect(subject).to_not be_email_access_allowed
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context '#email' do
|
87
|
+
it 'should return email from raw_info if available' do
|
88
|
+
allow(subject).to receive(:raw_info).and_return({ 'email' => 'you@example.com' })
|
89
|
+
expect(subject.email).to eq('you@example.com')
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should return nil if there is no raw_info and email access is not allowed' do
|
93
|
+
allow(subject).to receive(:raw_info).and_return({})
|
94
|
+
expect(subject.email).to be_nil
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should not return the primary email if there is no raw_info and email access is allowed' do
|
98
|
+
emails = [
|
99
|
+
{ 'email' => 'secondary@example.com', 'primary' => false },
|
100
|
+
{ 'email' => 'primary@example.com', 'primary' => true }
|
101
|
+
]
|
102
|
+
allow(subject).to receive(:raw_info).and_return({})
|
103
|
+
subject.options['scope'] = 'user'
|
104
|
+
allow(subject).to receive(:emails).and_return(emails)
|
105
|
+
expect(subject.email).to be_nil
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should not return the first email if there is no raw_info and email access is allowed' do
|
109
|
+
emails = [
|
110
|
+
{ 'email' => 'first@example.com', 'primary' => false },
|
111
|
+
{ 'email' => 'second@example.com', 'primary' => false }
|
112
|
+
]
|
113
|
+
allow(subject).to receive(:raw_info).and_return({})
|
114
|
+
subject.options['scope'] = 'user'
|
115
|
+
allow(subject).to receive(:emails).and_return(emails)
|
116
|
+
expect(subject.email).to be_nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context '#raw_info' do
|
121
|
+
it 'should use relative paths' do
|
122
|
+
expect(access_token).to receive(:get).with('user').and_return(response)
|
123
|
+
expect(subject.raw_info).to eq(parsed_response)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should use the header auth mode' do
|
127
|
+
expect(access_token).to receive(:get).with('user').and_return(response)
|
128
|
+
subject.raw_info
|
129
|
+
expect(access_token.options[:mode]).to eq(:header)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context '#emails' do
|
134
|
+
it 'should use relative paths' do
|
135
|
+
expect(access_token).to receive(:get).with('user/emails', :headers => {
|
136
|
+
'Accept' => 'application/vnd.github.v3'
|
137
|
+
}).and_return(response)
|
138
|
+
|
139
|
+
subject.options['scope'] = 'user'
|
140
|
+
expect(subject.emails).to eq(parsed_response)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should use the header auth mode' do
|
144
|
+
expect(access_token).to receive(:get).with('user/emails', :headers => {
|
145
|
+
'Accept' => 'application/vnd.github.v3'
|
146
|
+
}).and_return(response)
|
147
|
+
|
148
|
+
subject.options['scope'] = 'user'
|
149
|
+
subject.emails
|
150
|
+
expect(access_token.options[:mode]).to eq(:header)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context '#info.email' do
|
155
|
+
it 'should use any available email' do
|
156
|
+
allow(subject).to receive(:raw_info).and_return({})
|
157
|
+
allow(subject).to receive(:email).and_return('you@example.com')
|
158
|
+
expect(subject.info['email']).to eq('you@example.com')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context '#info.urls' do
|
163
|
+
it 'should use html_url from raw_info' do
|
164
|
+
allow(subject).to receive(:raw_info).and_return({ 'login' => 'me', 'html_url' => 'http://enterprise/me' })
|
165
|
+
expect(subject.info['urls']['GitHub']).to eq('http://enterprise/me')
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context '#extra.scope' do
|
170
|
+
it 'returns the scope on the returned access_token' do
|
171
|
+
expect(subject.scope).to eq('user')
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe '#callback_url' do
|
176
|
+
it 'is a combination of host, script name, and callback path' do
|
177
|
+
allow(subject).to receive(:full_host).and_return('https://example.com')
|
178
|
+
allow(subject).to receive(:script_name).and_return('/sub_uri')
|
179
|
+
|
180
|
+
expect(subject.callback_url).to eq('https://example.com/sub_uri/auth/github/callback')
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
require 'rspec'
|
6
|
+
require 'rack/test'
|
7
|
+
require 'webmock/rspec'
|
8
|
+
require 'omniauth'
|
9
|
+
require 'omniauth-gov'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.include WebMock::API
|
13
|
+
config.include Rack::Test::Methods
|
14
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
15
|
+
end
|
16
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-gov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Ricardo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth
|
@@ -100,7 +100,21 @@ email:
|
|
100
100
|
executables: []
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
|
-
files:
|
103
|
+
files:
|
104
|
+
- ".github/workflows/ruby.yml"
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- Gemfile
|
108
|
+
- Guardfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- lib/omniauth-gov.rb
|
113
|
+
- lib/omniauth-gov/version.rb
|
114
|
+
- lib/omniauth/strategies/gov.rb
|
115
|
+
- omniauth-gov.gemspec
|
116
|
+
- spec/omniauth/strategies/github_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
104
118
|
homepage: https://github.com/jonasrscampos/omniauth-gov
|
105
119
|
licenses:
|
106
120
|
- MIT
|
@@ -120,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
134
|
- !ruby/object:Gem::Version
|
121
135
|
version: '0'
|
122
136
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
137
|
+
rubygems_version: 3.3.5
|
124
138
|
signing_key:
|
125
139
|
specification_version: 4
|
126
140
|
summary: Official OmniAuth strategy for GitHub.
|