loginza 0.2.0
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +74 -0
- data/Rakefile +45 -0
- data/lib/loginza.rb +30 -0
- data/lib/loginza/api.rb +68 -0
- data/lib/loginza/railtie.rb +21 -0
- data/lib/loginza/utils.rb +41 -0
- data/lib/loginza/version.rb +12 -0
- data/lib/loginza/view_helper.rb +72 -0
- data/rails/init.rb +2 -0
- metadata +89 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 [name of plugin creator]
|
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,74 @@
|
|
1
|
+
= Loginza
|
2
|
+
|
3
|
+
Loginza - is interactive JavaScript widget provides visitors to your sites,
|
4
|
+
a wide range of options for authentication through the accounts of common WEB-portals and
|
5
|
+
service (Yandex, Google, and TA. See full list {providers}[http://loginza.ru/features-and-benefits]).
|
6
|
+
Easy to learn {Loginza.API}[http://loginza.ru/api-overview].
|
7
|
+
|
8
|
+
== Install
|
9
|
+
|
10
|
+
Via rails plugin:
|
11
|
+
|
12
|
+
Rails 3:
|
13
|
+
|
14
|
+
gem 'loginza'
|
15
|
+
|
16
|
+
Rails 2:
|
17
|
+
|
18
|
+
./script/plugin install git://github.com/galetahub/loginza.git
|
19
|
+
|
20
|
+
Via rails gem:
|
21
|
+
|
22
|
+
sudo gem install loginza
|
23
|
+
|
24
|
+
== Usage
|
25
|
+
|
26
|
+
=== View
|
27
|
+
|
28
|
+
==== Link
|
29
|
+
|
30
|
+
Simple example:
|
31
|
+
|
32
|
+
<%= loginza_button_tag("Login via OpenID", clients_url) %>
|
33
|
+
|
34
|
+
With set of providers:
|
35
|
+
|
36
|
+
<%= loginza_button_tag("Login via OpenID", clients_url, :providers => [ :google, :facebook, :twitter ]) %>
|
37
|
+
|
38
|
+
With default provider:
|
39
|
+
|
40
|
+
<%= loginza_button_tag("Login via OpenID", clients_url, :provider => :google) %>
|
41
|
+
|
42
|
+
With a block:
|
43
|
+
|
44
|
+
<%= loginza_button_tag(clients_url, :provider => :google) do %>
|
45
|
+
<div class='loginza'>
|
46
|
+
<img src="http://loginza.ru/img/providers/google.png" alt="Google" title="Google Accounts">
|
47
|
+
<img src="http://loginza.ru/img/providers/twitter.png" alt="Twitter" title="Twitter">
|
48
|
+
<img src="http://loginza.ru/img/providers/yandex.png" alt="Yandex" title="Yandex">
|
49
|
+
<img src="http://loginza.ru/img/providers/myopenid.png" alt="MyOpenID" title="MyOpenID">
|
50
|
+
<img src="http://loginza.ru/img/providers/openid.png" alt="OpenID" title="OpenID">
|
51
|
+
</div>
|
52
|
+
<% end %>
|
53
|
+
|
54
|
+
==== Frame
|
55
|
+
|
56
|
+
<%= loginza_frame_tag(clients_url, { :providers => [:google, :yandex, :mailru] }, { :style => "width:400px;height:350px;" }) %>
|
57
|
+
|
58
|
+
|
59
|
+
=== Controller
|
60
|
+
|
61
|
+
class ClientsController < ApplicationController
|
62
|
+
|
63
|
+
def create
|
64
|
+
if data = Loginza.user_data(params[:token])
|
65
|
+
client = Client.find_or_create(data)
|
66
|
+
redirect_to root_path
|
67
|
+
else
|
68
|
+
redirect_to login_path
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
Copyright (c) 2011 Aimbulance, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require File.join(File.dirname(__FILE__), 'lib', 'loginza', 'version')
|
5
|
+
|
6
|
+
desc 'Default: run unit tests.'
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
desc 'Test the loginza plugin.'
|
10
|
+
Rake::TestTask.new(:test) do |t|
|
11
|
+
t.libs << 'lib'
|
12
|
+
t.libs << 'test'
|
13
|
+
t.pattern = 'test/**/*_test.rb'
|
14
|
+
t.verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Generate documentation for the loginza plugin.'
|
18
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
19
|
+
rdoc.rdoc_dir = 'rdoc'
|
20
|
+
rdoc.title = 'Loginza'
|
21
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
22
|
+
rdoc.rdoc_files.include('README')
|
23
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'jeweler'
|
28
|
+
Jeweler::Tasks.new do |gemspec|
|
29
|
+
gemspec.name = "loginza"
|
30
|
+
gemspec.version = Loginza::Version.dup
|
31
|
+
gemspec.summary = "Rails plugin for openID authentication by service Loginza.API"
|
32
|
+
gemspec.description = "Loginza - an interactive JavaScript widget provides visitors to your sites, a wide range of options for authentication through the accounts of common WEB-portals and services"
|
33
|
+
gemspec.email = "galeta.igor@gmail.com"
|
34
|
+
gemspec.homepage = "http://loginza.ru/"
|
35
|
+
gemspec.authors = ["Igor Galeta"]
|
36
|
+
gemspec.files = FileList["[A-Z]*", "{lib,rails}/**/*"]
|
37
|
+
gemspec.rubyforge_project = "loginza"
|
38
|
+
|
39
|
+
gemspec.add_dependency('json')
|
40
|
+
end
|
41
|
+
|
42
|
+
Jeweler::GemcutterTasks.new
|
43
|
+
rescue LoadError
|
44
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
45
|
+
end
|
data/lib/loginza.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'loginza/railtie'
|
3
|
+
|
4
|
+
module Loginza
|
5
|
+
autoload :ViewHelper, 'loginza/view_helper'
|
6
|
+
autoload :Api, 'loginza/api'
|
7
|
+
autoload :Utils, 'loginza/utils'
|
8
|
+
autoload :Version, 'loginza/version'
|
9
|
+
|
10
|
+
def self.user_data(token, options = {})
|
11
|
+
options = options.dup
|
12
|
+
|
13
|
+
data = begin
|
14
|
+
auth_info(token, options)
|
15
|
+
rescue ServerError
|
16
|
+
return nil if $!.to_s=~/Data not found/
|
17
|
+
raise
|
18
|
+
end
|
19
|
+
|
20
|
+
block_given? ? yield(data) : data
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.auth_info(token, options = {})
|
24
|
+
Api.call('authinfo', options.merge(:token => token))
|
25
|
+
end
|
26
|
+
|
27
|
+
class ServerError < RuntimeError; end
|
28
|
+
class ApiError < ServerError; end
|
29
|
+
class ServiceUnavailableError < ServerError; end
|
30
|
+
end
|
data/lib/loginza/api.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
|
5
|
+
module Loginza
|
6
|
+
module Api
|
7
|
+
class << self
|
8
|
+
|
9
|
+
BASE_URL = "http://loginza.ru/api/"
|
10
|
+
|
11
|
+
def call(method, data, cookies = {})
|
12
|
+
options = {
|
13
|
+
:timestamp => Time.now.to_i
|
14
|
+
}.merge(data)
|
15
|
+
|
16
|
+
response = request(File.join(uri.path, method), options)
|
17
|
+
parse_response(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def uri
|
21
|
+
@@uri ||= URI.parse(BASE_URL)
|
22
|
+
@@uri
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def request(path, data)
|
28
|
+
client.request(request_object(path, data))
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_object(path, data)
|
32
|
+
request = Net::HTTP::Post.new("#{path}?token=#{data.delete(:token)}")
|
33
|
+
request.form_data = stringify_keys(data)
|
34
|
+
request
|
35
|
+
end
|
36
|
+
|
37
|
+
# symbol keys -> string keys
|
38
|
+
# because of ruby 1.9.x bug in Net::HTTP
|
39
|
+
# http://redmine.ruby-lang.org/issues/show/1351
|
40
|
+
def stringify_keys(hash)
|
41
|
+
hash.map{|k,v| [k.to_s,v]}
|
42
|
+
end
|
43
|
+
|
44
|
+
def client
|
45
|
+
client = Net::HTTP.new(uri.host, uri.port)
|
46
|
+
client
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse_response(response)
|
50
|
+
if response.code.to_i >= 400
|
51
|
+
raise ServiceUnavailableError, "The Loginza service is temporarily unavailable. (4XX)"
|
52
|
+
else
|
53
|
+
begin
|
54
|
+
result = Utils.parse_json(response.body)
|
55
|
+
rescue Exception => e
|
56
|
+
::Rails.logger.info("Error parse: #{response.body}")
|
57
|
+
::Rails.logger.error(e)
|
58
|
+
return
|
59
|
+
end
|
60
|
+
|
61
|
+
return result unless result['error_type']
|
62
|
+
|
63
|
+
raise ApiError, "Got error: #{result['error_message']} (error_type: #{result['error_type']}), HTTP status: #{response.code}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'loginza'
|
3
|
+
|
4
|
+
module Loginza
|
5
|
+
if defined? Rails::Railtie
|
6
|
+
require 'rails'
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
initializer 'loginza.insert_into_action_view' do
|
9
|
+
Loginza::Railtie.insert
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Railtie
|
15
|
+
def self.insert
|
16
|
+
ActionView::Base.send(:include, Loginza::ViewHelper)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Loginza
|
5
|
+
module Utils
|
6
|
+
def self.turn_into_json(data)
|
7
|
+
JSON.generate(data)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.parse_json(data)
|
11
|
+
JSON.parse(data)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.parse_query(value, spliter = '&')
|
15
|
+
Rack::Utils.parse_query(value, spliter).inject({}) {|h,(k,v)|
|
16
|
+
h[k] = Array === v ? v.first : v
|
17
|
+
h
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.new_safe_buffer
|
22
|
+
if Object.const_defined?('ActiveSupport')
|
23
|
+
ActiveSupport::SafeBuffer.new
|
24
|
+
else
|
25
|
+
String.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.generate_url(callback_url, options = {}, params = {})
|
30
|
+
params[:token_url] = callback_url
|
31
|
+
params[:lang] ||= ::I18n.locale.to_s
|
32
|
+
|
33
|
+
providers = options[:providers] ? options.delete(:providers).map(&:to_s).join(',') : options.delete(:provider)
|
34
|
+
|
35
|
+
query = ::Rack::Utils.build_query(params)
|
36
|
+
query += "&providers_set=#{providers}"
|
37
|
+
|
38
|
+
"https://loginza.ru/api/widget?#{query}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Loginza
|
3
|
+
module ViewHelper
|
4
|
+
include ActionView::Helpers::AssetTagHelper
|
5
|
+
include ActionView::Helpers::TagHelper
|
6
|
+
include ActionView::Helpers::UrlHelper
|
7
|
+
|
8
|
+
# Loginza button
|
9
|
+
#
|
10
|
+
# Simple example:
|
11
|
+
# <%= loginza_button_tag("Login via OpenID", clients_url) %>
|
12
|
+
#
|
13
|
+
# With set of providers:
|
14
|
+
# <%= loginza_button_tag("Login via OpenID", clients_url, :providers => [ :google, :facebook, :twitter ]) %>
|
15
|
+
#
|
16
|
+
# With default provider:
|
17
|
+
# <%= loginza_button_tag("Login via OpenID", clients_url, :provider => :google) %>
|
18
|
+
#
|
19
|
+
# With a block:
|
20
|
+
# <%= loginza_button_tag(clients_url, :provider => :google) do %>
|
21
|
+
# <div class='loginza'>
|
22
|
+
# ...
|
23
|
+
# </div>
|
24
|
+
# <% end %>
|
25
|
+
#
|
26
|
+
# Supported providers:
|
27
|
+
# google, yandex, mailruapi, mailru, vkontakte, facebook, twitter, loginza, myopenid, webmoney, rambler, flickr, lastfm, verisign, aol, steam, openid.
|
28
|
+
#
|
29
|
+
def loginza_button_tag(*args, &block)
|
30
|
+
if block_given?
|
31
|
+
callback_url = args.first
|
32
|
+
options = args.second || {}
|
33
|
+
html_options = args.third
|
34
|
+
|
35
|
+
loginza_button_tag(capture(&block), callback_url, options, html_options)
|
36
|
+
else
|
37
|
+
name = args[0]
|
38
|
+
callback_url = args[1]
|
39
|
+
options = args[2] || {}
|
40
|
+
html_options = args[3] || {}
|
41
|
+
|
42
|
+
html_options[:class] ||= "loginza"
|
43
|
+
without_js = options.delete(:without_js)
|
44
|
+
|
45
|
+
url = Utils.generate_url(callback_url, options)
|
46
|
+
|
47
|
+
html = Utils.new_safe_buffer
|
48
|
+
html << javascript_include_tag("http://s1.loginza.ru/js/widget.js") unless without_js
|
49
|
+
html << link_to(name, url, options, html_options)
|
50
|
+
html
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Loginza frame
|
55
|
+
#
|
56
|
+
# Simple example:
|
57
|
+
#
|
58
|
+
# <%= loginza_frame_tag(clients_url, { :providers => [:google, :yandex, :mailru] }, { :style => "width:400px;height:350px;" }) %>
|
59
|
+
#
|
60
|
+
def loginza_frame_tag(callback_url, options = {}, html_options = {})
|
61
|
+
html_options = {
|
62
|
+
:scrolling => "no",
|
63
|
+
:frameborder => "no",
|
64
|
+
:style => "width:359px;height:300px;",
|
65
|
+
}.merge(html_options)
|
66
|
+
|
67
|
+
html_options[:src] = Utils.generate_url(callback_url, options, { :overlay => 'loginza' })
|
68
|
+
|
69
|
+
content_tag(:iframe, nil, html_options)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/rails/init.rb
ADDED
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: loginza
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Igor Galeta
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-14 00:00:00 +03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Loginza - an interactive JavaScript widget provides visitors to your sites, a wide range of options for authentication through the accounts of common WEB-portals and services
|
36
|
+
email: galeta.igor@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.rdoc
|
43
|
+
files:
|
44
|
+
- MIT-LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
- Rakefile
|
47
|
+
- lib/loginza.rb
|
48
|
+
- lib/loginza/api.rb
|
49
|
+
- lib/loginza/railtie.rb
|
50
|
+
- lib/loginza/utils.rb
|
51
|
+
- lib/loginza/version.rb
|
52
|
+
- lib/loginza/view_helper.rb
|
53
|
+
- rails/init.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://loginza.ru/
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
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
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project: loginza
|
84
|
+
rubygems_version: 1.6.2
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Rails plugin for openID authentication by service Loginza.API
|
88
|
+
test_files: []
|
89
|
+
|