Class: OpenID::SReg::Request

### Home Classes Methods

### In Files

- lib/openid/extensions/sreg.rb

### Parent

OpenID::Extension

### Methods

- ::from_openid_request
- ::new
- #all_requested_fields
- #get_extension_args
- #member?
- #parse_extension_args
- #request_field
- #request_fields
- #were_fields_requested?

### 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::SReg::Request

An object to hold the state of a simple registration request.

### Attributes

ns_uri[R]
optional[R]
policy_url[RW]
required[R]

### Public Class Methods

from_openid_request(request) click to toggle source

Create a simple registration request that contains the fields that were requested in the OpenID request with the given arguments Takes an OpenID::CheckIDRequest, returns an OpenID::Sreg::Request return nil if the extension was not requested.

    # File lib/openid/extensions/sreg.rb, line 101
    def self.from_openid_request(request)
      # Since we're going to mess with namespace URI mapping, don't
      # mutate the object that was passed in.
      message = request.message.copy
      ns_uri = OpenID::get_sreg_ns(message)
      args = message.get_args(ns_uri)
      return nil if args == {}
      req = new(nil,nil,nil,ns_uri)
      req.parse_extension_args(args)
      return req
    end

new(required = nil, optional = nil, policy_url = nil, ns_uri = NS_URI) click to toggle source

    # File lib/openid/extensions/sreg.rb, line 79
    def initialize(required = nil, optional = nil, policy_url = nil, ns_uri = NS_URI)
      super()

      @policy_url = policy_url
      @ns_uri = ns_uri
      @ns_alias = 'sreg'
      @required = []
      @optional = []

      if required
        request_fields(required, true, true)
      end
      if optional
        request_fields(optional, false, true)
      end
    end

### Public Instance Methods

all_requested_fields() click to toggle source

A list of all of the simple registration fields that were requested, whether they were required or optional.

    # File lib/openid/extensions/sreg.rb, line 153
    def all_requested_fields
      @required + @optional
    end

get_extension_args() click to toggle source

Get a hash of unqualified simple registration arguments representing this request. This method is essentially the inverse of parse_extension_args. This method serializes the simple registration request fields.

    # File lib/openid/extensions/sreg.rb, line 206
    def get_extension_args
      args = {}
      args['required'] = @required.join(',') unless @required.empty?
      args['optional'] = @optional.join(',') unless @optional.empty?
      args['policy_url'] = @policy_url unless @policy_url.nil?
      return args
    end

member?(field_name) click to toggle source

    # File lib/openid/extensions/sreg.rb, line 214
    def member?(field_name)
      all_requested_fields.member?(field_name)
    end

parse_extension_args(args, strict = false) click to toggle source

Parse the unqualified simple registration request parameters and add them to this object.

This method is essentially the inverse of getExtensionArgs. This method restores the serialized simple registration request fields.

If you are extracting arguments from a standard OpenID checkid_* request, you probably want to use fromOpenIDRequest, which will extract the sreg namespace and arguments from the OpenID request. This method is intended for cases where the OpenID server needs more control over how the arguments are parsed than that method provides.

    # File lib/openid/extensions/sreg.rb, line 126
    def parse_extension_args(args, strict = false)
      required_items = args['required']
      unless required_items.nil? or required_items.empty?
        required_items.split(',').each{|field_name|
          begin
            request_field(field_name, true, strict)
          rescue ArgumentError
            raise if strict
          end
        }
      end

      optional_items = args['optional']
      unless optional_items.nil? or optional_items.empty?
        optional_items.split(',').each{|field_name|
          begin
            request_field(field_name, false, strict)
          rescue ArgumentError
            raise if strict
          end
        }
      end
      @policy_url = args['policy_url']
    end

request_field(field_name, required=false, strict=false) click to toggle source

Request the specified field from the OpenID user field_name: the unqualified simple registration field name required: whether the given field should be presented

    to the user as being a required to successfully complete
    the request

strict: whether to raise an exception when a field is

    added to a request more than once

Raises ArgumentError if the field_name is not a simple registration field, or if strict is set and a field is added more than once

    # File lib/openid/extensions/sreg.rb, line 171
    def request_field(field_name, required=false, strict=false)
      OpenID::check_sreg_field_name(field_name)

      if strict
        if (@required + @optional).member? field_name
          raise ArgumentError, 'That field has already been requested'
        end
      else
        return if @required.member? field_name
        if @optional.member? field_name
          if required
            @optional.delete field_name
          else
            return
          end
        end
      end
      if required
        @required << field_name
      else
        @optional << field_name
      end
    end

request_fields(field_names, required = false, strict = false) click to toggle source

Add the given list of fields to the request.

    # File lib/openid/extensions/sreg.rb, line 196
    def request_fields(field_names, required = false, strict = false)
      raise ArgumentError unless field_names.respond_to?(:each) and
                                 field_names[0].is_a?(String)
      field_names.each{|fn|request_field(fn, required, strict)}
    end

were_fields_requested?() click to toggle source

Have any simple registration fields been requested?

    # File lib/openid/extensions/sreg.rb, line 158
    def were_fields_requested?
      !all_requested_fields.empty?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.