Class: OpenID::AX::FetchRequest

### Home Classes Methods

### In Files

- lib/openid/extensions/ax.rb

### Parent

OpenID::AX::AXMessage

### Methods

- ::from_openid_request
- ::new
- #add
- #attributes
- #get_extension_args
- #get_required_attrs
- #member?
- #parse_extension_args
- #requested_types

### Files

- LICENSE

### Class/Module Index

Quicksearch

- OpenID
- OpenID::AX
- OpenID::AX::AXMessage
- OpenID::AX::AttrInfo
- OpenID::AX::Error
- OpenID::AX::FetchRequest
- OpenID::AX::FetchResponse
- OpenID::AX::KeyValueMessage
- OpenID::AX::StoreRequest
- OpenID::AX::StoreResponse
- OpenID::AssertionError
- OpenID::Association
- OpenID::AssociationNegotiator
- OpenID::Consumer
- OpenID::Consumer::AssociationManager
- OpenID::Consumer::CancelResponse
- OpenID::Consumer::CheckIDRequest
- OpenID::Consumer::DiffieHellmanSHA1Session
- OpenID::Consumer::DiffieHellmanSHA256Session
- OpenID::Consumer::DiffieHellmanSession
- OpenID::Consumer::DiscoveredServices
- OpenID::Consumer::DiscoveryManager
- OpenID::Consumer::FailureResponse
- OpenID::Consumer::IdResHandler
- OpenID::Consumer::NoEncryptionSession
- OpenID::Consumer::Response
- OpenID::Consumer::Session
- OpenID::Consumer::SetupNeededResponse
- OpenID::Consumer::SuccessResponse
- OpenID::CryptUtil
- OpenID::DiffieHellman
- OpenID::DiscoveryFailure
- OpenID::Extension
- OpenID::FetchingError
- OpenID::HTTPRedirectLimitReached
- OpenID::HTTPResponse
- OpenID::HTTPStatusError
- OpenID::InvalidOpenIDNamespace
- OpenID::KVFormError
- OpenID::KVPostNetworkError
- OpenID::Message
- OpenID::Message::KeyNotFound
- OpenID::NamespaceAliasRegistrationError
- OpenID::NamespaceMap
- OpenID::Nonce
- OpenID::OAuth
- OpenID::OAuth::Request
- OpenID::OAuth::Response
- OpenID::OpenIDError
- OpenID::OpenIDServiceEndpoint
- OpenID::PAPE
- OpenID::PAPE::Request
- OpenID::PAPE::Response
- OpenID::ProtocolError
- OpenID::RealmVerificationRedirected
- OpenID::SReg
- OpenID::SReg::NamespaceError
- OpenID::SReg::Request
- OpenID::SReg::Response
- OpenID::SSLFetchingError
- OpenID::Server
- OpenID::Server::AlreadySigned
- OpenID::Server::AssociateRequest
- OpenID::Server::BaseServerSession
- OpenID::Server::CheckAuthRequest
- OpenID::Server::CheckIDRequest
- OpenID::Server::Decoder
- OpenID::Server::DiffieHellmanSHA1ServerSession
- OpenID::Server::DiffieHellmanSHA256ServerSession
- OpenID::Server::Encoder
- OpenID::Server::EncodingError
- OpenID::Server::MalformedReturnURL
- OpenID::Server::MalformedTrustRoot
- OpenID::Server::NoReturnToError
- OpenID::Server::OpenIDRequest
- OpenID::Server::OpenIDResponse
- OpenID::Server::PlainTextServerSession
- OpenID::Server::ProtocolError
- OpenID::Server::Server
- OpenID::Server::Signatory
- OpenID::Server::SigningEncoder
- OpenID::Server::UntrustedReturnURL
- OpenID::Server::VersionError
- OpenID::Server::WebResponse
- OpenID::ServerError
- OpenID::StandardFetcher
- OpenID::Store
- OpenID::Store::Filesystem
- OpenID::Store::Interface
- OpenID::Store::Memcache
- OpenID::Store::Memory
- OpenID::TrustRoot
- OpenID::TrustRoot::TrustRoot
- OpenID::TypeURIMismatch
- OpenID::UI
- OpenID::UI::Request
- OpenID::URINorm
- OpenID::UndefinedOpenIDNamespace
- OpenID::Util
- OpenID::Yadis
- OpenID::Yadis::BasicServiceEndpoint
- OpenID::Yadis::CompoundFilter
- OpenID::Yadis::DiscoveryResult
- OpenID::Yadis::TransformFilterMaker
- OpenID::Yadis::XRDSError
- OpenID::Yadis::XRDSFraud
- OpenID::Yadis::XRI
- OpenID::Yadis::XRI::ProxyResolver
- OpenID::Yadis::XRI::XRIHTTPError
- HMAC
- HMAC::Base
- HMAC::SHA1
- HMAC::SHA256
- HMAC::SHA384
- HMAC::SHA512
- Net
- Net::HTTP
- HTMLComment
- HTMLTag
- HTMLText
- HTMLToken
- HTMLTokenizer
- HTMLTokenizerError
- Object

No matching classes.

# OpenID::AX::FetchRequest

An attribute exchange 'fetch_request' message. This message is sent by a relying party when it wishes to obtain attributes about the subject of an OpenID authentication request.

### Constants

MODE

### Attributes

requested_attributes[R]
update_url[RW]

### Public Class Methods

from_openid_request(oidreq) click to toggle source

Extract a FetchRequest from an OpenID message message: OpenID::Message return a FetchRequest or nil if AX arguments are not present

    # File lib/openid/extensions/ax.rb, line 189
    def self.from_openid_request(oidreq)
      message = oidreq.message
      ax_args = message.get_args(NS_URI)
      return nil if ax_args == {} or ax_args['mode'] != MODE
      req = new
      req.parse_extension_args(ax_args)

      if req.update_url
        realm = message.get_arg(OPENID_NS, 'realm',
                                message.get_arg(OPENID_NS, 'return_to'))
        if realm.nil? or realm.empty?
          raise Error, "Cannot validate update_url #{req.update_url.inspect} against absent realm"
        end
        tr = TrustRoot::TrustRoot.parse(realm)
        unless tr.validate_url(req.update_url)
          raise Error, "Update URL #{req.update_url.inspect} failed validation against realm #{realm.inspect}"
        end
      end

      return req
    end

new(update_url = nil) click to toggle source

    # File lib/openid/extensions/ax.rb, line 123
    def initialize(update_url = nil)
      super()
      @mode = MODE
      @requested_attributes = {}
      @update_url = update_url
    end

### Public Instance Methods

add(attribute) click to toggle source

Add an attribute to this attribute exchange request. attribute: AttrInfo, the attribute being requested Raises IndexError if the requested attribute is already present

    in this request.

    # File lib/openid/extensions/ax.rb, line 134
    def add(attribute)
      if @requested_attributes[attribute.type_uri]
        raise IndexError, "The attribute #{attribute.type_uri} has already been requested"
      end
      @requested_attributes[attribute.type_uri] = attribute
    end

attributes() click to toggle source

return the list of AttrInfo objects contained in the FetchRequest

    # File lib/openid/extensions/ax.rb, line 255
    def attributes
      @requested_attributes.values
    end

get_extension_args() click to toggle source

Get the serialized form of this attribute fetch request. returns a hash of the arguments

    # File lib/openid/extensions/ax.rb, line 143
    def get_extension_args
      aliases = NamespaceMap.new
      required = []
      if_available = []
      ax_args = new_args
      @requested_attributes.each{|type_uri, attribute|
        if attribute.ns_alias
          name = aliases.add_alias(type_uri, attribute.ns_alias)
        else
          name = aliases.add(type_uri)
        end
        if attribute.required
          required << name
        else
          if_available << name
        end
        if attribute.count != 1
          ax_args["count.#{name}"] = attribute.count.to_s
        end
        ax_args["type.#{name}"] = type_uri
      }

      unless required.empty?
        ax_args['required'] = required.join(',')
      end
      unless if_available.empty?
        ax_args['if_available'] = if_available.join(',')
      end
      return ax_args
    end

get_required_attrs() click to toggle source

Get the type URIs for all attributes that have been marked as required.

    # File lib/openid/extensions/ax.rb, line 176
    def get_required_attrs
      @requested_attributes.inject([]) {|required, (type_uri, attribute)|
        if attribute.required
          required << type_uri
        else
          required
        end
      }
    end

member?(type_uri) click to toggle source

    # File lib/openid/extensions/ax.rb, line 264
    def member?(type_uri)
      ! @requested_attributes[type_uri].nil?
    end

parse_extension_args(ax_args) click to toggle source

    # File lib/openid/extensions/ax.rb, line 211
    def parse_extension_args(ax_args)
      check_mode(ax_args)

      aliases = NamespaceMap.new

      ax_args.each{|k,v|
        if k.index('type.') == 0
          name = k[5..-1]
          type_uri = v
          aliases.add_alias(type_uri, name)

          count_key = 'count.'+name
          count_s = ax_args[count_key]
          count = 1
          if count_s
            if count_s == UNLIMITED_VALUES
              count = count_s
            else
              count = count_s.to_i
              if count <= 0
                raise Error, "Invalid value for count #{count_key.inspect}: #{count_s.inspect}"
              end
            end
          end
          add(AttrInfo.new(type_uri, name, false, count))
        end
      }

      required = AX.to_type_uris(aliases, ax_args['required'])
      required.each{|type_uri|
        @requested_attributes[type_uri].required = true
      }
      if_available = AX.to_type_uris(aliases, ax_args['if_available'])
      all_type_uris = required + if_available

      aliases.namespace_uris.each{|type_uri|
        unless all_type_uris.member? type_uri
          raise Error, "Type URI #{type_uri.inspect} was in the request but not present in 'required' or 'if_available'"
        end
      }
      @update_url = ax_args['update_url']
    end

requested_types() click to toggle source

return the list of requested attribute type URIs

    # File lib/openid/extensions/ax.rb, line 260
    def requested_types
      @requested_attributes.keys
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.