omniauth-mailru 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +22 -0
- data/Guardfile +5 -0
- data/README.md +22 -0
- data/Rakefile +20 -0
- data/examples/config.ru +41 -0
- data/lib/omniauth-mailru.rb +8 -0
- data/lib/omniauth-mailru/version.rb +5 -0
- data/lib/omniauth/strategies/mailru.rb +63 -0
- data/omniauth-mailru.gemspec +22 -0
- data/spec/omniauth/strategies/mailru_spec.rb +11 -0
- data/spec/spec_helper.rb +14 -0
- metadata +83 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :development, :test do
|
6
|
+
gem "rake"
|
7
|
+
|
8
|
+
gem "rspec", "~> 2.7"
|
9
|
+
gem "rack-test"
|
10
|
+
gem "webmock"
|
11
|
+
gem "guard"
|
12
|
+
gem "guard-rspec"
|
13
|
+
|
14
|
+
if RUBY_PLATFORM =~ /darwin/i
|
15
|
+
gem "rb-fsevent", :require => false
|
16
|
+
gem "growl_notify", :require => false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
group :example do
|
21
|
+
gem "sinatra"
|
22
|
+
end
|
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# OmniAuth Mail.ru
|
2
|
+
|
3
|
+
This gem contains the unofficial Mail.ru OAuth2 strategy for OmniAuth.
|
4
|
+
|
5
|
+
[![Build Status](https://secure.travis-ci.org/gumayunov/omniauth-mailru.png)](http://travis-ci.org/gumayunov/omniauth-mailru)
|
6
|
+
|
7
|
+
## Basic Usage
|
8
|
+
|
9
|
+
use OmniAuth::Builder do
|
10
|
+
provider :mailru, ENV['MAILRU_KEY'], ENV['MAILRU_PRIVATE_KEY']
|
11
|
+
end
|
12
|
+
|
13
|
+
## License
|
14
|
+
|
15
|
+
Copyright (c) 2011 by Victor Gumayunov
|
16
|
+
|
17
|
+
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:
|
18
|
+
|
19
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
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.
|
22
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'bundler/gem_tasks'
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
desc 'Default: run specs.'
|
14
|
+
task :default => :spec
|
15
|
+
|
16
|
+
desc "Run specs"
|
17
|
+
RSpec::Core::RakeTask.new
|
18
|
+
|
19
|
+
desc 'Run specs'
|
20
|
+
task :default => :spec
|
data/examples/config.ru
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Sample app for Google OAuth2 Strategy
|
2
|
+
# Make sure to setup the ENV variables GOOGLE_KEY and GOOGLE_SECRET
|
3
|
+
# Run with "bundle exec rackup"
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler'
|
7
|
+
require 'sinatra'
|
8
|
+
require 'omniauth'
|
9
|
+
require 'omniauth-mailru'
|
10
|
+
|
11
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
12
|
+
|
13
|
+
class App < Sinatra::Base
|
14
|
+
get '/' do
|
15
|
+
<<-HTML
|
16
|
+
<ul>
|
17
|
+
<li><a href='/auth/mailru'>Sign in with Mail.ri</a></li>
|
18
|
+
</ul>
|
19
|
+
HTML
|
20
|
+
end
|
21
|
+
|
22
|
+
get '/auth/:provider/callback' do
|
23
|
+
content_type 'text/plain'
|
24
|
+
request.env['omniauth.auth'].to_hash.inspect
|
25
|
+
end
|
26
|
+
|
27
|
+
get '/auth/failure' do
|
28
|
+
content_type 'text/plain'
|
29
|
+
request.env['omniauth.auth'].to_hash.inspect
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
use Rack::Session::Cookie
|
34
|
+
|
35
|
+
use OmniAuth::Builder do
|
36
|
+
provider :mailru, ENV['MAILRU_KEY'], ENV['MAILRU_PRIVATE']
|
37
|
+
end
|
38
|
+
|
39
|
+
run App.new
|
40
|
+
|
41
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'omniauth/strategies/oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
|
6
|
+
# Authenticate to Mail.ru utilizing OAuth 2.0
|
7
|
+
# http://api.mail.ru/docs/guides/oauth/sites/
|
8
|
+
|
9
|
+
class Mailru < OmniAuth::Strategies::OAuth2
|
10
|
+
option :name, "mailru"
|
11
|
+
|
12
|
+
option :client_options, {
|
13
|
+
:site => 'https://connect.mail.ru/',
|
14
|
+
:token_url => '/oauth/token',
|
15
|
+
:authorize_url => '/oauth/authorize'
|
16
|
+
}
|
17
|
+
|
18
|
+
uid do
|
19
|
+
access_token.params['x_mailru_vid']
|
20
|
+
end
|
21
|
+
|
22
|
+
info do
|
23
|
+
{
|
24
|
+
:nickname => raw_info['nick'],
|
25
|
+
:email => raw_info['email'],
|
26
|
+
:name => raw_info['name'],
|
27
|
+
:first_name => raw_info['first_name'],
|
28
|
+
:last_name => raw_info['last_name'],
|
29
|
+
:image => (raw_info['has_pic'].to_s != "0") && raw_info['pic_big'] || nil,
|
30
|
+
:location => (raw_info['location'] || {})['name']
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
extra do
|
35
|
+
{:raw_info => raw_info}
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def raw_info
|
41
|
+
@raw_info ||= begin
|
42
|
+
params = {
|
43
|
+
:method => 'users.getInfo',
|
44
|
+
:app_id => options.client_id,
|
45
|
+
:session_id => access_token.token,
|
46
|
+
:format => "json"
|
47
|
+
}
|
48
|
+
params[:sig] = calc_signature(params)
|
49
|
+
result = access_token.get('http://appsmail.ru/platform/api', :params => params).parsed.first
|
50
|
+
result
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def calc_signature(hash)
|
55
|
+
raw = hash.map{|key, value| [key, value].join('=')}.sort.join
|
56
|
+
raw = [uid, raw, options.client_secret].join
|
57
|
+
Digest::MD5.hexdigest(raw)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "omniauth-mailru/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "omniauth-mailru"
|
6
|
+
s.version = Omniauth::Mailru::VERSION
|
7
|
+
s.authors = ["Victor Gumayunov"]
|
8
|
+
s.email = ["gumayunov@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/gumayuniv/omniauth-mailru"
|
10
|
+
s.summary = %q{OmniAuth strategy for Mail.ru}
|
11
|
+
s.description = %q{OmniAuth strategy for Mail.ru}
|
12
|
+
|
13
|
+
s.rubyforge_project = "omniauth-mailru"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency 'omniauth', '~> 1.0'
|
21
|
+
s.add_dependency 'omniauth-oauth2', '~> 1.0'
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'rspec'
|
4
|
+
require 'rack/test'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
require 'omniauth'
|
7
|
+
require 'omniauth-mailru'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.include WebMock::API
|
11
|
+
config.include Rack::Test::Methods
|
12
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
13
|
+
end
|
14
|
+
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-mailru
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Victor Gumayunov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-15 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth
|
16
|
+
requirement: &70142864223120 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70142864223120
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: omniauth-oauth2
|
27
|
+
requirement: &70142864221740 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70142864221740
|
36
|
+
description: OmniAuth strategy for Mail.ru
|
37
|
+
email:
|
38
|
+
- gumayunov@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .rspec
|
45
|
+
- .travis.yml
|
46
|
+
- Gemfile
|
47
|
+
- Guardfile
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- examples/config.ru
|
51
|
+
- lib/omniauth-mailru.rb
|
52
|
+
- lib/omniauth-mailru/version.rb
|
53
|
+
- lib/omniauth/strategies/mailru.rb
|
54
|
+
- omniauth-mailru.gemspec
|
55
|
+
- spec/omniauth/strategies/mailru_spec.rb
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
homepage: https://github.com/gumayuniv/omniauth-mailru
|
58
|
+
licenses: []
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project: omniauth-mailru
|
77
|
+
rubygems_version: 1.8.10
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: OmniAuth strategy for Mail.ru
|
81
|
+
test_files:
|
82
|
+
- spec/omniauth/strategies/mailru_spec.rb
|
83
|
+
- spec/spec_helper.rb
|