Auth 2.0 Extensions: Namespace Prefixes

Josh Hoyt josh at janrain.com
Tue Jun 5 17:49:44 UTC 2007


On 6/5/07, Recordon, David <drecordon at verisign.com> wrote:
> Since it seems no one has replied yet, I'd agree that this would make
> implementations easier.  Iterating via a regular expression seems ugly
> and hard to do (well except in Perl). :-\

-1. It's one more thing to get wrong. There would then be the case
where an extension had a namespace alias declaration but was missing
from that list, or was in that list but did not have a namespace alias
declaration.

Iterating one time to build a lookup table is easy, and you get the
namespace URIs out of that one iteration.  It doesn't take regular
expressions (it's just a prefix match), and I've never used a language
that would make this kind of iteration difficult.

Each technique implemented in Python for comparison:

prefix = "openid.ns."
prefix_len = len(prefix)

def extractNamespaceAliases(query):
    """Extract the namespace URIs from a dictionary containing a
    parsed HTTP query string or POST body. Returns a dictionary from
    namespace alias to namespace URI.

    This code implements the current draft of the OpenID 2.0
    specification. Very straightforward.

    """
    namespace_aliases = {}

    for k, v in query.iteritems():
        if k.startswith(prefix):
            alias = key[prefix_len:]
            namespace_aliases[alias] = v

    return namespace_aliases

def extractNamespaceAliases1(query):
    """Extract the namespace URIs from a dictionary containing a
    parsed HTTP query string or POST body. Returns a dictionary from
    namespace alias to namespace URI.

    This version implements the proposal in this thread. The code has
    more branches and has to build new strings as lookup keys.
    """
    namespace_aliases = {}

    namespace_string = query.get('openid.extensions')

    # Ignore missing or empty "openid.extensions" parameter
    if namespace_string:
        aliases = namespace_string.split(',')

        for alias in aliases:
            try:
                namespace_aliases[alias] = query[prefix + alias]
            except KeyError:
                pass # Ignore declared but missing extensions

    return namespace_aliases



More information about the specs mailing list