@@ -28,23 +28,22 @@ class ChefServerSlice::OpenidConsumer < ChefServerSlice::Application
2828 def index
2929 if request . xhr?
3030 render :layout => false
31- else
31+ else
3232 render
3333 end
3434 end
35-
35+
3636 def start
3737 oid = params [ :openid_identifier ]
3838 providers = Chef ::Config [ :openid_providers ]
39- raise ( Unauthorized , "Sorry, #{ openid } is not an authorized OpenID." ) unless is_authorized_openid_identifier? ( oid , providers )
40- raise ( Unauthorized , "Sorry, #{ openid } is not an allowed OpenID Provider." ) unless is_valid_openid_provider? ( oid , providers )
41-
39+ raise ( Unauthorized , "Sorry, #{ oid } is not an allowed OpenID Provider." ) unless is_valid_openid_provider? ( oid , providers )
40+
4241 begin
4342 oidreq = consumer . begin ( oid )
4443 rescue OpenID ::OpenIDError => e
4544 raise BadRequest , "Discovery failed for #{ params [ :openid_identifier ] } : #{ e } "
4645 end
47-
46+
4847 return_to = absolute_slice_url ( :openid_consumer_complete )
4948 realm = absolute_slice_url ( :openid_consumer )
5049
@@ -57,9 +56,12 @@ def start
5756 end
5857
5958 def login
59+ oid = params [ :openid_identifier ]
60+ authorized_openids = Chef ::Config [ :authorized_openid_identifiers ]
61+ raise ( Unauthorized , "Sorry, #{ oid } is not an authorized OpenID." ) unless is_authorized_openid_identifier? ( oid , authorized_openids )
6062 start
6163 end
62-
64+
6365 def complete
6466 # FIXME - url_for some action is not necessarily the current URL.
6567 current_url = absolute_slice_url ( :openid_consumer_complete )
@@ -96,17 +98,17 @@ def logout
9698 end
9799
98100 private
99- #
100- #
101-
101+ #
102+ #
103+
102104 # Returns true if the openid is at a valid provider, based on whether :openid_providers is
103105 # defined. Raises an exception if it is not an allowed provider.
104106 def is_valid_openid_provider? ( openid , providers )
105107 ( providers && providers . detect { |p | openid =~ /^https?:\/ \/ #{ p } / or openid =~ /^#{ p } / } ) || true
106108 end
107109
108- def is_authorized_openid_identifier? ( openid , providers )
109- ( providers && providers . detect { |p | openid ==p } ) || true
110+ def is_authorized_openid_identifier? ( openid , authorized_openids )
111+ ( authorized_openids && authorized_openids . detect { |p | openid ==p } )
110112 end
111113
112114 def consumer
@@ -117,5 +119,5 @@ def consumer
117119 OpenID ::Store ::Filesystem . new ( Chef ::Config [ :openid_cstore_path ] )
118120 end )
119121 end
120-
122+
121123end
0 commit comments