omniauth-mailru-oauth2 0.1.1

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: 68ef3bd926612ab488df7b1578327b875b201b0d6da6942e824d9913e13619eb
4
+ data.tar.gz: 16f1255cf6564bfa0e0e960ca394d7f7951b01daeee4f966609c90a316cdc1e6
5
+ SHA512:
6
+ metadata.gz: 00e69b06d271ed7788919c3bac2d6ad4b56b116a0e4df1445d0b1411205eaf4b414b4a2d4b2921c7a7f205d01e692874d5e921e78635c01a91df4e9a32597325
7
+ data.tar.gz: 48c4343477f3a756e1f9e04ba3a3720f4c70e2151e161b267bd79640737c291e435f2c2670f5f5800f92bb739461e319ba686a63516bf8f1f17966c2b20782ab
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ doc/
5
+ coverage/
6
+
7
+ Gemfile.lock
8
+ gemfiles/
9
+
10
+ spec/internal/public
11
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ --tty
3
+ --format progress
4
+ --order random
5
+ --require ./spec/spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
7
+ script: bundle exec rspec ./spec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # OmniAuth strategy for Mail.ru
2
+
3
+ [![Build Status](https://travis-ci.org/isqad/omniauth-mailru-oauth2.svg?branch=master)](https://travis-ci.org/isqad/omniauth-mailru-oauth2)
4
+
5
+ OmniAuth strategy for Mail.ru
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'omniauth-mailru-oauth2'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install omniauth-mailru-oauth2
22
+
23
+ ## Tests
24
+
25
+ Install [dip](https://github.com/bibendi/dip/releases) and run:
26
+
27
+ ```bash
28
+ $ dip provision && dip rspec
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/isqad/omniauth-mailru-oauth2/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/dip.yml ADDED
@@ -0,0 +1,42 @@
1
+ version: '2'
2
+
3
+ environment:
4
+ DOCKER_RUBY_VERSION: 2.2
5
+ RUBY_IMAGE_TAG: 2.2-latest
6
+ COMPOSE_FILE_EXT: development
7
+ RAILS_ENV: test
8
+ APRESS_GEMS_CREDENTIALS: ""
9
+
10
+ compose:
11
+ files:
12
+ - docker-compose.yml
13
+ - docker-compose.${COMPOSE_FILE_EXT}.yml
14
+
15
+ interaction:
16
+ sh:
17
+ service: app
18
+
19
+ irb:
20
+ service: app
21
+ command: irb
22
+
23
+ bundle:
24
+ service: app
25
+ command: bundle
26
+
27
+ rake:
28
+ service: app
29
+ command: bundle exec rake
30
+
31
+ rspec:
32
+ service: app
33
+ command: bundle exec rspec
34
+
35
+ clean:
36
+ service: app
37
+ command: rm -f Gemfile.lock
38
+
39
+ provision:
40
+ - docker volume create --name bundler_data
41
+ - dip clean
42
+ - dip bundle install
@@ -0,0 +1,12 @@
1
+ version: '2'
2
+
3
+ services:
4
+ app:
5
+ volumes:
6
+ - ../:/localgems
7
+ - bundler-data:/bundle
8
+
9
+ volumes:
10
+ bundler-data:
11
+ external:
12
+ name: bundler_data
@@ -0,0 +1,6 @@
1
+ version: '2'
2
+
3
+ services:
4
+ app:
5
+ volumes:
6
+ - /bundle:/bundle
@@ -0,0 +1,16 @@
1
+ version: '2'
2
+
3
+ services:
4
+ app:
5
+ image: abakpress/ruby-app:$RUBY_IMAGE_TAG
6
+ environment:
7
+ - BUNDLE_PATH=/bundle/$DOCKER_RUBY_VERSION
8
+ - SSH_AUTH_SOCK=/ssh/auth/sock
9
+ command: bash
10
+ volumes:
11
+ - .:/app
12
+ - ssh_data:/ssh:ro
13
+
14
+ volumes:
15
+ ssh_data:
16
+ external: true
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module MailruOauth2
3
+ VERSION = "0.1.1".freeze
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require 'omniauth/strategies/mailru_oauth2'
@@ -0,0 +1,58 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class MailruOauth2 < OmniAuth::Strategies::OAuth2
6
+ DEFAULT_SCOPE = 'userinfo'.freeze
7
+
8
+ option :name, 'mailru_oauth2'
9
+
10
+ option :client_options, {
11
+ site: 'https://oauth.mail.ru',
12
+ authorize_url: '/login',
13
+ token_url: '/token'
14
+ }
15
+
16
+ def authorize_params
17
+ super.tap do |params|
18
+ params[:scope] = params[:scope] || DEFAULT_SCOPE
19
+ end
20
+ end
21
+
22
+ uid do
23
+ raw_info['email']
24
+ end
25
+
26
+ extra do
27
+ {
28
+ 'raw_info' => raw_info
29
+ }
30
+ end
31
+
32
+ info do
33
+ {
34
+ email: raw_info['email'],
35
+ image: raw_info['image'],
36
+ name: raw_info['name'],
37
+ nickname: raw_info['nickname'],
38
+ first_name: raw_info['first_name'],
39
+ last_name: raw_info['last_name'],
40
+ birthday: raw_info['birthday'],
41
+ gender: raw_info['gender'],
42
+ locate: raw_info['locate'],
43
+ client_id: raw_info['client_id']
44
+ }
45
+ end
46
+
47
+ def raw_info
48
+ @raw_info ||= access_token.get("https://oauth.mail.ru/userinfo?access_token=#{access_token.token}").parsed
49
+ end
50
+
51
+ private
52
+
53
+ def callback_url
54
+ full_host + script_name + callback_path
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ require 'omniauth/mailru_oauth2'
2
+
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'omniauth/mailru_oauth2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'omniauth-mailru-oauth2'
8
+ spec.license = 'MIT'
9
+ spec.version = OmniAuth::MailruOauth2::VERSION
10
+ spec.authors = ['Andrew Shalaev']
11
+ spec.email = ['isqad88@gmail.com']
12
+ spec.homepage = 'https://github.com/isqad/omniauth-mailru-oauth2'
13
+ spec.summary = 'OmniAuth strategy for Mail.ru'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_runtime_dependency 'omniauth'
21
+ spec.add_runtime_dependency 'omniauth-oauth2'
22
+
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec-rails', '>= 2.14.0'
25
+ spec.add_development_dependency 'appraisal', '>= 1.0.2'
26
+ spec.add_development_dependency 'simplecov'
27
+ spec.add_development_dependency 'test-unit'
28
+ spec.add_development_dependency 'pry-byebug'
29
+ end
@@ -0,0 +1,74 @@
1
+ RSpec.describe OmniAuth::Strategies::MailruOauth2 do
2
+ let(:server_userinfo) do
3
+ {
4
+ 'nickname' => 'Andrew Shalaev',
5
+ 'client_id' => 123,
6
+ 'image' => 'https://filin.mail.ru/foobar',
7
+ 'first_name' => 'Andrew',
8
+ 'email' => 'isqad88@gmail.com',
9
+ 'locate' => 'ru_RU',
10
+ 'name' => 'Andrew Shalaev',
11
+ 'last_name' => 'Shalaev',
12
+ 'birthday' => '09.11.1988',
13
+ 'gender' => 'm'
14
+ }
15
+ end
16
+ let(:request) { double('Request', params: {}, cookies: {}, env: {}) }
17
+ let(:app) do
18
+ lambda do
19
+ [200, {}, ['Hello.']]
20
+ end
21
+ end
22
+
23
+ subject do
24
+ described_class.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
25
+ allow(strategy).to receive(:request) { request }
26
+ end
27
+ end
28
+
29
+ before { OmniAuth.config.test_mode = true }
30
+
31
+ after { OmniAuth.config.test_mode = false }
32
+
33
+ describe 'client options' do
34
+ it do
35
+ expect(subject.client.site).to eq 'https://oauth.mail.ru'
36
+ expect(subject.client.authorize_url).to eq 'https://oauth.mail.ru/login'
37
+ expect(subject.client.token_url).to eq 'https://oauth.mail.ru/token'
38
+ end
39
+ end
40
+
41
+ describe '#authorize_params' do
42
+ it do
43
+ expect(subject.authorize_params).to include(scope: described_class::DEFAULT_SCOPE)
44
+ expect(subject.authorize_params).to be_has_key(:state)
45
+ end
46
+ end
47
+
48
+ describe 'userinfo' do
49
+ let(:expected_userinfo) do
50
+ {
51
+ nickname: 'Andrew Shalaev',
52
+ client_id: 123,
53
+ image: 'https://filin.mail.ru/foobar',
54
+ first_name: 'Andrew',
55
+ email: 'isqad88@gmail.com',
56
+ locate: 'ru_RU',
57
+ name: 'Andrew Shalaev',
58
+ last_name: 'Shalaev',
59
+ birthday: '09.11.1988',
60
+ gender: 'm'
61
+ }
62
+ end
63
+
64
+ before { allow(subject).to receive(:raw_info).and_return(server_userinfo) }
65
+
66
+ it { expect(subject.info).to include(expected_userinfo) }
67
+ end
68
+
69
+ describe 'uid' do
70
+ before { allow(subject).to receive(:raw_info).and_return(server_userinfo) }
71
+
72
+ it { expect(subject.uid).to eq('isqad88@gmail.com') }
73
+ end
74
+ end
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ minimum_coverage 90
6
+ end
7
+
8
+ require 'omniauth-mailru-oauth2'
9
+ require 'pry-byebug'
10
+
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-mailru-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Shalaev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
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: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: appraisal
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
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: test-unit
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: pry-byebug
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:
126
+ email:
127
+ - isqad88@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - README.md
137
+ - Rakefile
138
+ - dip.yml
139
+ - docker-compose.development.yml
140
+ - docker-compose.drone.yml
141
+ - docker-compose.yml
142
+ - lib/omniauth-mailru-oauth2.rb
143
+ - lib/omniauth/mailru_oauth2.rb
144
+ - lib/omniauth/mailru_oauth2/version.rb
145
+ - lib/omniauth/strategies/mailru_oauth2.rb
146
+ - omniauth-mailru-oath2.gemspec
147
+ - spec/omniauth/strategies/mailru_oauth2_spec.rb
148
+ - spec/spec_helper.rb
149
+ homepage: https://github.com/isqad/omniauth-mailru-oauth2
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.7.7
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: OmniAuth strategy for Mail.ru
173
+ test_files:
174
+ - spec/omniauth/strategies/mailru_oauth2_spec.rb
175
+ - spec/spec_helper.rb