Class: OmniAuth::Strategies::Cloudfoundry
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::Cloudfoundry
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/cloudfoundry.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#auth_server_url ⇒ Object
readonly
Returns the value of attribute auth_server_url.
-
#token_issuer ⇒ Object
readonly
Returns the value of attribute token_issuer.
-
#token_server_url ⇒ Object
readonly
Returns the value of attribute token_server_url.
Instance Method Summary collapse
- #authorize_params ⇒ Object
- #build_access_token(query_string) ⇒ Object
- #callback_phase ⇒ Object
- #callback_url ⇒ Object
- #client ⇒ Object
- #expired?(access_token) ⇒ Boolean
- #prune!(hash) ⇒ Object
- #raw_info ⇒ Object
- #refresh(access_token) ⇒ Object
- #request_phase ⇒ Object
- #token_params ⇒ Object
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
32 33 34 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 32 def access_token @access_token end |
#auth_server_url ⇒ Object (readonly)
Returns the value of attribute auth_server_url.
34 35 36 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 34 def auth_server_url @auth_server_url end |
#token_issuer ⇒ Object (readonly)
Returns the value of attribute token_issuer.
33 34 35 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 33 def token_issuer @token_issuer end |
#token_server_url ⇒ Object (readonly)
Returns the value of attribute token_server_url.
35 36 37 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 35 def token_server_url @token_server_url end |
Instance Method Details
#authorize_params ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 78 def params = ..merge(..inject({}){|h,k| h[k.to_sym] = [k] if [k]; h}) if OmniAuth.config.test_mode @env ||= {} @env['rack.session'] ||= {} end params end |
#build_access_token(query_string) ⇒ Object
136 137 138 139 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 136 def build_access_token(query_string) log :info, "Fetching access token" client.authcode_grant(session.delete('redir_uri'), query_string) end |
#callback_phase ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 91 def callback_phase log :info, "In callback phase #{request.query_string}" self.access_token = build_access_token(request.query_string) self.access_token = refresh(access_token) if expired?(access_token) log :info, "Got access token #{access_token.inspect}" super end |
#callback_url ⇒ Object
67 68 69 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 67 def callback_url full_host + script_name + callback_path end |
#client ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 38 def client unless @token_issuer unless @auth_server_url @auth_server_url ||= .auth_server_url unless @auth_server_url.start_with?("http") @auth_server_url = "https://#{@auth_server_url}" end end unless @token_server_url @token_server_url = .token_server_url || .auth_server_url unless @token_server_url.start_with?("http") @token_server_url = "https://#{@token_server_url}" end end @token_issuer ||= CF::UAA::TokenIssuer.new(@auth_server_url, .client_id, .client_secret, {:token_target => @token_server_url}) log :info, "Client: #{.client_id} auth_server: #{@auth_server_url} token_server: #{@token_server_url}" @token_issuer.logger = OmniAuth.logger end @token_issuer end |
#expired?(access_token) ⇒ Boolean
146 147 148 149 150 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 146 def expired?(access_token) access_token = access_token.auth_header if access_token.respond_to? :auth_header expiry = CF::UAA::TokenCoder.decode(access_token.split()[1], nil, nil, false)[:expires_at] expiry.is_a?(Integer) && expiry <= Time.now.to_i end |
#prune!(hash) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 129 def prune!(hash) hash.delete_if do |_, value| prune!(value) if value.is_a?(Hash) value.nil? || (value.respond_to?(:empty?) && value.empty?) end end |
#raw_info ⇒ Object
125 126 127 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 125 def raw_info @raw_info ||= CF::UAA::Misc.whoami(@token_server_url, self.access_token.auth_header) end |
#refresh(access_token) ⇒ Object
141 142 143 144 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 141 def refresh(access_token) log :info, "Refreshing access token" client.refresh_token_grant(access_token.info[:refresh_token]) end |
#request_phase ⇒ Object
71 72 73 74 75 76 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 71 def request_phase authcode_uri = client.authcode_uri(callback_url, .scope) log :info, "Redirect URI #{authcode_uri}" session['redir_uri'] = authcode_uri redirect authcode_uri end |
#token_params ⇒ Object
87 88 89 |
# File 'lib/omniauth/strategies/cloudfoundry.rb', line 87 def token_params .token_params.merge(..inject({}){|h,k| h[k.to_sym] = [k] if [k]; h}) end |