ax.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. # -*- test-case-name: openid.test.test_ax -*-
  2. """Implements the OpenID Attribute Exchange specification, version 1.0.
  3. @since: 2.1.0
  4. """
  5. __all__ = [
  6. 'AttributeRequest',
  7. 'FetchRequest',
  8. 'FetchResponse',
  9. 'StoreRequest',
  10. 'StoreResponse',
  11. ]
  12. from openid import extension
  13. from openid.server.trustroot import TrustRoot
  14. from openid.message import NamespaceMap, OPENID_NS
  15. # Use this as the 'count' value for an attribute in a FetchRequest to
  16. # ask for as many values as the OP can provide.
  17. UNLIMITED_VALUES = "unlimited"
  18. # Minimum supported alias length in characters. Here for
  19. # completeness.
  20. MINIMUM_SUPPORTED_ALIAS_LENGTH = 32
  21. def checkAlias(alias):
  22. """
  23. Check an alias for invalid characters; raise AXError if any are
  24. found. Return None if the alias is valid.
  25. """
  26. if ',' in alias:
  27. raise AXError("Alias %r must not contain comma" % (alias,))
  28. if '.' in alias:
  29. raise AXError("Alias %r must not contain period" % (alias,))
  30. class AXError(ValueError):
  31. """Results from data that does not meet the attribute exchange 1.0
  32. specification"""
  33. class NotAXMessage(AXError):
  34. """Raised when there is no Attribute Exchange mode in the message."""
  35. def __repr__(self):
  36. return self.__class__.__name__
  37. def __str__(self):
  38. return self.__class__.__name__
  39. class AXMessage(extension.Extension):
  40. """Abstract class containing common code for attribute exchange messages
  41. @cvar ns_alias: The preferred namespace alias for attribute
  42. exchange messages
  43. @cvar mode: The type of this attribute exchange message. This must
  44. be overridden in subclasses.
  45. """
  46. # This class is abstract, so it's OK that it doesn't override the
  47. # abstract method in Extension:
  48. #
  49. #pylint:disable-msg=W0223
  50. ns_alias = 'ax'
  51. mode = None
  52. ns_uri = 'http://openid.net/srv/ax/1.0'
  53. def _checkMode(self, ax_args):
  54. """Raise an exception if the mode in the attribute exchange
  55. arguments does not match what is expected for this class.
  56. @raises NotAXMessage: When there is no mode value in ax_args at all.
  57. @raises AXError: When mode does not match.
  58. """
  59. mode = ax_args.get('mode')
  60. if mode != self.mode:
  61. if not mode:
  62. raise NotAXMessage()
  63. else:
  64. raise AXError(
  65. 'Expected mode %r; got %r' % (self.mode, mode))
  66. def _newArgs(self):
  67. """Return a set of attribute exchange arguments containing the
  68. basic information that must be in every attribute exchange
  69. message.
  70. """
  71. return {'mode':self.mode}
  72. class AttrInfo(object):
  73. """Represents a single attribute in an attribute exchange
  74. request. This should be added to an AXRequest object in order to
  75. request the attribute.
  76. @ivar required: Whether the attribute will be marked as required
  77. when presented to the subject of the attribute exchange
  78. request.
  79. @type required: bool
  80. @ivar count: How many values of this type to request from the
  81. subject. Defaults to one.
  82. @type count: int
  83. @ivar type_uri: The identifier that determines what the attribute
  84. represents and how it is serialized. For example, one type URI
  85. representing dates could represent a Unix timestamp in base 10
  86. and another could represent a human-readable string.
  87. @type type_uri: str
  88. @ivar alias: The name that should be given to this alias in the
  89. request. If it is not supplied, a generic name will be
  90. assigned. For example, if you want to call a Unix timestamp
  91. value 'tstamp', set its alias to that value. If two attributes
  92. in the same message request to use the same alias, the request
  93. will fail to be generated.
  94. @type alias: str or NoneType
  95. """
  96. # It's OK that this class doesn't have public methods (it's just a
  97. # holder for a bunch of attributes):
  98. #
  99. #pylint:disable-msg=R0903
  100. def __init__(self, type_uri, count=1, required=False, alias=None):
  101. self.required = required
  102. self.count = count
  103. self.type_uri = type_uri
  104. self.alias = alias
  105. if self.alias is not None:
  106. checkAlias(self.alias)
  107. def wantsUnlimitedValues(self):
  108. """
  109. When processing a request for this attribute, the OP should
  110. call this method to determine whether all available attribute
  111. values were requested. If self.count == UNLIMITED_VALUES,
  112. this returns True. Otherwise this returns False, in which
  113. case self.count is an integer.
  114. """
  115. return self.count == UNLIMITED_VALUES
  116. def toTypeURIs(namespace_map, alias_list_s):
  117. """Given a namespace mapping and a string containing a
  118. comma-separated list of namespace aliases, return a list of type
  119. URIs that correspond to those aliases.
  120. @param namespace_map: The mapping from namespace URI to alias
  121. @type namespace_map: openid.message.NamespaceMap
  122. @param alias_list_s: The string containing the comma-separated
  123. list of aliases. May also be None for convenience.
  124. @type alias_list_s: str or NoneType
  125. @returns: The list of namespace URIs that corresponds to the
  126. supplied list of aliases. If the string was zero-length or
  127. None, an empty list will be returned.
  128. @raise KeyError: If an alias is present in the list of aliases but
  129. is not present in the namespace map.
  130. """
  131. uris = []
  132. if alias_list_s:
  133. for alias in alias_list_s.split(','):
  134. type_uri = namespace_map.getNamespaceURI(alias)
  135. if type_uri is None:
  136. raise KeyError(
  137. 'No type is defined for attribute name %r' % (alias,))
  138. else:
  139. uris.append(type_uri)
  140. return uris
  141. class FetchRequest(AXMessage):
  142. """An attribute exchange 'fetch_request' message. This message is
  143. sent by a relying party when it wishes to obtain attributes about
  144. the subject of an OpenID authentication request.
  145. @ivar requested_attributes: The attributes that have been
  146. requested thus far, indexed by the type URI.
  147. @type requested_attributes: {str:AttrInfo}
  148. @ivar update_url: A URL that will accept responses for this
  149. attribute exchange request, even in the absence of the user
  150. who made this request.
  151. """
  152. mode = 'fetch_request'
  153. def __init__(self, update_url=None):
  154. AXMessage.__init__(self)
  155. self.requested_attributes = {}
  156. self.update_url = update_url
  157. def add(self, attribute):
  158. """Add an attribute to this attribute exchange request.
  159. @param attribute: The attribute that is being requested
  160. @type attribute: C{L{AttrInfo}}
  161. @returns: None
  162. @raise KeyError: when the requested attribute is already
  163. present in this fetch request.
  164. """
  165. if attribute.type_uri in self.requested_attributes:
  166. raise KeyError('The attribute %r has already been requested'
  167. % (attribute.type_uri,))
  168. self.requested_attributes[attribute.type_uri] = attribute
  169. def getExtensionArgs(self):
  170. """Get the serialized form of this attribute fetch request.
  171. @returns: The fetch request message parameters
  172. @rtype: {unicode:unicode}
  173. """
  174. aliases = NamespaceMap()
  175. required = []
  176. if_available = []
  177. ax_args = self._newArgs()
  178. for type_uri, attribute in self.requested_attributes.iteritems():
  179. if attribute.alias is None:
  180. alias = aliases.add(type_uri)
  181. else:
  182. # This will raise an exception when the second
  183. # attribute with the same alias is added. I think it
  184. # would be better to complain at the time that the
  185. # attribute is added to this object so that the code
  186. # that is adding it is identified in the stack trace,
  187. # but it's more work to do so, and it won't be 100%
  188. # accurate anyway, since the attributes are
  189. # mutable. So for now, just live with the fact that
  190. # we'll learn about the error later.
  191. #
  192. # The other possible approach is to hide the error and
  193. # generate a new alias on the fly. I think that would
  194. # probably be bad.
  195. alias = aliases.addAlias(type_uri, attribute.alias)
  196. if attribute.required:
  197. required.append(alias)
  198. else:
  199. if_available.append(alias)
  200. if attribute.count != 1:
  201. ax_args['count.' + alias] = str(attribute.count)
  202. ax_args['type.' + alias] = type_uri
  203. if required:
  204. ax_args['required'] = ','.join(required)
  205. if if_available:
  206. ax_args['if_available'] = ','.join(if_available)
  207. return ax_args
  208. def getRequiredAttrs(self):
  209. """Get the type URIs for all attributes that have been marked
  210. as required.
  211. @returns: A list of the type URIs for attributes that have
  212. been marked as required.
  213. @rtype: [str]
  214. """
  215. required = []
  216. for type_uri, attribute in self.requested_attributes.iteritems():
  217. if attribute.required:
  218. required.append(type_uri)
  219. return required
  220. def fromOpenIDRequest(cls, openid_request):
  221. """Extract a FetchRequest from an OpenID message
  222. @param openid_request: The OpenID authentication request
  223. containing the attribute fetch request
  224. @type openid_request: C{L{openid.server.server.CheckIDRequest}}
  225. @rtype: C{L{FetchRequest}} or C{None}
  226. @returns: The FetchRequest extracted from the message or None, if
  227. the message contained no AX extension.
  228. @raises KeyError: if the AuthRequest is not consistent in its use
  229. of namespace aliases.
  230. @raises AXError: When parseExtensionArgs would raise same.
  231. @see: L{parseExtensionArgs}
  232. """
  233. message = openid_request.message
  234. ax_args = message.getArgs(cls.ns_uri)
  235. self = cls()
  236. try:
  237. self.parseExtensionArgs(ax_args)
  238. except NotAXMessage, err:
  239. return None
  240. if self.update_url:
  241. # Update URL must match the openid.realm of the underlying
  242. # OpenID 2 message.
  243. realm = message.getArg(OPENID_NS, 'realm',
  244. message.getArg(OPENID_NS, 'return_to'))
  245. if not realm:
  246. raise AXError(("Cannot validate update_url %r " +
  247. "against absent realm") % (self.update_url,))
  248. tr = TrustRoot.parse(realm)
  249. if not tr.validateURL(self.update_url):
  250. raise AXError("Update URL %r failed validation against realm %r" %
  251. (self.update_url, realm,))
  252. return self
  253. fromOpenIDRequest = classmethod(fromOpenIDRequest)
  254. def parseExtensionArgs(self, ax_args):
  255. """Given attribute exchange arguments, populate this FetchRequest.
  256. @param ax_args: Attribute Exchange arguments from the request.
  257. As returned from L{Message.getArgs<openid.message.Message.getArgs>}.
  258. @type ax_args: dict
  259. @raises KeyError: if the message is not consistent in its use
  260. of namespace aliases.
  261. @raises NotAXMessage: If ax_args does not include an Attribute Exchange
  262. mode.
  263. @raises AXError: If the data to be parsed does not follow the
  264. attribute exchange specification. At least when
  265. 'if_available' or 'required' is not specified for a
  266. particular attribute type.
  267. """
  268. # Raises an exception if the mode is not the expected value
  269. self._checkMode(ax_args)
  270. aliases = NamespaceMap()
  271. for key, value in ax_args.iteritems():
  272. if key.startswith('type.'):
  273. alias = key[5:]
  274. type_uri = value
  275. aliases.addAlias(type_uri, alias)
  276. count_key = 'count.' + alias
  277. count_s = ax_args.get(count_key)
  278. if count_s:
  279. try:
  280. count = int(count_s)
  281. if count <= 0:
  282. raise AXError("Count %r must be greater than zero, got %r" % (count_key, count_s,))
  283. except ValueError:
  284. if count_s != UNLIMITED_VALUES:
  285. raise AXError("Invalid count value for %r: %r" % (count_key, count_s,))
  286. count = count_s
  287. else:
  288. count = 1
  289. self.add(AttrInfo(type_uri, alias=alias, count=count))
  290. required = toTypeURIs(aliases, ax_args.get('required'))
  291. for type_uri in required:
  292. self.requested_attributes[type_uri].required = True
  293. if_available = toTypeURIs(aliases, ax_args.get('if_available'))
  294. all_type_uris = required + if_available
  295. for type_uri in aliases.iterNamespaceURIs():
  296. if type_uri not in all_type_uris:
  297. raise AXError(
  298. 'Type URI %r was in the request but not '
  299. 'present in "required" or "if_available"' % (type_uri,))
  300. self.update_url = ax_args.get('update_url')
  301. def iterAttrs(self):
  302. """Iterate over the AttrInfo objects that are
  303. contained in this fetch_request.
  304. """
  305. return self.requested_attributes.itervalues()
  306. def __iter__(self):
  307. """Iterate over the attribute type URIs in this fetch_request
  308. """
  309. return iter(self.requested_attributes)
  310. def has_key(self, type_uri):
  311. """Is the given type URI present in this fetch_request?
  312. """
  313. return type_uri in self.requested_attributes
  314. __contains__ = has_key
  315. class AXKeyValueMessage(AXMessage):
  316. """An abstract class that implements a message that has attribute
  317. keys and values. It contains the common code between
  318. fetch_response and store_request.
  319. """
  320. # This class is abstract, so it's OK that it doesn't override the
  321. # abstract method in Extension:
  322. #
  323. #pylint:disable-msg=W0223
  324. def __init__(self):
  325. AXMessage.__init__(self)
  326. self.data = {}
  327. def addValue(self, type_uri, value):
  328. """Add a single value for the given attribute type to the
  329. message. If there are already values specified for this type,
  330. this value will be sent in addition to the values already
  331. specified.
  332. @param type_uri: The URI for the attribute
  333. @param value: The value to add to the response to the relying
  334. party for this attribute
  335. @type value: unicode
  336. @returns: None
  337. """
  338. try:
  339. values = self.data[type_uri]
  340. except KeyError:
  341. values = self.data[type_uri] = []
  342. values.append(value)
  343. def setValues(self, type_uri, values):
  344. """Set the values for the given attribute type. This replaces
  345. any values that have already been set for this attribute.
  346. @param type_uri: The URI for the attribute
  347. @param values: A list of values to send for this attribute.
  348. @type values: [unicode]
  349. """
  350. self.data[type_uri] = values
  351. def _getExtensionKVArgs(self, aliases=None):
  352. """Get the extension arguments for the key/value pairs
  353. contained in this message.
  354. @param aliases: An alias mapping. Set to None if you don't
  355. care about the aliases for this request.
  356. """
  357. if aliases is None:
  358. aliases = NamespaceMap()
  359. ax_args = {}
  360. for type_uri, values in self.data.iteritems():
  361. alias = aliases.add(type_uri)
  362. ax_args['type.' + alias] = type_uri
  363. ax_args['count.' + alias] = str(len(values))
  364. for i, value in enumerate(values):
  365. key = 'value.%s.%d' % (alias, i + 1)
  366. ax_args[key] = value
  367. return ax_args
  368. def parseExtensionArgs(self, ax_args):
  369. """Parse attribute exchange key/value arguments into this
  370. object.
  371. @param ax_args: The attribute exchange fetch_response
  372. arguments, with namespacing removed.
  373. @type ax_args: {unicode:unicode}
  374. @returns: None
  375. @raises ValueError: If the message has bad values for
  376. particular fields
  377. @raises KeyError: If the namespace mapping is bad or required
  378. arguments are missing
  379. """
  380. self._checkMode(ax_args)
  381. aliases = NamespaceMap()
  382. for key, value in ax_args.iteritems():
  383. if key.startswith('type.'):
  384. type_uri = value
  385. alias = key[5:]
  386. checkAlias(alias)
  387. aliases.addAlias(type_uri, alias)
  388. for type_uri, alias in aliases.iteritems():
  389. try:
  390. count_s = ax_args['count.' + alias]
  391. except KeyError:
  392. value = ax_args['value.' + alias]
  393. if value == u'':
  394. values = []
  395. else:
  396. values = [value]
  397. else:
  398. count = int(count_s)
  399. values = []
  400. for i in range(1, count + 1):
  401. value_key = 'value.%s.%d' % (alias, i)
  402. value = ax_args[value_key]
  403. values.append(value)
  404. self.data[type_uri] = values
  405. def getSingle(self, type_uri, default=None):
  406. """Get a single value for an attribute. If no value was sent
  407. for this attribute, use the supplied default. If there is more
  408. than one value for this attribute, this method will fail.
  409. @type type_uri: str
  410. @param type_uri: The URI for the attribute
  411. @param default: The value to return if the attribute was not
  412. sent in the fetch_response.
  413. @returns: The value of the attribute in the fetch_response
  414. message, or the default supplied
  415. @rtype: unicode or NoneType
  416. @raises ValueError: If there is more than one value for this
  417. parameter in the fetch_response message.
  418. @raises KeyError: If the attribute was not sent in this response
  419. """
  420. values = self.data.get(type_uri)
  421. if not values:
  422. return default
  423. elif len(values) == 1:
  424. return values[0]
  425. else:
  426. raise AXError(
  427. 'More than one value present for %r' % (type_uri,))
  428. def get(self, type_uri):
  429. """Get the list of values for this attribute in the
  430. fetch_response.
  431. XXX: what to do if the values are not present? default
  432. parameter? this is funny because it's always supposed to
  433. return a list, so the default may break that, though it's
  434. provided by the user's code, so it might be okay. If no
  435. default is supplied, should the return be None or []?
  436. @param type_uri: The URI of the attribute
  437. @returns: The list of values for this attribute in the
  438. response. May be an empty list.
  439. @rtype: [unicode]
  440. @raises KeyError: If the attribute was not sent in the response
  441. """
  442. return self.data[type_uri]
  443. def count(self, type_uri):
  444. """Get the number of responses for a particular attribute in
  445. this fetch_response message.
  446. @param type_uri: The URI of the attribute
  447. @returns: The number of values sent for this attribute
  448. @raises KeyError: If the attribute was not sent in the
  449. response. KeyError will not be raised if the number of
  450. values was zero.
  451. """
  452. return len(self.get(type_uri))
  453. class FetchResponse(AXKeyValueMessage):
  454. """A fetch_response attribute exchange message
  455. """
  456. mode = 'fetch_response'
  457. def __init__(self, request=None, update_url=None):
  458. """
  459. @param request: When supplied, I will use namespace aliases
  460. that match those in this request. I will also check to
  461. make sure I do not respond with attributes that were not
  462. requested.
  463. @type request: L{FetchRequest}
  464. @param update_url: By default, C{update_url} is taken from the
  465. request. But if you do not supply the request, you may set
  466. the C{update_url} here.
  467. @type update_url: str
  468. """
  469. AXKeyValueMessage.__init__(self)
  470. self.update_url = update_url
  471. self.request = request
  472. def getExtensionArgs(self):
  473. """Serialize this object into arguments in the attribute
  474. exchange namespace
  475. @returns: The dictionary of unqualified attribute exchange
  476. arguments that represent this fetch_response.
  477. @rtype: {unicode;unicode}
  478. """
  479. aliases = NamespaceMap()
  480. zero_value_types = []
  481. if self.request is not None:
  482. # Validate the data in the context of the request (the
  483. # same attributes should be present in each, and the
  484. # counts in the response must be no more than the counts
  485. # in the request)
  486. for type_uri in self.data:
  487. if type_uri not in self.request:
  488. raise KeyError(
  489. 'Response attribute not present in request: %r'
  490. % (type_uri,))
  491. for attr_info in self.request.iterAttrs():
  492. # Copy the aliases from the request so that reading
  493. # the response in light of the request is easier
  494. if attr_info.alias is None:
  495. aliases.add(attr_info.type_uri)
  496. else:
  497. aliases.addAlias(attr_info.type_uri, attr_info.alias)
  498. try:
  499. values = self.data[attr_info.type_uri]
  500. except KeyError:
  501. values = []
  502. zero_value_types.append(attr_info)
  503. if (attr_info.count != UNLIMITED_VALUES) and \
  504. (attr_info.count < len(values)):
  505. raise AXError(
  506. 'More than the number of requested values were '
  507. 'specified for %r' % (attr_info.type_uri,))
  508. kv_args = self._getExtensionKVArgs(aliases)
  509. # Add the KV args into the response with the args that are
  510. # unique to the fetch_response
  511. ax_args = self._newArgs()
  512. # For each requested attribute, put its type/alias and count
  513. # into the response even if no data were returned.
  514. for attr_info in zero_value_types:
  515. alias = aliases.getAlias(attr_info.type_uri)
  516. kv_args['type.' + alias] = attr_info.type_uri
  517. kv_args['count.' + alias] = '0'
  518. update_url = ((self.request and self.request.update_url)
  519. or self.update_url)
  520. if update_url:
  521. ax_args['update_url'] = update_url
  522. ax_args.update(kv_args)
  523. return ax_args
  524. def parseExtensionArgs(self, ax_args):
  525. """@see: {Extension.parseExtensionArgs<openid.extension.Extension.parseExtensionArgs>}"""
  526. super(FetchResponse, self).parseExtensionArgs(ax_args)
  527. self.update_url = ax_args.get('update_url')
  528. def fromSuccessResponse(cls, success_response, signed=True):
  529. """Construct a FetchResponse object from an OpenID library
  530. SuccessResponse object.
  531. @param success_response: A successful id_res response object
  532. @type success_response: openid.consumer.consumer.SuccessResponse
  533. @param signed: Whether non-signed args should be
  534. processsed. If True (the default), only signed arguments
  535. will be processsed.
  536. @type signed: bool
  537. @returns: A FetchResponse containing the data from the OpenID
  538. message, or None if the SuccessResponse did not contain AX
  539. extension data.
  540. @raises AXError: when the AX data cannot be parsed.
  541. """
  542. self = cls()
  543. ax_args = success_response.extensionResponse(self.ns_uri, signed)
  544. try:
  545. self.parseExtensionArgs(ax_args)
  546. except NotAXMessage, err:
  547. return None
  548. else:
  549. return self
  550. fromSuccessResponse = classmethod(fromSuccessResponse)
  551. class StoreRequest(AXKeyValueMessage):
  552. """A store request attribute exchange message representation
  553. """
  554. mode = 'store_request'
  555. def __init__(self, aliases=None):
  556. """
  557. @param aliases: The namespace aliases to use when making this
  558. store request. Leave as None to use defaults.
  559. """
  560. super(StoreRequest, self).__init__()
  561. self.aliases = aliases
  562. def getExtensionArgs(self):
  563. """
  564. @see: L{Extension.getExtensionArgs<openid.extension.Extension.getExtensionArgs>}
  565. """
  566. ax_args = self._newArgs()
  567. kv_args = self._getExtensionKVArgs(self.aliases)
  568. ax_args.update(kv_args)
  569. return ax_args
  570. class StoreResponse(AXMessage):
  571. """An indication that the store request was processed along with
  572. this OpenID transaction.
  573. """
  574. SUCCESS_MODE = 'store_response_success'
  575. FAILURE_MODE = 'store_response_failure'
  576. def __init__(self, succeeded=True, error_message=None):
  577. AXMessage.__init__(self)
  578. if succeeded and error_message is not None:
  579. raise AXError('An error message may only be included in a '
  580. 'failing fetch response')
  581. if succeeded:
  582. self.mode = self.SUCCESS_MODE
  583. else:
  584. self.mode = self.FAILURE_MODE
  585. self.error_message = error_message
  586. def succeeded(self):
  587. """Was this response a success response?"""
  588. return self.mode == self.SUCCESS_MODE
  589. def getExtensionArgs(self):
  590. """@see: {Extension.getExtensionArgs<openid.extension.Extension.getExtensionArgs>}"""
  591. ax_args = self._newArgs()
  592. if not self.succeeded() and self.error_message:
  593. ax_args['error'] = self.error_message
  594. return ax_args