# File lib/rack/oauth2/client.rb, line 8 def initialize(attributes = {}) (required_attributes + optional_attributes).each do |key| self.send :"#{key}=", attributes[key] end @grant = Grant::ClientCredentials.new @authorization_endpoint ||= '/oauth2/authorize' @token_endpoint ||= '/oauth2/token' attr_missing! end
# File lib/rack/oauth2/client.rb, line 67 def access_token!(*args) headers, params = {}, @grant.as_json # NOTE: # Using Array#estract_options! for backward compatibility. # Until v1.0.5, the first argument was 'client_auth_method' in scalar. options = args.extract_options! client_auth_method = args.first || options.delete(:client_auth_method) || :basic params[:scope] = Array(options.delete(:scope)).join(' ') if options[:scope].present? params.merge! options if secret if client_auth_method == :basic cred = ["#{identifier}:#{secret}"].pack('m').tr("\n", '') headers.merge!( 'Authorization' => "Basic #{cred}" ) else params.merge!( client_id: identifier, client_secret: secret ) end end handle_response do Rack::OAuth2.http_client.post( absolute_uri_for(token_endpoint), Util.compact_hash(params), headers ) end end
# File lib/rack/oauth2/client.rb, line 48 def jwt_bearer=(assertion) @grant = Grant::JWTBearer.new( assertion: assertion ) end
# File lib/rack/oauth2/client.rb, line 42 def refresh_token=(token) @grant = Grant::RefreshToken.new( refresh_token: token ) end
# File lib/rack/oauth2/client.rb, line 35 def resource_owner_credentials=(credentials) @grant = Grant::Password.new( username: credentials.first, password: credentials.last ) end
# File lib/rack/oauth2/client.rb, line 54 def saml2_bearer=(assertion) @grant = Grant::SAML2Bearer.new( assertion: assertion ) end
# File lib/rack/oauth2/client.rb, line 60 def subject_token=(subject_token, subject_token_type = URN::TokenType::JWT) @grant = Grant::TokenExchange.new( subject_token: subject_token, subject_token_type: subject_token_type ) end