Class ::xo::oauth::Signature

::xo::oauth::Signature[i] create ... \
           [ -base_string_uri base_string_uri ] \
           [ -client_secret client_secret ] \
           [ -request_method (default "POST") ] \
           [ -signature_parameters signature_parameters ] \
           [ -token_secret (default "") ]

Documented Parameters:
protocol_parameters
Expects a list of key-value pairs representing parameters of different sources.
Defined in packages/xooauth/tcl/oauth-procs.tcl

Class Relations

  • class: ::xotcl::Class[i]
  • superclass: ::xotcl::Object[i]
::xotcl::Class create ::xo::oauth::Signature \
     -superclass ::xotcl::Object

Methods (to be applied on the object)

  • base_string_from_url (scripted, public)

     xo::oauth::Signature[i] base_string_from_url uri

    This procedure transforms a given URL into a format that is conformant to "http://tools.ietf.org/html/rfc5849#section-3.4.1.2". Most importantly, it strips any query part from the URL.

    Parameters:
    uri

    Partial Call Graph (max 5 caller/called nodes):
    %3 uri::join uri::join uri::split uri::split xo::oauth::Signature proc base_string_from_url xo::oauth::Signature proc base_string_from_url xo::oauth::Signature proc base_string_from_url->uri::join xo::oauth::Signature proc base_string_from_url->uri::split

    Testcases:
    No testcase defined.
    set info [uri::split $uri]
    set base_string_uri [uri::join  scheme [dict get $info scheme]  host [dict get $info host]  port [dict get $info port]  path [dict get $info path]]
    return $base_string_uri

Methods (to be applied on instances)

  • base_string_uri (setter)

  • client_secret (setter)

  • construct_base_string (scripted)

    # @see http://tools.ietf.org/html/rfc3986#section-3.1
    append sbs [:encode [string toupper [:request_method]]]
    append sbs "&"
    append sbs [:encode [:base_string_uri]]
    append sbs "&"
    append sbs [:normalize_parameters]
    #:log "Signature Base String:\n$sbs"
    return $sbs
  • encode (scripted, public)

     <instance of xo::oauth::Signature[i]> encode s
    Parameters:
    s
    See Also:

    Partial Call Graph (max 5 caller/called nodes):
    %3

    Testcases:
    No testcase defined.
    #return [::xowiki::utility urlencode $s]
    return [::xo::oauth::utility urlencode $s]
  • generate (scripted)

    
    set signature [ns_crypto::hmac string  -binary  -digest sha1  -encoding base64  [:encode ${:client_secret}]&[:encode ${:token_secret}]  [:construct_base_string]  ]
    
    return $signature
  • normalize_parameters (scripted)

    set parameter_pair_list [:signature_parameters]
    set encoded_parameter_pair_list {}
    foreach pair $parameter_pair_list {
      lassign $pair key value
      if {[string match "*secret" $key]} continue
      lappend encoded_parameter_pair_list [list [:encode $key] [:encode $value]]
    }
    #ns_log notice "encoded_parameter_pair_list $encoded_parameter_pair_list"
    foreach pair $encoded_parameter_pair_list {
      lassign $pair key value
      lappend concatenated_parameter_list [list ${key}=${value}]
    }
    # Note: OAuth requires the parameters to be sorted first by name and then,
    # if two parameters have the same name, by value. So instead of sorting
    # twice here, we just sort the concatenated value (e.g. a=b) as a whole.
    # I hope I have no error in reasoning here...
    # set sorted_parameter_pair_list [lsort -index 0 $encoded_parameter_pair_list]
    set sorted_concatenated_parameter_list [lsort $concatenated_parameter_list]
    
    #:log "Sorted Concatenated Parameters"
    #foreach pair $sorted_concatenated_parameter_list {
    #  foreach {key value} $pair {
    #    :log "Name: $key Value: $value"
    #  }
    #}
    
    set normalized_parameters [join $sorted_concatenated_parameter_list &]
    set encoded_normalized_parameters [:encode $normalized_parameters]
    return $encoded_normalized_parameters
  • request_method (setter)

  • signature_parameters (setter)

  • token_secret (setter)