omniauth-nk 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +13 -0
- data/README.md +58 -0
- data/Rakefile +7 -0
- data/lib/omniauth-nk.rb +2 -0
- data/lib/omniauth-nk/version.rb +5 -0
- data/lib/omniauth/strategies/nk.rb +78 -0
- data/omniauth-nk.gemspec +27 -0
- metadata +155 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2012 Nasza Klasa Spółka z ograniczoną odpowiedzialnością
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
## nk.pl OAuth2 Strategy for OmniAuth 1.0
|
2
|
+
|
3
|
+
Supports the OAuth 2.0 server-side authentication, and OAuth user data endpoint. To get application key/secret please go to http://developers.nk.pl
|
4
|
+
|
5
|
+
## Installing
|
6
|
+
Add to your `Gemfile`:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'omniauth-nk'
|
10
|
+
```
|
11
|
+
Then `bundle install`.
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Put into your config/initializers/omniauth.rb
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
19
|
+
provider :nk, ENV['NK_KEY'], ENV['NK_SECRET']
|
20
|
+
end
|
21
|
+
|
22
|
+
OmniAuth.config.on_failure do |env|
|
23
|
+
[302, {'Location' => "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{env['omniauth.error.type']}", 'Content-Type'=> 'text/html'}, []]
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
Get own application key/secret from http://developers.nk.pl
|
28
|
+
|
29
|
+
## Auth Hash
|
30
|
+
|
31
|
+
Here's an example *Auth Hash* available in request
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
{
|
35
|
+
:provider => 'nk',
|
36
|
+
:uid => 'person.acbdefgh',
|
37
|
+
:info => {
|
38
|
+
:name => 'Jan Kowalski',
|
39
|
+
:email => 'jan@kowalski.pl',
|
40
|
+
:age => 33,
|
41
|
+
:gender => 'male'
|
42
|
+
:location => 'Wrocław',
|
43
|
+
:image => 'http://photos.nasza-klasa.pl/125/10/thumb/6646b702e7.jpeg',
|
44
|
+
},
|
45
|
+
:credentials => {
|
46
|
+
:token => 'ABCDEF...',
|
47
|
+
:expires_at => 1321747205,
|
48
|
+
:expires => true
|
49
|
+
},
|
50
|
+
:extra => {
|
51
|
+
:raw_info => {
|
52
|
+
:entry => {
|
53
|
+
[see http://developers.nk.pl/wiki/Rest_Service_Profile_Information]
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
```
|
data/Rakefile
ADDED
data/lib/omniauth-nk.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'oauth'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class Nk < OmniAuth::Strategies::OAuth2
|
8
|
+
|
9
|
+
DEFAULT_RESPONSE_TYPE = 'code'
|
10
|
+
DEFAULT_GRANT = 'authorization_code'
|
11
|
+
DEFAULT_SCOPE = 'BASIC_PROFILE_ROLE,EMAIL_PROFILE_ROLE'
|
12
|
+
|
13
|
+
option :name, "nk"
|
14
|
+
|
15
|
+
option :client_options, {
|
16
|
+
:site => 'https://nk.pl',
|
17
|
+
:authorize_url => '/oauth2/login',
|
18
|
+
:token_url => '/oauth2/token'
|
19
|
+
}
|
20
|
+
|
21
|
+
def callback_phase
|
22
|
+
if request.params['error'] || request.params['error_description']
|
23
|
+
fail!(request.params['error'], CallbackError.new(request.params['error'], request.params['error_description'], request.params['error_uri']))
|
24
|
+
end
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
def authorize_params
|
29
|
+
super.tap do |params|
|
30
|
+
params[:scope] ||= DEFAULT_SCOPE
|
31
|
+
params[:response_type] ||= DEFAULT_RESPONSE_TYPE
|
32
|
+
params[:client_id] = client.id
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def token_params
|
37
|
+
super.tap do |params|
|
38
|
+
params[:scope] ||= DEFAULT_SCOPE
|
39
|
+
params[:grant_type] ||= DEFAULT_GRANT
|
40
|
+
params[:client_id] = client.id
|
41
|
+
params[:client_secret] = client.secret
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
uid do
|
46
|
+
raw_info['entry']['id']
|
47
|
+
end
|
48
|
+
|
49
|
+
info do
|
50
|
+
row = raw_info['entry']
|
51
|
+
{
|
52
|
+
:name => row['name']['formatted'],
|
53
|
+
:email => row['emails'].instance_of?(Array) ? row['emails'].last['value'] : nil,
|
54
|
+
:age => row['age'].to_i,
|
55
|
+
:gender => row['gender'],
|
56
|
+
:location => row['currentLocation']['region'],
|
57
|
+
:image => row['thumbnailUrl'],
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
extra do
|
62
|
+
{ :raw_info => raw_info }
|
63
|
+
end
|
64
|
+
|
65
|
+
def raw_info
|
66
|
+
if @raw_info.nil?
|
67
|
+
# OAuth is used to get user data
|
68
|
+
fields = %w(id name emails age gender currentLocation thumbnailUrl)
|
69
|
+
request_url = "http://opensocial.nk-net.pl/v09/social/rest/people/@me?fields=#{fields.join(',')}&nk_token=#{credentials['token']}"
|
70
|
+
|
71
|
+
consumer = OAuth::Consumer.new(options.client_id, options.client_secret, {:site => 'http://opensocial.nk-net.pl'})
|
72
|
+
@raw_info = MultiJson.decode(OAuth::AccessToken.new(consumer, credentials['token']).get(request_url).body.to_s)
|
73
|
+
end
|
74
|
+
@raw_info
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/omniauth-nk.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'omniauth-nk/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "omniauth-nk"
|
7
|
+
gem.version = Omniauth::Nk::VERSION
|
8
|
+
gem.authors = ["Arkadiusz Kurylowicz, Nasza Klasa Spolka z ograniczona odpowiedzialnoscia"]
|
9
|
+
gem.date = '2012-05-25'
|
10
|
+
gem.email = ["arkadiusz.kurylowicz@nasza-klasa.pl"]
|
11
|
+
gem.description = %q{OmniAuth Strategy for nk.pl using OAuth2}
|
12
|
+
gem.summary = %q{OmniAuth Strategy for nk.pl using OAuth2}
|
13
|
+
gem.homepage = "https://github.com/naszaklasa/omniauth-nk"
|
14
|
+
|
15
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
gem.files = `git ls-files`.split("\n")
|
17
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'omniauth', '~> 1.0'
|
21
|
+
gem.add_dependency 'omniauth-oauth2', '~> 1.0'
|
22
|
+
gem.add_dependency 'multi_json', '~> 1.0'
|
23
|
+
gem.add_dependency 'oauth', '~> 0.4.6'
|
24
|
+
|
25
|
+
gem.add_development_dependency 'rake'
|
26
|
+
gem.add_development_dependency 'rspec', '~> 2.8'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-nk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 1
|
8
|
+
version: "1.1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Arkadiusz Kurylowicz, Nasza Klasa Spolka z ograniczona odpowiedzialnoscia
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2012-05-25 00:00:00 +02:00
|
17
|
+
default_executable:
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: omniauth
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
version: "1.0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: omniauth-oauth2
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 0
|
44
|
+
version: "1.0"
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: multi_json
|
49
|
+
prerelease: false
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 0
|
58
|
+
version: "1.0"
|
59
|
+
type: :runtime
|
60
|
+
version_requirements: *id003
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: oauth
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
- 4
|
72
|
+
- 6
|
73
|
+
version: 0.4.6
|
74
|
+
type: :runtime
|
75
|
+
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: rake
|
78
|
+
prerelease: false
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
type: :development
|
88
|
+
version_requirements: *id005
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec
|
91
|
+
prerelease: false
|
92
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ~>
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 2
|
99
|
+
- 8
|
100
|
+
version: "2.8"
|
101
|
+
type: :development
|
102
|
+
version_requirements: *id006
|
103
|
+
description: OmniAuth Strategy for nk.pl using OAuth2
|
104
|
+
email:
|
105
|
+
- arkadiusz.kurylowicz@nasza-klasa.pl
|
106
|
+
executables: []
|
107
|
+
|
108
|
+
extensions: []
|
109
|
+
|
110
|
+
extra_rdoc_files: []
|
111
|
+
|
112
|
+
files:
|
113
|
+
- .gitignore
|
114
|
+
- Gemfile
|
115
|
+
- LICENSE
|
116
|
+
- README.md
|
117
|
+
- Rakefile
|
118
|
+
- lib/omniauth-nk.rb
|
119
|
+
- lib/omniauth-nk/version.rb
|
120
|
+
- lib/omniauth/strategies/nk.rb
|
121
|
+
- omniauth-nk.gemspec
|
122
|
+
has_rdoc: true
|
123
|
+
homepage: https://github.com/naszaklasa/omniauth-nk
|
124
|
+
licenses: []
|
125
|
+
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
version: "0"
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
version: "0"
|
147
|
+
requirements: []
|
148
|
+
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 1.3.7
|
151
|
+
signing_key:
|
152
|
+
specification_version: 3
|
153
|
+
summary: OmniAuth Strategy for nk.pl using OAuth2
|
154
|
+
test_files: []
|
155
|
+
|