omnibucket 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 486ccabb2cb4cf5bc2da50ff5ee328e48fe2794fcfef2d00da9bf04447da32e0
4
+ data.tar.gz: c9684c8cc04c7e8865fad2a693165a807c92d5062ebc766bdbc311ad2691fb6c
5
+ SHA512:
6
+ metadata.gz: c6509c0956f12a27caba2c6c18562e746238e582421913255fd5d7759d7c0d2a0fe18a8d0302f2371a5035b80dbe3d5d81c161668e7added06ef7ca553d2303a
7
+ data.tar.gz: f1a60fc170c396528382a6f67ac5955ae561a77b5857ed2d2e1050e20c19adf0364a30b0960d166358f15ca591468d126dad7651f7dff526eaebeb23a32e446c
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rubocop.yml ADDED
@@ -0,0 +1,63 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/*.gemspec'
4
+ - '**/*.podspec'
5
+ - '**/*.jbuilder'
6
+ - '**/*.rake'
7
+ - '**/*.opal'
8
+ - '**/config.ru'
9
+ - '**/Gemfile'
10
+ - '**/Rakefile'
11
+ - '**/Capfile'
12
+ - '**/Guardfile'
13
+ - '**/Podfile'
14
+ - '**/Thorfile'
15
+ - '**/Vagrantfile'
16
+ - '**/Berksfile'
17
+ - '**/Cheffile'
18
+ - '**/Vagabondfile'
19
+
20
+ Style/Documentation:
21
+ Enabled: false
22
+
23
+ Style/StringLiterals:
24
+ EnforcedStyle: double_quotes
25
+
26
+ Layout/SpaceInsideBlockBraces:
27
+ EnforcedStyle: space
28
+ EnforcedStyleForEmptyBraces: space
29
+ SpaceBeforeBlockParameters: false
30
+
31
+ Layout/SpaceInsideHashLiteralBraces:
32
+ EnforcedStyle: no_space
33
+ EnforcedStyleForEmptyBraces: no_space
34
+
35
+ Layout/FirstArrayElementLineBreak:
36
+ Enabled: true
37
+
38
+ Layout/FirstHashElementLineBreak:
39
+ Enabled: true
40
+
41
+ Style/SymbolArray:
42
+ Enabled: true
43
+
44
+ Style/PercentLiteralDelimiters:
45
+ PreferredDelimiters:
46
+ '%': []
47
+ '%i': []
48
+ '%q': []
49
+ '%Q': []
50
+ '%r': '{}'
51
+ '%s': []
52
+ '%w': []
53
+ '%W': []
54
+ '%x': []
55
+
56
+ Metrics/LineLength:
57
+ Enabled: false
58
+
59
+ Style/EmptyMethod:
60
+ EnforcedStyle: expanded
61
+
62
+ Naming/FileName:
63
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - 2.4.2
6
+
7
+ script: 'bundle exec rake test test'
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-citrix.gemspec
4
+ gemspec
5
+ gem 'coveralls', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Nando Vieira
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ [![Build Status](https://travis-ci.org/ylaguna/omnibucket.svg?branch=master)](https://travis-ci.org/ylaguna/omnibucket)
2
+ [![Coverage Status](https://coveralls.io/repos/github/ylaguna/omnibucket/badge.svg?branch=master)](https://coveralls.io/github/ylaguna/omnibucket?branch=master)
3
+
4
+
5
+ # omnibucket
6
+
7
+ Bitbucket's OAuth2 Strategy for OmniAuth. This strategy uses API 2.0 to retrieve user information.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList["test/**/*_test.rb"]
7
+ t.warning = false
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Bitbucket
3
+ VERSION = "0.2.0".freeze
4
+ end
5
+ end
@@ -0,0 +1,53 @@
1
+ require "omniauth"
2
+ require "omniauth-oauth2"
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Bitbucket < OmniAuth::Strategies::OAuth2
7
+
8
+ option :client_options,
9
+ site: "https://bitbucket.org",
10
+ authorize_url: "/site/oauth2/authorize",
11
+ token_url: "/site/oauth2/access_token"
12
+
13
+ def callback_url
14
+ full_host + script_name + callback_path
15
+ end
16
+
17
+ uid do
18
+ raw_info[:uuid]
19
+ end
20
+
21
+ info do
22
+ {
23
+ username: raw_info[:username],
24
+ email: primary_email,
25
+ name: raw_info[:display_name]
26
+ }
27
+ end
28
+
29
+ extra do
30
+ {
31
+ account_id: raw_info[:account_id],
32
+ created_on: raw_info[:created_on],
33
+ is_staff: raw_info[:is_staff],
34
+ links: raw_info[:links],
35
+ location: raw_info[:location],
36
+ website: raw_info[:website]
37
+ }
38
+ end
39
+
40
+ def raw_info
41
+ @raw_info ||= deep_symbolize(access_token.get("/api/2.0/user").parsed)
42
+ end
43
+
44
+ def emails
45
+ @emails ||= deep_symbolize(access_token.get("/api/2.0/user/emails").parsed).fetch(:values)
46
+ end
47
+
48
+ def primary_email
49
+ (emails.find {|info| info["is_primary"] } || {})["email"]
50
+ end
51
+ end
52
+ end
53
+ end
data/lib/omnibucket.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "omniauth-bitbucket/version"
2
+ require "omniauth/strategies/bitbucket"
@@ -0,0 +1,26 @@
1
+ require "./lib/omniauth-bitbucket/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "omnibucket"
5
+ spec.version = Omniauth::Bitbucket::VERSION
6
+ spec.authors = ["Yan Laguna"]
7
+ spec.email = ["yan.laguna@gmail.com"]
8
+ spec.summary = "A fork from Nando Vieira's omniauth-atlassian-bitbucket"
9
+ spec.description = spec.summary
10
+ spec.homepage = "https://github.com/ylaguna/omniauth-atlassian-bitbucket"
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0")
14
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_runtime_dependency "omniauth-oauth2"
19
+ spec.add_development_dependency "bundler"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "minitest-utils"
22
+ spec.add_development_dependency "pry-meta"
23
+ spec.add_development_dependency "mocha"
24
+ spec.add_development_dependency "simplecov"
25
+ spec.add_development_dependency "webmock"
26
+ end
@@ -0,0 +1,21 @@
1
+ require "test_helper"
2
+
3
+ class AuthorizeParamsTest < Minitest::Test
4
+ let(:app) { ->(env) { } }
5
+
6
+ let(:strategy) do
7
+ OmniAuth::Strategies::Bitbucket.new(app, "consumer_id", "consumer_secret")
8
+ end
9
+
10
+ test "dont set a default scope" do
11
+ strategy.stubs(:session).returns({})
12
+ assert_equal nil, strategy.authorize_params.scope
13
+ end
14
+
15
+ test "sets unique scopes" do
16
+ strategy = OmniAuth::Strategies::Bitbucket.new(nil, "ID", "SECRET", scope: "account team")
17
+ strategy.stubs(:session).returns({})
18
+
19
+ assert_equal "account team", strategy.authorize_params.scope
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ require "test_helper"
2
+
3
+ class ClientOptionsTest < Minitest::Test
4
+ let(:app) { ->(env) { } }
5
+
6
+ let(:strategy) do
7
+ OmniAuth::Strategies::Bitbucket.new(app, "consumer_id", "consumer_secret")
8
+ end
9
+
10
+ test "sets name" do
11
+ assert_equal "bitbucket", strategy.options.name
12
+ end
13
+
14
+ test "sets site" do
15
+ assert_equal "https://bitbucket.org", strategy.options.client_options.site
16
+ end
17
+
18
+ test "sets authorize url" do
19
+ assert_equal "/site/oauth2/authorize", strategy.options.client_options.authorize_url
20
+ end
21
+
22
+ test "sets token url" do
23
+ assert_equal "/site/oauth2/access_token", strategy.options.client_options.token_url
24
+ end
25
+ end
@@ -0,0 +1,74 @@
1
+ require "test_helper"
2
+
3
+ class DataTest < Minitest::Test
4
+ let(:app) { ->(env) { } }
5
+
6
+ let(:strategy) do
7
+ OmniAuth::Strategies::Bitbucket.new(app, "consumer_id", "consumer_secret")
8
+ end
9
+
10
+ test "returns raw info" do
11
+ payload = {"id" => "ID"}
12
+ access_token = mock("access_token")
13
+ response = mock("response", parsed: payload)
14
+ access_token.expects(:get).with("/api/2.0/user").returns(response)
15
+ strategy.stubs(:access_token).returns(access_token)
16
+
17
+ assert_equal Hash[:id, "ID"], strategy.raw_info
18
+ end
19
+
20
+ test "returns emails" do
21
+ payload = {"values" => ["EMAILS"]}
22
+ access_token = mock("access_token")
23
+ response = mock("response", parsed: payload)
24
+ access_token.expects(:get).with("/api/2.0/user/emails").returns(response)
25
+ strategy.stubs(:access_token).returns(access_token)
26
+
27
+ assert_equal ["EMAILS"], strategy.emails
28
+ end
29
+
30
+ test "returns primary email" do
31
+ emails = [
32
+ {"email" => "SECONDARY", "is_primary" => false},
33
+ {"email" => "PRIMARY", "is_primary" => true}
34
+ ]
35
+ strategy.stubs(:emails).returns(emails)
36
+
37
+ assert_equal "PRIMARY", strategy.primary_email
38
+ end
39
+
40
+ test "returns nil when no primary email is found" do
41
+ strategy.stubs(:emails).returns([])
42
+ assert_nil strategy.primary_email
43
+ end
44
+
45
+ test "returns info" do
46
+ strategy.stubs(:raw_info).returns(username: "USERNAME", display_name: "NAME")
47
+ strategy.stubs(:primary_email).returns("EMAIL")
48
+
49
+ info = strategy.info
50
+
51
+ assert_equal "USERNAME", info[:username]
52
+ assert_equal "EMAIL", info[:email]
53
+ assert_equal "NAME", info[:name]
54
+ end
55
+
56
+ test "returns uid" do
57
+ strategy.stubs(:raw_info).returns(uuid: "ID")
58
+ assert_equal "ID", strategy.uid
59
+ end
60
+
61
+ test "returns extra info" do
62
+ raw_info = {
63
+ account_id: "ACCOUNT_ID",
64
+ created_on: "CREATED_ON",
65
+ is_staff: "IS_STAFF",
66
+ links: "LINKS",
67
+ location: "LOCATION",
68
+ website: "WEBSITE"
69
+ }
70
+ strategy.stubs(:raw_info).returns(raw_info)
71
+
72
+ assert_equal raw_info, strategy.extra
73
+ end
74
+ end
@@ -0,0 +1,8 @@
1
+ require "coveralls"
2
+ Coveralls.wear!
3
+
4
+ require "bundler/setup"
5
+ require "omnibucket"
6
+
7
+ require "minitest/utils"
8
+ require "minitest/autorun"
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omnibucket
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Yan Laguna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-utils
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-meta
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: A fork from Nando Vieira's omniauth-atlassian-bitbucket
126
+ email:
127
+ - yan.laguna@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".coveralls.yml"
133
+ - ".gitignore"
134
+ - ".rubocop.yml"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - lib/omniauth-bitbucket/version.rb
141
+ - lib/omniauth/strategies/bitbucket.rb
142
+ - lib/omnibucket.rb
143
+ - omnibucket.gemspec
144
+ - test/omniauth/strategies/authorize_params_test.rb
145
+ - test/omniauth/strategies/client_options_test.rb
146
+ - test/omniauth/strategies/data_test.rb
147
+ - test/test_helper.rb
148
+ homepage: https://github.com/ylaguna/omniauth-atlassian-bitbucket
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.7.6
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: A fork from Nando Vieira's omniauth-atlassian-bitbucket
172
+ test_files:
173
+ - test/omniauth/strategies/authorize_params_test.rb
174
+ - test/omniauth/strategies/client_options_test.rb
175
+ - test/omniauth/strategies/data_test.rb
176
+ - test/test_helper.rb