omniauth-mail_ru 1.0.1 → 1.1.0
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 +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +22 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +0 -0
- data/Rakefile +1 -2
- data/lib/omniauth/mail_ru/version.rb +1 -1
- data/lib/omniauth/strategies/mail_ru.rb +30 -23
- data/lib/omniauth-mail_ru.rb +1 -1
- data/omniauth-mail_ru.gemspec +5 -3
- data/spec/omniauth/strategies/mail_ru_spec.rb +99 -0
- data/spec/rubocop_spec.rb +9 -0
- data/spec/spec_helper.rb +4 -0
- metadata +53 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4443bb97ff026aa10df7700596b0177dfd8599ed660e5b7f77b483def1e800bc
|
4
|
+
data.tar.gz: b8dcab96ae5729a6f1ff8389ba5f1752e256e19c7d7ef9fa2ba8186e042134e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa7ec35b215d200aa65b095af9191c7339c75f3131526eb3d8f1cb304ea10f63fdd2a61b7fb85ded75dd4a6180401403a7d01795b8f44b04aa17ea99d6e699e3
|
7
|
+
data.tar.gz: 14b7d3666fd9ead84b70da5ed03d40812f17e5658250f4540304a7e2be1febb9164bceccd2b4cc3f2d964c20d7d737854c0e221683eb37830d3017cc0c604807
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
ClassLength:
|
2
|
+
Enabled: false
|
3
|
+
Layout/IndentHeredoc:
|
4
|
+
Enabled: false
|
5
|
+
Metrics/AbcSize:
|
6
|
+
Enabled: false
|
7
|
+
Metrics/BlockLength:
|
8
|
+
ExcludedMethods: ['describe', 'context']
|
9
|
+
Metrics/CyclomaticComplexity:
|
10
|
+
Enabled: false
|
11
|
+
Metrics/LineLength:
|
12
|
+
Enabled: false
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Enabled: false
|
15
|
+
Metrics/PerceivedComplexity:
|
16
|
+
Enabled: false
|
17
|
+
Naming:
|
18
|
+
Enabled: false
|
19
|
+
Style/MutableConstant:
|
20
|
+
Enabled: false
|
21
|
+
Gemspec/RequiredRubyVersion:
|
22
|
+
Enabled: false
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -2,46 +2,53 @@ require 'omniauth-oauth2'
|
|
2
2
|
|
3
3
|
module OmniAuth
|
4
4
|
module Strategies
|
5
|
+
# Authentication strategy for connecting with Mail.ru OAuth 2.0
|
5
6
|
class MailRu < OmniAuth::Strategies::OAuth2
|
6
7
|
option :name, 'mail_ru'
|
7
8
|
|
8
|
-
option :client_options,
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
}
|
9
|
+
option :client_options,
|
10
|
+
site: 'https://connect.mail.ru',
|
11
|
+
token_url: '/oauth/token',
|
12
|
+
authorize_url: '/oauth/authorize'
|
13
13
|
|
14
14
|
uid { access_token.params['x_mailru_vid'] }
|
15
15
|
|
16
16
|
info do
|
17
17
|
{
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
name: [raw_info['first_name'], raw_info['last_name']].join(' ').strip,
|
19
|
+
email: raw_info['email'],
|
20
|
+
nickname: raw_info['nick'],
|
21
|
+
first_name: raw_info['first_name'],
|
22
|
+
last_name: raw_info['last_name'],
|
23
|
+
image: raw_info['has_pic'].to_i == 1 ? (raw_info['pic_50'] || raw_info['pic_small']) : nil,
|
24
|
+
urls: {
|
25
|
+
'Mailru' => raw_info['link']
|
26
|
+
}
|
27
27
|
}
|
28
28
|
end
|
29
29
|
|
30
30
|
extra do
|
31
31
|
{
|
32
|
-
|
32
|
+
raw_info: raw_info
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
36
36
|
def raw_info
|
37
|
-
@raw_info ||= access_token.get('
|
37
|
+
@raw_info ||= access_token.get('https://www.appsmail.ru/platform/api', params: info_params).parsed.first
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
private
|
41
|
+
|
42
|
+
def callback_url
|
43
|
+
full_host + script_name + callback_path
|
44
|
+
end
|
45
|
+
|
46
|
+
def info_params
|
41
47
|
params = {
|
42
|
-
|
43
|
-
|
44
|
-
|
48
|
+
app_id: options.client_id,
|
49
|
+
method: 'users.getInfo',
|
50
|
+
secure: 1,
|
51
|
+
session_key: access_token.token
|
45
52
|
}
|
46
53
|
params[:sig] = signature(params)
|
47
54
|
|
@@ -49,9 +56,9 @@ module OmniAuth
|
|
49
56
|
end
|
50
57
|
|
51
58
|
def signature(params)
|
52
|
-
params = params.sort.reduce(
|
53
|
-
Digest::MD5.hexdigest([
|
59
|
+
params = params.sort.reduce([]) { |m, (key, value)| m.push("#{key}=#{value}") }.join
|
60
|
+
Digest::MD5.hexdigest([params, options.client_secret].join)
|
54
61
|
end
|
55
62
|
end
|
56
63
|
end
|
57
|
-
end
|
64
|
+
end
|
data/lib/omniauth-mail_ru.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'omniauth/mail_ru/version'
|
2
|
-
require 'omniauth/strategies/mail_ru'
|
2
|
+
require 'omniauth/strategies/mail_ru'
|
data/omniauth-mail_ru.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'omniauth/mail_ru/version'
|
@@ -8,8 +7,8 @@ Gem::Specification.new do |spec|
|
|
8
7
|
spec.version = OmniAuth::MailRu::VERSION
|
9
8
|
spec.authors = ['Andrey Skuryatin']
|
10
9
|
spec.email = ['andrey.skuryatin@gmai.com']
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
10
|
+
spec.summary = 'OmniAuth strategy for Mail.ru'
|
11
|
+
spec.description = 'OmniAuth strategy for Mail.ru'
|
13
12
|
spec.homepage = 'https://github.com/andrey-skat/omniauth-mail_ru'
|
14
13
|
spec.license = 'MIT'
|
15
14
|
|
@@ -19,4 +18,7 @@ Gem::Specification.new do |spec|
|
|
19
18
|
spec.require_paths = ['lib']
|
20
19
|
|
21
20
|
spec.add_dependency 'omniauth-oauth2', '~> 1.0'
|
21
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.6'
|
23
|
+
spec.add_development_dependency 'rubocop', '~> 0.49'
|
22
24
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'omniauth-mail_ru'
|
5
|
+
|
6
|
+
describe OmniAuth::Strategies::MailRu do
|
7
|
+
let(:request) { double('Request', params: {}, cookies: {}, env: {}) }
|
8
|
+
let(:app) do
|
9
|
+
lambda do
|
10
|
+
[200, {}, ['Hello.']]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject do
|
15
|
+
OmniAuth::Strategies::MailRu.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
|
16
|
+
allow(strategy).to receive(:request) do
|
17
|
+
request
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
before do
|
23
|
+
OmniAuth.config.test_mode = true
|
24
|
+
end
|
25
|
+
|
26
|
+
after do
|
27
|
+
OmniAuth.config.test_mode = false
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#client_options' do
|
31
|
+
it 'has correct site' do
|
32
|
+
expect(subject.client.site).to eq('https://connect.mail.ru')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'has correct authorize_url' do
|
36
|
+
expect(subject.client.options[:authorize_url]).to eq('/oauth/authorize')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'has correct token_url' do
|
40
|
+
expect(subject.client.options[:token_url]).to eq('/oauth/token')
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'overrides' do
|
44
|
+
context 'as strings' do
|
45
|
+
it 'should allow overriding the site' do
|
46
|
+
@options = { client_options: { 'site' => 'https://example.com' } }
|
47
|
+
expect(subject.client.site).to eq('https://example.com')
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should allow overriding the authorize_url' do
|
51
|
+
@options = { client_options: { 'authorize_url' => 'https://example.com' } }
|
52
|
+
expect(subject.client.options[:authorize_url]).to eq('https://example.com')
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should allow overriding the token_url' do
|
56
|
+
@options = { client_options: { 'token_url' => 'https://example.com' } }
|
57
|
+
expect(subject.client.options[:token_url]).to eq('https://example.com')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'as symbols' do
|
62
|
+
it 'should allow overriding the site' do
|
63
|
+
@options = { client_options: { site: 'https://example.com' } }
|
64
|
+
expect(subject.client.site).to eq('https://example.com')
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should allow overriding the authorize_url' do
|
68
|
+
@options = { client_options: { authorize_url: 'https://example.com' } }
|
69
|
+
expect(subject.client.options[:authorize_url]).to eq('https://example.com')
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should allow overriding the token_url' do
|
73
|
+
@options = { client_options: { token_url: 'https://example.com' } }
|
74
|
+
expect(subject.client.options[:token_url]).to eq('https://example.com')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'raw_info' do
|
81
|
+
it 'should have pic_50 url' do
|
82
|
+
allow(subject).to receive(:raw_info) { { 'has_pic' => '1', 'pic_50' => 'http://avt-17.foto.mail.ru/mail/test/_avatar50?111' } }
|
83
|
+
|
84
|
+
expect(subject.info[:image]).to eq('http://avt-17.foto.mail.ru/mail/test/_avatar50?111')
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should have pic_small url' do
|
88
|
+
allow(subject).to receive(:raw_info) { { 'has_pic' => '1', 'pic_small' => 'http://avt-17.foto.mail.ru/mail/test/_avatarsmall?111' } }
|
89
|
+
|
90
|
+
expect(subject.info[:image]).to eq('http://avt-17.foto.mail.ru/mail/test/_avatarsmall?111')
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should not have pic url' do
|
94
|
+
allow(subject).to receive(:raw_info) { { 'has_pic' => '0', 'pic_50' => 'http://avt-17.foto.mail.ru/mail/test/_avatar50?111', 'pic_small' => 'http://avt-17.foto.mail.ru/mail/test/_avatarsmall?111' } }
|
95
|
+
|
96
|
+
expect(subject.info[:image]).to be_nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-mail_ru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Skuryatin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|
@@ -24,6 +24,48 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.49'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.49'
|
27
69
|
description: OmniAuth strategy for Mail.ru
|
28
70
|
email:
|
29
71
|
- andrey.skuryatin@gmai.com
|
@@ -32,6 +74,7 @@ extensions: []
|
|
32
74
|
extra_rdoc_files: []
|
33
75
|
files:
|
34
76
|
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
35
78
|
- Gemfile
|
36
79
|
- LICENSE.txt
|
37
80
|
- README.md
|
@@ -40,6 +83,9 @@ files:
|
|
40
83
|
- lib/omniauth/mail_ru/version.rb
|
41
84
|
- lib/omniauth/strategies/mail_ru.rb
|
42
85
|
- omniauth-mail_ru.gemspec
|
86
|
+
- spec/omniauth/strategies/mail_ru_spec.rb
|
87
|
+
- spec/rubocop_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
43
89
|
homepage: https://github.com/andrey-skat/omniauth-mail_ru
|
44
90
|
licenses:
|
45
91
|
- MIT
|
@@ -60,9 +106,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
106
|
version: '0'
|
61
107
|
requirements: []
|
62
108
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.7.6
|
64
110
|
signing_key:
|
65
111
|
specification_version: 4
|
66
112
|
summary: OmniAuth strategy for Mail.ru
|
67
|
-
test_files:
|
68
|
-
|
113
|
+
test_files:
|
114
|
+
- spec/omniauth/strategies/mail_ru_spec.rb
|
115
|
+
- spec/rubocop_spec.rb
|
116
|
+
- spec/spec_helper.rb
|