omniauth-draugiem 1.0.1
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 +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/lib/omniauth-draugiem.rb +2 -0
- data/lib/omniauth-draugiem/version.rb +5 -0
- data/lib/omniauth/strategies/draugiem.rb +98 -0
- data/omniauth-draugiem.gemspec +30 -0
- data/spec/omniauth/strategies/draugiem_spec.rb +51 -0
- data/spec/spec_helper.rb +12 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: be3b7eb114c496930595e2fb4840a13633fde8b3
|
4
|
+
data.tar.gz: 1cf0b1bedfccec6c192e77d8e61cab3edf10ed3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c4e85ad7699f5ae228a282fc79799d138fba55175060c5f0a80d0910c95887a6007f4aaeb1e93f02dcff32e823d487e8a12fdd0d99f9c1b394617f8926b317f
|
7
|
+
data.tar.gz: 49438ac6f4d96de1be1df729a8fd39c1be5a4d97e9388cb4bb11d86e9c3a189a2dafa2b8118ad0fb0cc94031156849d7aa44d226441584354508363eb1d5c65c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Edgars Beigarts
|
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,35 @@
|
|
1
|
+
# Omniauth::Draugiem
|
2
|
+
|
3
|
+
[](http://travis-ci.org/mak-it/omniauth-draugiem)
|
4
|
+
|
5
|
+
OmniAuth strategy for authenticating to draugiem.lv
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'omniauth-draugiem'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install omniauth-draugiem
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Add this to config/initializers/omniauth.rb
|
24
|
+
|
25
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
26
|
+
provider :draugiem, 'app_id', 'api_key'
|
27
|
+
end
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( http://github.com/mak-it/omniauth-draugiem/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'omniauth'
|
4
|
+
require 'rest_client'
|
5
|
+
|
6
|
+
module OmniAuth
|
7
|
+
module Strategies
|
8
|
+
#
|
9
|
+
# Authenticate to draugiem.lv and frype.com and others.
|
10
|
+
#
|
11
|
+
# @example Basic Rails Usage
|
12
|
+
#
|
13
|
+
# Add this to config/initializers/omniauth.rb
|
14
|
+
#
|
15
|
+
# Rails.application.config.middleware.use OmniAuth::Builder do
|
16
|
+
# provider :draugiem, 'App id', 'API Key'
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# @example Basic Rack example
|
20
|
+
#
|
21
|
+
# use Rack::Session::Cookie
|
22
|
+
# use OmniAuth::Strategies::Draugiem, 'App id', 'API Key'
|
23
|
+
#
|
24
|
+
class Draugiem
|
25
|
+
include OmniAuth::Strategy
|
26
|
+
|
27
|
+
args [:app_id, :api_key]
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def request_phase
|
32
|
+
params = {
|
33
|
+
:app => options.app_id,
|
34
|
+
:redirect => callback_url,
|
35
|
+
:hash => Digest::MD5.hexdigest("#{options.api_key}#{callback_url}")
|
36
|
+
}
|
37
|
+
query_string = params.collect{ |key,value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&')
|
38
|
+
redirect "http://api.draugiem.lv/authorize/?#{query_string}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def callback_phase
|
42
|
+
if request.params['dr_auth_status'] == 'ok' && request.params['dr_auth_code']
|
43
|
+
response = RestClient.get('http://api.draugiem.lv/json/', { :params => draugiem_authorize_params(request.params['dr_auth_code']) })
|
44
|
+
auth = MultiJson.decode(response.to_s)
|
45
|
+
unless auth['error']
|
46
|
+
@auth_data = auth
|
47
|
+
super
|
48
|
+
else
|
49
|
+
fail!(auth['error']['code'].to_s,auth["error"]["description"].to_s)
|
50
|
+
end
|
51
|
+
else
|
52
|
+
fail!(:invalid_request)
|
53
|
+
end
|
54
|
+
rescue Exception => e
|
55
|
+
fail!(:invalid_response, e)
|
56
|
+
end
|
57
|
+
|
58
|
+
uid { @auth_data['uid'] }
|
59
|
+
|
60
|
+
credentials do
|
61
|
+
{ 'apikey' => @auth_data['apikey'] }
|
62
|
+
end
|
63
|
+
|
64
|
+
info do
|
65
|
+
if @auth_data['users'] && @auth_data['users'][@auth_data['uid']]
|
66
|
+
user = @auth_data['users'][@auth_data['uid']]
|
67
|
+
{
|
68
|
+
'name' => "#{user['name']} #{user['surname']}",
|
69
|
+
'nickname' => user['nick'],
|
70
|
+
'first_name' => user['name'],
|
71
|
+
'last_name' => user['surname'],
|
72
|
+
'location' => user['place'],
|
73
|
+
'age' => user['age'] =~ /^0-9$/ ? user['age'] : nil,
|
74
|
+
'adult' => user['adult'] == '1' ? true : false,
|
75
|
+
'image' => user['img'],
|
76
|
+
'sex' => user['sex']
|
77
|
+
}
|
78
|
+
else
|
79
|
+
{}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
extra do
|
84
|
+
{ 'user_hash' => @auth_data }
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def draugiem_authorize_params code
|
90
|
+
{
|
91
|
+
:action => 'authorize',
|
92
|
+
:app => options.api_key,
|
93
|
+
:code => code
|
94
|
+
}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omniauth-draugiem/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "omniauth-draugiem"
|
8
|
+
s.version = Omniauth::Draugiem::VERSION
|
9
|
+
s.authors = ["Edgars Beigarts", "Uldis Ziņģis"]
|
10
|
+
s.email = ["edgars.beigarts@makit.lv", "uldis.zingis@makit.lv"]
|
11
|
+
s.summary = "Draugiem.lv authentication strategy for OmniAuth"
|
12
|
+
s.description = s.summary
|
13
|
+
s.homepage = "http://github.com/mak-it/omniauth-draugiem"
|
14
|
+
s.license = "MIT"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split($/)
|
17
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
s.test_files = s.files.grep(%r{^spec/})
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_runtime_dependency "omniauth", "~> 1.0"
|
22
|
+
s.add_runtime_dependency "rest-client", "~> 1.6"
|
23
|
+
|
24
|
+
s.add_development_dependency "bundler", "~> 1.5"
|
25
|
+
s.add_development_dependency "rake"
|
26
|
+
s.add_development_dependency "rspec"
|
27
|
+
s.add_development_dependency "simplecov"
|
28
|
+
s.add_development_dependency "rack-test"
|
29
|
+
s.add_development_dependency 'webmock'
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe 'OmniAuth::Strategies::Draugiem', :type => :strategy do
|
4
|
+
|
5
|
+
include OmniAuth::Test::StrategyTestCase
|
6
|
+
|
7
|
+
def strategy
|
8
|
+
[OmniAuth::Strategies::Draugiem, '123', "abc"]
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should initialize with api key and app id' do
|
12
|
+
lambda{OmniAuth::Strategies::Draugiem.new({},'123','abc')}.should_not raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '/auth/draugiem' do
|
16
|
+
|
17
|
+
it 'should redirect to api.draugiem.lv' do
|
18
|
+
get '/auth/draugiem'
|
19
|
+
last_response.should be_redirect
|
20
|
+
last_response.headers['Location'].should match %r{http://api\.draugiem\.lv/authorize/}
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should gather user data after success authorization' do
|
24
|
+
stub_request(:get, "http://api.draugiem.lv/json/?action=authorize&app=abc&code=123456").
|
25
|
+
to_return(:body => MultiJson.encode({
|
26
|
+
'apikey'=>"123456789",
|
27
|
+
'uid'=>"100",
|
28
|
+
'language'=>"lv",
|
29
|
+
'users'=>{
|
30
|
+
'100'=>{
|
31
|
+
'uid'=>"100",
|
32
|
+
'name'=>"John",
|
33
|
+
'surname'=>"Lenon",
|
34
|
+
'nick'=>"johnybravo",
|
35
|
+
'place'=>"Durbe",
|
36
|
+
'age'=>"false",
|
37
|
+
'adult'=>"1",
|
38
|
+
'img'=>"http://4.bp.blogspot.com/_ZmXOoYjxXog/Sg2jby1RFSI/AAAAAAAAE_Q/1LpfjimAz50/s400/JohnnyBravo3.gif",
|
39
|
+
'sex'=>"M"
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}))
|
43
|
+
get '/auth/draugiem/callback?dr_auth_status=ok&dr_auth_code=123456'
|
44
|
+
|
45
|
+
last_request.env['omniauth.auth']['credentials']['apikey'].should == "123456789"
|
46
|
+
last_request.env['omniauth.auth']['info']['location'].should == "Durbe"
|
47
|
+
last_request.env['omniauth.auth']['info']['age'].should be_nil
|
48
|
+
last_request.env['omniauth.auth']['info']['adult'].should be_true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
require 'rspec'
|
4
|
+
require 'rack/test'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
require 'omniauth-draugiem'
|
7
|
+
require 'omniauth'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.include Rack::Test::Methods
|
11
|
+
config.include WebMock::API
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-draugiem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Edgars Beigarts
|
8
|
+
- Uldis Ziņģis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rest-client
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.6'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.6'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.5'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.5'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: simplecov
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rack-test
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: webmock
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: Draugiem.lv authentication strategy for OmniAuth
|
127
|
+
email:
|
128
|
+
- edgars.beigarts@makit.lv
|
129
|
+
- uldis.zingis@makit.lv
|
130
|
+
executables: []
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- ".gitignore"
|
135
|
+
- ".travis.yml"
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- lib/omniauth-draugiem.rb
|
141
|
+
- lib/omniauth-draugiem/version.rb
|
142
|
+
- lib/omniauth/strategies/draugiem.rb
|
143
|
+
- omniauth-draugiem.gemspec
|
144
|
+
- spec/omniauth/strategies/draugiem_spec.rb
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
homepage: http://github.com/mak-it/omniauth-draugiem
|
147
|
+
licenses:
|
148
|
+
- MIT
|
149
|
+
metadata: {}
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
requirements: []
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 2.2.0.rc.1
|
167
|
+
signing_key:
|
168
|
+
specification_version: 4
|
169
|
+
summary: Draugiem.lv authentication strategy for OmniAuth
|
170
|
+
test_files:
|
171
|
+
- spec/omniauth/strategies/draugiem_spec.rb
|
172
|
+
- spec/spec_helper.rb
|