omniauth-iauth 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f66efd0ee82f2e6e368685677e8695e3be1e233b
4
+ data.tar.gz: ef0a33f1c97b313c8f3aa12a65645f308d6705e4
5
+ SHA512:
6
+ metadata.gz: 09a1ed5644972fbfd66ba98195d6caff28569ddce87787e4d9fc38e34c00f1d6eab6af8eaca3f47c1865270fa46fd89c1a57ff1c20234077fa7c44b09965ae84
7
+ data.tar.gz: 6efec9ffa2e83ca0d40bdcc58795e372b44642396820b144b6594e47e5baa66a1d8807b25276a21e0dd66dacb46395d3e45bb9445a9d8096c2850ffd4ca5d299
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ gemspec
4
+
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-iauth (1.0.0)
5
+ iauth
6
+ omniauth
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.0)
12
+ hashie (3.3.1)
13
+ httparty (0.13.3)
14
+ json (~> 1.8)
15
+ multi_xml (>= 0.5.2)
16
+ iauth (1.0.1)
17
+ httparty
18
+ json (1.8.1)
19
+ method_source (0.8.2)
20
+ multi_xml (0.5.5)
21
+ omniauth (1.2.2)
22
+ hashie (>= 1.2, < 4)
23
+ rack (~> 1.0)
24
+ pry (0.10.1)
25
+ coderay (~> 1.1.0)
26
+ method_source (~> 0.8.1)
27
+ slop (~> 3.4)
28
+ rack (1.5.2)
29
+ rake (10.3.2)
30
+ slop (3.6.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ omniauth-iauth!
37
+ pry
38
+ rake
@@ -0,0 +1,3 @@
1
+ require "omniauth-iauth/version"
2
+ require 'omniauth/strategies/iauth'
3
+
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module IAuth
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,87 @@
1
+ require 'securerandom'
2
+ require 'omniauth'
3
+ require 'iauth'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class IAuth
8
+ include OmniAuth::Strategy
9
+
10
+ args [:app_id, :app_secret]
11
+
12
+ option :app_id, nil
13
+ option :app_secret, nil
14
+ option :authorize_params, {}
15
+ option :uid, nil
16
+ option :access_token, nil
17
+ option :access_secret, nil
18
+
19
+ attr_reader :access_token
20
+
21
+ def request_phase
22
+ state = options.authorize_params[:state] = SecureRandom.hex(8)
23
+ session['omniauth.state'] = state
24
+ redirect "http://i.buaa.edu.cn/plugin/iauth/login.php?appid=#{options.app_id}&state=#{state}"
25
+ end
26
+
27
+ def callback_phase
28
+ operate = request.params['operate']
29
+ verifier = request.params['verifier']
30
+ state = request.params['state']
31
+ fail!(:invalid_request, CallbackError.new(:invalid_request)) unless state == session['omniauth.state']
32
+ iauth = ::IAuth.new options.app_id, options.app_secret
33
+ if operate == 'login'
34
+ c = iauth.login verifier, state
35
+ elsif operate == 'auth'
36
+ c = iauth.auth verifier, state
37
+ else
38
+ fail!(:invalid_request, CallbackError.new(:invalid_request))
39
+ end
40
+ options.uid = c['uid']
41
+ options.access_token = c['access_token']
42
+ options.access_secret = c['access_secret']
43
+ super
44
+ rescue ::Timeout::Error => e
45
+ fail!(:timeout, e)
46
+ rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
47
+ fail!(:service_unavailable, e)
48
+ rescue ::MultiJson::DecodeError => e
49
+ fail!(:invalid_response, e)
50
+ rescue ::OmniAuth::NoSessionError => e
51
+ fail!(:session_expired, e)
52
+ end
53
+
54
+ uid do
55
+ options.uid
56
+ end
57
+
58
+ # info do
59
+ # end
60
+
61
+ credentials do
62
+ c = { 'access_token' => options.access_token }
63
+ c['access_secret'] = options.access_secret unless options.access_secret.nil?
64
+ c
65
+ end
66
+
67
+ # extra do
68
+ # end
69
+
70
+ class CallbackError < StandardError
71
+ attr_accessor :error, :error_reason, :error_uri
72
+
73
+ def initialize(error, error_reason = nil, error_uri = nil)
74
+ self.error = error
75
+ self.error_reason = error_reason
76
+ self.error_uri = error_uri
77
+ end
78
+
79
+ def message
80
+ [error, error_reason, error_uri].compact.join(' | ')
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ OmniAuth.config.add_camelization 'iauth', 'IAuth'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-iauth/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Eric Zhang"]
6
+ gem.email = ["i@qinix.com"]
7
+ gem.description = %q{A generic IAuth (1.0/1.0a) strategy for OmniAuth.}
8
+ gem.summary = %q{A generic IAuth (1.0/1.0a) strategy for OmniAuth.}
9
+ gem.homepage = "https://github.com/qinix/omniauth-iauth"
10
+
11
+ gem.add_runtime_dependency 'omniauth'
12
+ gem.add_runtime_dependency 'iauth'
13
+ gem.add_development_dependency 'rake'
14
+ gem.add_development_dependency 'pry'
15
+
16
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ gem.files = `git ls-files`.split("\n")
18
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ gem.name = "omniauth-iauth"
20
+ gem.require_paths = ["lib"]
21
+ gem.version = OmniAuth::IAuth::VERSION
22
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-iauth
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Zhang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: iauth
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A generic IAuth (1.0/1.0a) strategy for OmniAuth.
70
+ email:
71
+ - i@qinix.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - lib/omniauth-iauth.rb
79
+ - lib/omniauth-iauth/version.rb
80
+ - lib/omniauth/strategies/iauth.rb
81
+ - omniauth-iauth.gemspec
82
+ homepage: https://github.com/qinix/omniauth-iauth
83
+ licenses: []
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.4.3
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: A generic IAuth (1.0/1.0a) strategy for OmniAuth.
105
+ test_files: []