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: 67627e723de80738c791907eeb6d7b3569e1fe2c
4
- data.tar.gz: 597401fd1122f2ba52a89a98bc87d3fd477f49df
3
+ metadata.gz: a9f430848d7a3c9fb3b749f702dfa72f6835d13c
4
+ data.tar.gz: ef1b240908d2aa9c677fd297006d52836f7dbd9e
5
5
  SHA512:
6
- metadata.gz: 993538711c5b393162aa122ebde78566cf712f01d868a857b7cb467bbafb3d7904aaeb3fc746a542682d626810cdb75e682171b520faee56601bb6fea61d1afd
7
- data.tar.gz: 6ab62ed7eb38e31e5cc957238c1a84d2b099a104275ebaa3df7928dd3dbde5c67f82f0be98cac8ed58fcf1fee90f08a139e76a8ab48f4547c41183b83f0fd59d
6
+ metadata.gz: 57aa1b0fa61831d63046ec0a9edadb633f83326f7a4761ae4d296f2a5d3b43a3a1a9948fb69954abd1ca1ff77463d6edd9c0a108ff2d1b28feb583f4ab6a0a1c
7
+ data.tar.gz: 9f4edf8b516030280fb7adcd8ad6bf77a39eb004c5dbc53a11921bb7ae474752d11e166ad6416556dcd69852219235b293a3ce98d0772e97f12ebfe85b3e162b
Binary file
@@ -1,6 +1,6 @@
1
1
  module Omniauth
2
2
  module Campus
3
- VERSION = "0.5.8"
3
+ VERSION = "0.5.9"
4
4
  end
5
5
  end
6
6
 
Binary file
@@ -1,4 +1,4 @@
1
- require "omniauth-oauth2"
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 < OmniAuth::Strategies::OAuth2
15
+ class Campus
16
+ include OmniAuth::Strategy
16
17
 
17
- DEFAULT_RESPONSE_TYPE = 'code'
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
- token_url: '/oauth/access_token',
26
- authorize_url: '/oauth/authorize',
22
+ client_id: nil,
23
+ client_secret: nil,
27
24
  #request_token_path: '/oauth/request_token',
28
- site: 'http://community3dev.devcloud.acquia-sites.com/api'
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 authorize_params
45
- super.tap do |params|
46
- params[:response_type] ||= DEFAULT_RESPONSE_TYPE
47
- params[:client_id] = client.id
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
- end
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('/me').body )
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-campus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: 0.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - johnvehr