mojeid 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/cert/cznic-cacert-test.pem +40 -0
- data/lib/attributes.rb +62 -0
- data/lib/helpers.rb +17 -0
- data/lib/mojeid.rb +139 -0
- data/mojeid.gemspec +69 -0
- data/spec/mojeid_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +170 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Add dependencies to develop your gem here.
|
4
|
+
# Include everything needed to run rake, tests, features, etc.
|
5
|
+
group :development do
|
6
|
+
gem "rspec", "~> 2.8.0"
|
7
|
+
gem "rdoc", "~> 3.12"
|
8
|
+
gem "bundler", "~> 1.0.0"
|
9
|
+
gem "jeweler", "~> 1.8.3"
|
10
|
+
gem "rcov", ">= 0"
|
11
|
+
end
|
12
|
+
|
13
|
+
gem "ruby-openid", :git => "git://github.com/joe1chen/ruby-openid.git"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/joe1chen/ruby-openid.git
|
3
|
+
revision: 452053ba4437b3d27ed5360e5a12a83aff4db4e9
|
4
|
+
specs:
|
5
|
+
ruby-openid (2.1.9.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
git (1.2.5)
|
12
|
+
jeweler (1.8.3)
|
13
|
+
bundler (~> 1.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
rdoc
|
17
|
+
json (1.6.5)
|
18
|
+
rake (0.9.2.2)
|
19
|
+
rcov (1.0.0)
|
20
|
+
rdoc (3.12)
|
21
|
+
json (~> 1.4)
|
22
|
+
rspec (2.8.0)
|
23
|
+
rspec-core (~> 2.8.0)
|
24
|
+
rspec-expectations (~> 2.8.0)
|
25
|
+
rspec-mocks (~> 2.8.0)
|
26
|
+
rspec-core (2.8.0)
|
27
|
+
rspec-expectations (2.8.0)
|
28
|
+
diff-lcs (~> 1.1.2)
|
29
|
+
rspec-mocks (2.8.0)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
bundler (~> 1.0.0)
|
36
|
+
jeweler (~> 1.8.3)
|
37
|
+
rcov
|
38
|
+
rdoc (~> 3.12)
|
39
|
+
rspec (~> 2.8.0)
|
40
|
+
ruby-openid!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Richard Říman
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= mojeid
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to mojeid
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Richard Říman. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "mojeid"
|
18
|
+
gem.homepage = "http://github.com/railsformers/mojeid"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{MojeID authentication gem}
|
21
|
+
gem.description = %Q{Gem with common functionality for authentication using MojeID provider. Uses ruby-openid gem for this.}
|
22
|
+
gem.email = "riman.richard@gmail.com"
|
23
|
+
gem.authors = ["Richard Říman"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "mojeid #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.5
|
@@ -0,0 +1,40 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIG8jCCBNqgAwIBAgIJAJq/RWgHJPQyMA0GCSqGSIb3DQEBBQUAMIGBMQswCQYD
|
3
|
+
VQQGEwJDWjEPMA0GA1UEBxMGUHJhZ3VlMRkwFwYDVQQKExBDWi5OSUMsIHoucy5w
|
4
|
+
Lm8uMSwwKgYDVQQDEyNDWi5OSUMgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0
|
5
|
+
eTEYMBYGCSqGSIb3DQEJARYJY2FAbmljLmN6MB4XDTA5MDIxOTEzNTEwNVoXDTE5
|
6
|
+
MDIxNzEzNTEwNVowgYEx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8zWdwDAK6juWGZh4My4wEzTbOK/oYmdUF2
|
36
|
+
Wf95ilOtNURLd3Nl0uH0FyisQ4gFN2PsAay3h/q8iVpbAiL1ESxXtAobDjQuVwQR
|
37
|
+
Qw3z++QWVaqKDXaD0329wgEds6kLSzB3S5K6bf7a1muYTgE2Aemi617L1XErHO7B
|
38
|
+
Ep5tO11alKUJ2oYFSPhIWx7UVrgZwoCcKwRxCkQD6gzS8pDQgz0IPPsDSBAq31o9
|
39
|
+
Zep++ugl
|
40
|
+
-----END CERTIFICATE-----
|
data/lib/attributes.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# for more informations about attributes look at http://www.mojeid.cz/page/800/jak-zavest-mojeid-/
|
2
|
+
|
3
|
+
module MojeIDAttributes
|
4
|
+
AVAILABLE_ATTRIBUTES = %W(
|
5
|
+
http://axschema.org/namePerson
|
6
|
+
http://axschema.org/namePerson/first
|
7
|
+
http://axschema.org/namePerson/last
|
8
|
+
http://axschema.org/namePerson/friendly
|
9
|
+
http://axschema.org/company/name
|
10
|
+
http://axschema.org/contact/postalAddress/home
|
11
|
+
http://axschema.org/contact/postalAddressAdditional/home
|
12
|
+
http://specs.nic.cz/attr/addr/main/street3
|
13
|
+
http://axschema.org/contact/city/home
|
14
|
+
http://axschema.org/contact/state/home
|
15
|
+
http://axschema.org/contact/country/home
|
16
|
+
http://axschema.org/contact/postalCode/home
|
17
|
+
http://specs.nic.cz/attr/addr/bill/street
|
18
|
+
http://specs.nic.cz/attr/addr/bill/street2
|
19
|
+
http://specs.nic.cz/attr/addr/bill/street3
|
20
|
+
http://specs.nic.cz/attr/addr/bill/city
|
21
|
+
http://specs.nic.cz/attr/addr/bill/sp
|
22
|
+
http://specs.nic.cz/attr/addr/bill/cc
|
23
|
+
http://specs.nic.cz/attr/addr/bill/pc
|
24
|
+
http://specs.nic.cz/attr/addr/ship/street
|
25
|
+
http://axschema.org/namePerson
|
26
|
+
http://axschema.org/namePerson/first
|
27
|
+
http://axschema.org/namePerson/last
|
28
|
+
http://axschema.org/namePerson/friendly
|
29
|
+
http://axschema.org/company/name
|
30
|
+
http://axschema.org/contact/postalAddress/h ome
|
31
|
+
http://axschema.org/contact/postalAddressAdditional/home
|
32
|
+
http://specs.nic.cz/attr/addr/main/street3
|
33
|
+
http://axschema.org/contact/city/home
|
34
|
+
http://axschema.org/contact/state/home
|
35
|
+
http://axschema.org/contact/country/home
|
36
|
+
http://axschema.org/contact/postalCode/home
|
37
|
+
http://specs.nic.cz/attr/addr/bill/street
|
38
|
+
http://specs.nic.cz/attr/addr/bill/street2
|
39
|
+
http://specs.nic.cz/attr/addr/bill/street3
|
40
|
+
http://specs.nic.cz/attr/addr/bill/city
|
41
|
+
http://specs.nic.cz/attr/addr/bill/sp
|
42
|
+
http://specs.nic.cz/attr/addr/bill/cc
|
43
|
+
http://specs.nic.cz/attr/addr/bill/pc
|
44
|
+
http://specs.nic.cz/attr/addr/ship/street
|
45
|
+
http://specs.nic.cz/attr/url/linkedin
|
46
|
+
http://axschema.org/contact/IM/ICQ
|
47
|
+
http://axschema.org/contact/IM/Jabber
|
48
|
+
http://axschema.org/contact/IM/Skype
|
49
|
+
http://specs.nic.cz/attr/im/google_talk
|
50
|
+
http://specs.nic.cz/attr/im/windows_live
|
51
|
+
http://specs.nic.cz/attr/contact/ident/vat_ id
|
52
|
+
http://specs.nic.cz/attr/contact/vat
|
53
|
+
http://specs.nic.cz/attr/contact/ident/card
|
54
|
+
http://specs.nic.cz/attr/contact/ident/pass
|
55
|
+
http://specs.nic.cz/attr/contact/ident/ssn
|
56
|
+
http://specs.nic.cz/attr/contact/student
|
57
|
+
http://specs.nic.cz/attr/contact/valid
|
58
|
+
http://specs.nic.cz/attr/contact/status
|
59
|
+
http://specs.nic.cz/attr/contact/adult
|
60
|
+
http://specs.nic.cz/attr/contact/image
|
61
|
+
)
|
62
|
+
end
|
data/lib/helpers.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# helper methods
|
2
|
+
|
3
|
+
def xrds_meta_tag(request)
|
4
|
+
tag :meta, :'http-equiv' => "x-xrds-location", :content => "#{request.protocol}#{request.host_with_port}/xrds.xml"
|
5
|
+
end
|
6
|
+
|
7
|
+
def xrds_response(return_url)
|
8
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
9
|
+
<xrds:XRDS xmlns:xrds=\"xri://$xrds\" xmlns=\"xri://$xrd*($v*2.0)\">
|
10
|
+
<XRD>
|
11
|
+
<Service>
|
12
|
+
<Type>http://specs.openid.net/auth/2.0/return_to</Type>
|
13
|
+
<URI>#{return_url}</URI>
|
14
|
+
</Service>
|
15
|
+
</XRD>
|
16
|
+
</xrds:XRDS>"
|
17
|
+
end
|
data/lib/mojeid.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require "openid"
|
2
|
+
require "openid/store/filesystem"
|
3
|
+
require "openid/extensions/ax"
|
4
|
+
require "openid/extensions/pape"
|
5
|
+
require "attributes"
|
6
|
+
require "helpers"
|
7
|
+
|
8
|
+
class MojeID
|
9
|
+
include MojeIDAttributes
|
10
|
+
|
11
|
+
MOJEID_ENDPOINT = "https://mojeid.cz/endpoint/"
|
12
|
+
MOJEID_ENDPOINT_TEST = "https://mojeid.fred.nic.cz/endpoint/"
|
13
|
+
|
14
|
+
@test = false
|
15
|
+
|
16
|
+
def initialize(options={:test => false})
|
17
|
+
@test = options[:test]
|
18
|
+
OpenID::fetcher.ca_file = "#{File.dirname(__FILE__)}/cert/cznic-cacert-test.pem" if @test
|
19
|
+
end
|
20
|
+
|
21
|
+
class DiscoveryFailure < OpenID::DiscoveryFailure; end
|
22
|
+
|
23
|
+
attr_accessor :return_to, :realm, :auth_request, :auth_response, :ax_request, :ax_response, :xrds_result
|
24
|
+
|
25
|
+
def self.get_openid_store(filestore_path)
|
26
|
+
OpenID::Store::Filesystem.new(filestore_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.get_consumer(session, store)
|
30
|
+
OpenID::Consumer.new(session, store)
|
31
|
+
end
|
32
|
+
|
33
|
+
def fetch_request(consumer)
|
34
|
+
identifier = @test ? MOJEID_ENDPOINT_TEST : MOJEID_ENDPOINT
|
35
|
+
process_discovery(consumer, identifier)
|
36
|
+
@ax_request = OpenID::AX::FetchRequest.new
|
37
|
+
pape_request = OpenID::PAPE::Request.new([OpenID::PAPE::AUTH_PHISHING_RESISTANT])
|
38
|
+
@auth_request.add_extension(pape_request)
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch_response(consumer, params, request, current_url)
|
42
|
+
process_response_by_type(:get, consumer, params, request, current_url)
|
43
|
+
@auth_response
|
44
|
+
end
|
45
|
+
|
46
|
+
def store_request(consumer)
|
47
|
+
identifier = @test ? MOJEID_ENDPOINT_TEST : MOJEID_ENDPOINT
|
48
|
+
process_discovery(consumer, identifier)
|
49
|
+
@ax_request = OpenID::AX::StoreRequest.new
|
50
|
+
end
|
51
|
+
|
52
|
+
def store_response(consumer, params, request, current_url)
|
53
|
+
process_response_by_type(:put, consumer, params, request, current_url)
|
54
|
+
@auth_response
|
55
|
+
end
|
56
|
+
|
57
|
+
# Add attributes you would like to read about user, to request.
|
58
|
+
# You can pass attribute as array and change options like ns_alias or require.
|
59
|
+
# * example: @moje_id.add_attributes(['http://axschema.org/namePerson', nil, false])
|
60
|
+
# * or simple : @moje_id.add_attributes('http://axschema.org/namePerson')
|
61
|
+
def add_attributes(attributes=[])
|
62
|
+
attributes.each do |attribute|
|
63
|
+
attribute.is_a?(Array) ? add_attribute(attribute[0], attribute[1], attribute[2]) : add_attribute(attribute)
|
64
|
+
end
|
65
|
+
pack_attributes_into_request
|
66
|
+
end
|
67
|
+
|
68
|
+
# Add attributes and they values which you would like to update user profile, to the request.
|
69
|
+
# Accepts hash like { 'http://axschema.org/namePerson' => 'my new great name' }.
|
70
|
+
def update_attributes(data={})
|
71
|
+
data.each { |attribute, value| set_attribute(attribute, value) }
|
72
|
+
pack_attributes_into_request
|
73
|
+
end
|
74
|
+
|
75
|
+
# returns the url you have to redirect after you compose your request
|
76
|
+
def redirect_url(immediate=false)
|
77
|
+
@auth_request.redirect_url(realm, return_to, immediate)
|
78
|
+
end
|
79
|
+
|
80
|
+
def response_status
|
81
|
+
case @auth_response.status
|
82
|
+
when OpenID::Consumer::FAILURE then return :failure
|
83
|
+
when OpenID::Consumer::SUCCESS then return :success
|
84
|
+
when OpenID::Consumer::SETUP_NEEDED then return :setup_needed
|
85
|
+
when OpenID::Consumer::CANCEL then return :cancel
|
86
|
+
else return :unknown
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Return data parsed to a Hash.
|
91
|
+
def data
|
92
|
+
@ax_response.data rescue {}
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def process_discovery(consumer, identifier)
|
98
|
+
begin
|
99
|
+
@auth_request = consumer.begin(identifier)
|
100
|
+
rescue OpenID::DiscoveryFailure => f
|
101
|
+
raise DiscoveryFailure.new(f.message, f.http_response)
|
102
|
+
end
|
103
|
+
@xrds_result = OpenID::Yadis::DiscoveryResult.new(@return_to)
|
104
|
+
end
|
105
|
+
|
106
|
+
def process_response_by_type(type, consumer, params, request, current_url)
|
107
|
+
@auth_response = consumer.complete(params.reject { |k, v| request.path_parameters.key?(k.to_sym) }, current_url)
|
108
|
+
if @auth_response.status == OpenID::Consumer::SUCCESS
|
109
|
+
if type == :get
|
110
|
+
@ax_response = OpenID::AX::FetchResponse.from_success_response(@auth_response)
|
111
|
+
elsif type == :put
|
112
|
+
@ax_response = OpenID::AX::StoreResponse.from_success_response(@auth_response)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Check if the attribute is available. You can find full list of attributes in lib/attributes.rb
|
118
|
+
def self.is_attribute_available?(attribute)
|
119
|
+
MojeIDAttributes::AVAILABLE_ATTRIBUTES.include?(attribute) ? true : raise("'#{attribute}' is not available")
|
120
|
+
end
|
121
|
+
|
122
|
+
def add_attribute(attribute, ns_alias=nil, required=false)
|
123
|
+
if MojeID.is_attribute_available?(attribute)
|
124
|
+
@ax_request.add(OpenID::AX::AttrInfo.new(attribute, ns_alias, required))
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Pack attributes and theirs values to request when you would like to store attribute.
|
129
|
+
def set_attribute(attribute, value)
|
130
|
+
if is_attribute_available?(attribute)
|
131
|
+
fetch_request.set_values(attribute, value)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def pack_attributes_into_request
|
136
|
+
@auth_request.add_extension(@ax_request)
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
data/mojeid.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "mojeid"
|
8
|
+
s.version = "0.1.5"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Richard \305\230\303\255man"]
|
12
|
+
s.date = "2012-05-28"
|
13
|
+
s.description = "Gem with common functionality for authentication using MojeID provider. Uses ruby-openid gem for this."
|
14
|
+
s.email = "riman.richard@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"cert/cznic-cacert-test.pem",
|
29
|
+
"lib/attributes.rb",
|
30
|
+
"lib/helpers.rb",
|
31
|
+
"lib/mojeid.rb",
|
32
|
+
"mojeid.gemspec",
|
33
|
+
"spec/mojeid_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = "http://github.com/railsformers/mojeid"
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = "1.8.21"
|
40
|
+
s.summary = "MojeID authentication gem"
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<ruby-openid>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
48
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
49
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
51
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<ruby-openid>, [">= 0"])
|
54
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
55
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
58
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<ruby-openid>, [">= 0"])
|
62
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
63
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/spec/mojeid_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'mojeid'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mojeid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "Richard \xC5\x98\xC3\xADman"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-05-28 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
type: :runtime
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
version_requirements: *id001
|
32
|
+
name: ruby-openid
|
33
|
+
prerelease: false
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
type: :development
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 47
|
42
|
+
segments:
|
43
|
+
- 2
|
44
|
+
- 8
|
45
|
+
- 0
|
46
|
+
version: 2.8.0
|
47
|
+
version_requirements: *id002
|
48
|
+
name: rspec
|
49
|
+
prerelease: false
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
type: :development
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 31
|
58
|
+
segments:
|
59
|
+
- 3
|
60
|
+
- 12
|
61
|
+
version: "3.12"
|
62
|
+
version_requirements: *id003
|
63
|
+
name: rdoc
|
64
|
+
prerelease: false
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
type: :development
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 23
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 0
|
76
|
+
- 0
|
77
|
+
version: 1.0.0
|
78
|
+
version_requirements: *id004
|
79
|
+
name: bundler
|
80
|
+
prerelease: false
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
type: :development
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 49
|
89
|
+
segments:
|
90
|
+
- 1
|
91
|
+
- 8
|
92
|
+
- 3
|
93
|
+
version: 1.8.3
|
94
|
+
version_requirements: *id005
|
95
|
+
name: jeweler
|
96
|
+
prerelease: false
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
type: :development
|
99
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
version_requirements: *id006
|
109
|
+
name: rcov
|
110
|
+
prerelease: false
|
111
|
+
description: Gem with common functionality for authentication using MojeID provider. Uses ruby-openid gem for this.
|
112
|
+
email: riman.richard@gmail.com
|
113
|
+
executables: []
|
114
|
+
|
115
|
+
extensions: []
|
116
|
+
|
117
|
+
extra_rdoc_files:
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.rdoc
|
120
|
+
files:
|
121
|
+
- .document
|
122
|
+
- .rspec
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.rdoc
|
127
|
+
- Rakefile
|
128
|
+
- VERSION
|
129
|
+
- cert/cznic-cacert-test.pem
|
130
|
+
- lib/attributes.rb
|
131
|
+
- lib/helpers.rb
|
132
|
+
- lib/mojeid.rb
|
133
|
+
- mojeid.gemspec
|
134
|
+
- spec/mojeid_spec.rb
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
homepage: http://github.com/railsformers/mojeid
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
hash: 3
|
159
|
+
segments:
|
160
|
+
- 0
|
161
|
+
version: "0"
|
162
|
+
requirements: []
|
163
|
+
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 1.8.21
|
166
|
+
signing_key:
|
167
|
+
specification_version: 3
|
168
|
+
summary: MojeID authentication gem
|
169
|
+
test_files: []
|
170
|
+
|