grosser-rpx_now 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README.markdown +56 -0
  2. data/Rakefile +21 -0
  3. data/init.rb +1 -0
  4. data/lib/rpx_now.rb +61 -0
  5. data/rpx_now.gemspec +37 -0
  6. metadata +81 -0
data/README.markdown ADDED
@@ -0,0 +1,56 @@
1
+ Problem
2
+ =======
3
+ - OpenID is complex
4
+ - OpenID is not universally used
5
+
6
+ Solution
7
+ ========
8
+ - Use [RPX](http://rpxnow.com) for universal and usable user login
9
+ - Make view/controller helpers for easy integration
10
+
11
+ Usage
12
+ =====
13
+ - Get an API key @ [RPX](http://rpxnow.com)
14
+ - Build login view
15
+ - Communicate with RPX API in controller to create or login User
16
+ - for more advanced features have a look at the [RPX API Docs](https://rpxnow.com/docs)
17
+
18
+ Install
19
+ =======
20
+ - As Rails plugin: `script/plugin install git://github.com/grosser/rpx_now.git `
21
+ - As gem: `sudo gem install grosser-rpx_now --source http://gems.github.com/`
22
+ - As gem from source: `git clone git://github.com/grosser/rpx_now.git`,`cd rpx_now`,`rake manifest`,`rake install`
23
+
24
+ Examples
25
+ ========
26
+
27
+ View
28
+ ----
29
+ #login.erb
30
+ #here 'mywebsite' is your subdomain/realm on RPX
31
+ <%=RPXNow.embed_code('mywebsite',rpx_token_sessions_url)%>
32
+ OR
33
+ <%=RPXNow.popup_code('Login here...','mywebsite',rpx_token_sessions_url,:language=>'de')%>
34
+
35
+ Controller
36
+ ----------
37
+ # simple: use defaults
38
+ def rpx_token
39
+ data = RPXNew.user_data(params[:token],'YOUR RPX API KEY') # :name=>'John Doe',:email=>'john@doe.com',:identifier=>'blug.google.com/openid/dsdfsdfs3f3'
40
+ #when no user_data was found, data is empty, you may want to handle that seperatly...
41
+ #your user model must have an identifier column
42
+ self.current_user = User.find_by_identifier(data[:identifier]) || User.create!(data)
43
+ redirect_to '/'
44
+ end
45
+
46
+ # process the raw response yourself:
47
+ RPXNew.user_data(params[:token],'YOUR RPX API KEY'){|raw| {:email=>raw['profile']['verifiedEmail']}}
48
+
49
+ # request extended parameters (most users and APIs do not supply them)
50
+ RPXNew.user_data(params[:token],'YOUR RPX API KEY',:extended=>'true'){|raw| ...have a look at the RPX API DOCS...}
51
+
52
+ Author
53
+ ======
54
+ Michael Grosser
55
+ grosser.michael@gmail.com
56
+ Hereby placed under public domain, do what you want, just do not hold me accountable...
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'echoe'
3
+
4
+ desc "Run all specs in spec directory"
5
+ task :test do |t|
6
+ options = "--colour --format progress --loadby --reverse"
7
+ files = FileList['spec/**/*_spec.rb']
8
+ system("spec #{options} #{files}")
9
+ end
10
+
11
+ #Gemspec
12
+ porject_name = 'rpx_now'
13
+ Echoe.new(porject_name , '0.2') do |p|
14
+ p.description = "Helper to simplify RPX Now user login/creation"
15
+ p.url = "http://github.com/grosser/#{porject_name}"
16
+ p.author = "Michael Grosser"
17
+ p.email = "grosser.michael@gmail.com"
18
+ p.dependencies = %w[activesupport]
19
+ end
20
+
21
+ task :update_gemspec => [:manifest, :build_gemspec]
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'rpx_now'
data/lib/rpx_now.rb ADDED
@@ -0,0 +1,61 @@
1
+ require 'activesupport'
2
+ module RPXNow
3
+ extend self
4
+ def user_data(token,api_key,parameters={})
5
+ raise "NO API KEY" if api_key.blank?
6
+ data = post('https://rpxnow.com/api/v2/auth_info',{:token=>token,:apiKey=>api_key}.merge(parameters))
7
+ data = ActiveSupport::JSON.decode(data)
8
+ return if data['err']
9
+ if block_given? then yield(data) else read_user_data_from_response(data) end
10
+ end
11
+
12
+ def embed_code(subdomain,url)
13
+ <<EOF
14
+ <iframe src="https://#{subdomain}.rpxnow.com/openid/embed?token_url=#{url}"
15
+ scrolling="no" frameBorder="no" style="width:400px;height:240px;">
16
+ </iframe>
17
+ EOF
18
+ end
19
+
20
+ def popup_code(text,subdomain,url,options={})
21
+ <<EOF
22
+ <a class="rpxnow" onclick="return false;" href="https://rathershort.rpxnow.com/openid/v2/signin?token_url=#{url}">
23
+ #{text}
24
+ </a>
25
+ <script src="https://rpxnow.com/openid/v2/widget" type="text/javascript"></script>
26
+ <script type="text/javascript">
27
+ //<![CDATA[
28
+ RPXNOW.token_url = "#{url}";
29
+
30
+ RPXNOW.realm = "#{subdomain}";
31
+ RPXNOW.overlay = true;
32
+ RPXNOW.language_preference = '#{options[:language]||'en'}';
33
+ //]]>
34
+ </script>
35
+ EOF
36
+ end
37
+
38
+ private
39
+
40
+ def read_user_data_from_response(response)
41
+ user_data = response['profile']
42
+ data = {}
43
+ data[:identifier] = user_data['identifier']
44
+ data[:email] = user_data['verifiedEmail'] || user_data['email']
45
+ data[:name] = user_data['displayName'] || user_data['preferredUsername'] || data[:email].sub(/@.*/,'')
46
+ data
47
+ end
48
+
49
+ def post(url,data)
50
+ require 'net/http'
51
+ url = URI.parse(url)
52
+ http = Net::HTTP.new(url.host, url.port)
53
+ if url.scheme == 'https'
54
+ require 'net/https'
55
+ http.use_ssl = true
56
+ end
57
+ resp, data = http.post(url.path, data.to_query)
58
+ raise "POST FAILED:"+resp.inspect unless resp.is_a? Net::HTTPOK
59
+ return data
60
+ end
61
+ end
data/rpx_now.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rpx_now}
5
+ s.version = "0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Michael Grosser"]
9
+ s.date = %q{2009-01-24}
10
+ s.description = %q{Helper to simplify RPX Now user login/creation}
11
+ s.email = %q{grosser.michael@gmail.com}
12
+ s.extra_rdoc_files = ["lib/rpx_now.rb", "README.markdown"]
13
+ s.files = ["Manifest", "lib/rpx_now.rb", "init.rb", "Rakefile", "README.markdown", "rpx_now.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/grosser/rpx_now}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rpx_now", "--main", "README.markdown"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{rpx_now}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Helper to simplify RPX Now user login/creation}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
28
+ s.add_development_dependency(%q<echoe>, [">= 0"])
29
+ else
30
+ s.add_dependency(%q<activesupport>, [">= 0"])
31
+ s.add_dependency(%q<echoe>, [">= 0"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<activesupport>, [">= 0"])
35
+ s.add_dependency(%q<echoe>, [">= 0"])
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grosser-rpx_now
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.2"
5
+ platform: ruby
6
+ authors:
7
+ - Michael Grosser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-24 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: echoe
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ description: Helper to simplify RPX Now user login/creation
34
+ email: grosser.michael@gmail.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - lib/rpx_now.rb
41
+ - README.markdown
42
+ files:
43
+ - Manifest
44
+ - lib/rpx_now.rb
45
+ - init.rb
46
+ - Rakefile
47
+ - README.markdown
48
+ - rpx_now.gemspec
49
+ has_rdoc: true
50
+ homepage: http://github.com/grosser/rpx_now
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --line-numbers
54
+ - --inline-source
55
+ - --title
56
+ - Rpx_now
57
+ - --main
58
+ - README.markdown
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "1.2"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project: rpx_now
76
+ rubygems_version: 1.2.0
77
+ signing_key:
78
+ specification_version: 2
79
+ summary: Helper to simplify RPX Now user login/creation
80
+ test_files: []
81
+