omniauth-campus 0.5.8 → 0.5.9
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9f430848d7a3c9fb3b749f702dfa72f6835d13c
|
4
|
+
data.tar.gz: ef1b240908d2aa9c677fd297006d52836f7dbd9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57aa1b0fa61831d63046ec0a9edadb633f83326f7a4761ae4d296f2a5d3b43a3a1a9948fb69954abd1ca1ff77463d6edd9c0a108ff2d1b28feb583f4ab6a0a1c
|
7
|
+
data.tar.gz: 9f4edf8b516030280fb7adcd8ad6bf77a39eb004c5dbc53a11921bb7ae474752d11e166ad6416556dcd69852219235b293a3ce98d0772e97f12ebfe85b3e162b
|
Binary file
|
Binary file
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "omniauth
|
1
|
+
require "omniauth"
|
2
2
|
require 'multi_json'
|
3
3
|
require 'faraday'
|
4
4
|
require 'net/http'
|
@@ -12,20 +12,17 @@ require 'uri'
|
|
12
12
|
module OmniAuth
|
13
13
|
module Strategies
|
14
14
|
# Your code goes here...
|
15
|
-
class Campus
|
15
|
+
class Campus
|
16
|
+
include OmniAuth::Strategy
|
16
17
|
|
17
|
-
|
18
|
-
DEFAULT_GRANT = 'authorization_code'
|
19
|
-
|
20
|
-
option :name, 'campus'
|
21
|
-
args [:client_id, :client_secret]
|
18
|
+
args [:client_id, :client_secret, :endpoint]
|
22
19
|
#option :consumer_key, "YzjVHuk8xoXCTcNwYg57yiCW5w59tucC"
|
23
20
|
#option :consumer_secret, "ZDrWuDsunNkRroU5psb6QyMmT86XkYST"
|
24
21
|
option :client_options, {
|
25
|
-
|
26
|
-
|
22
|
+
client_id: nil,
|
23
|
+
client_secret: nil,
|
27
24
|
#request_token_path: '/oauth/request_token',
|
28
|
-
|
25
|
+
endpoint: 'https://community3dev.devcloud.acquia-sites.com/api'
|
29
26
|
}
|
30
27
|
|
31
28
|
option :fields, [:name, :email]
|
@@ -41,25 +38,20 @@ module OmniAuth
|
|
41
38
|
# }
|
42
39
|
#
|
43
40
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
def request_phase
|
42
|
+
form = OmniAuth::Form.new(:title => "User Info", :url => callback_path)
|
43
|
+
options.fields.each do |field|
|
44
|
+
form.text_field field.to_s.capitalize.gsub("_", " "), field.to_s
|
48
45
|
end
|
49
|
-
|
50
|
-
|
51
|
-
def token_params
|
52
|
-
super.tap do |params|
|
53
|
-
params[:grant_type] ||= DEFAULT_GRANT
|
54
|
-
params[:client_id] = client.id
|
55
|
-
params[:client_secret] = client.secret
|
46
|
+
form.button "Sign In"
|
47
|
+
form.to_response
|
56
48
|
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def request_phase
|
60
|
-
redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(options.authorize_params))
|
61
|
-
end
|
62
49
|
|
50
|
+
def callback_phase
|
51
|
+
return fail!(:invalid_credentials) if !authentication_response
|
52
|
+
return fail!(:invalid_credentials) if authentication_response.code.to_i >= 400
|
53
|
+
super
|
54
|
+
end
|
63
55
|
|
64
56
|
|
65
57
|
uid {raw_info['uid']}
|
@@ -71,7 +63,38 @@ end
|
|
71
63
|
end
|
72
64
|
|
73
65
|
def raw_info
|
74
|
-
@raw_info ||= MultiJson.decode(access_token.get(
|
66
|
+
@raw_info ||= MultiJson.decode(access_token.get(@authentication_response).body )
|
67
|
+
end
|
68
|
+
|
69
|
+
def api_uri
|
70
|
+
options.endpoint
|
71
|
+
end
|
72
|
+
|
73
|
+
def name
|
74
|
+
request['name']
|
75
|
+
end
|
76
|
+
|
77
|
+
def email
|
78
|
+
request['email']
|
79
|
+
end
|
80
|
+
|
81
|
+
def authentication_response
|
82
|
+
unless @authentication_response
|
83
|
+
return unless name && email
|
84
|
+
|
85
|
+
uri = URI(api_uri)
|
86
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
87
|
+
if uri.scheme == 'https'
|
88
|
+
http.use_ssl = true
|
89
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
90
|
+
end
|
91
|
+
|
92
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
93
|
+
req.basic_auth name, email
|
94
|
+
@authentication_response = http.request(req)
|
95
|
+
end
|
96
|
+
|
97
|
+
@authentication_response
|
75
98
|
end
|
76
99
|
|
77
100
|
end
|