|
189 | 189 | from openid import cryptutil |
190 | 190 | from openid import kvform |
191 | 191 | from openid import oidutil |
192 | | -from openid.association import Association, default_negotiator |
| 192 | +from openid.association import Association, default_negotiator, \ |
| 193 | + SessionNegotiator |
193 | 194 | from openid.dh import DiffieHellman |
194 | 195 | from openid.store.nonce import mkNonce, split as splitNonce |
195 | 196 | from openid.yadis.manager import Discovery |
@@ -370,6 +371,28 @@ def complete(self, query, return_to=None): |
370 | 371 |
|
371 | 372 | return response |
372 | 373 |
|
| 374 | + def setAssociationPreference(self, association_preferences): |
| 375 | + """Set the order in which association types/sessions should be |
| 376 | + attempted. For instance, to only allow HMAC-SHA256 |
| 377 | + associations created with a DH-SHA256 association session: |
| 378 | +
|
| 379 | + >>> consumer.setAssociationPreference([('HMAC-SHA256', 'DH-SHA256')]) |
| 380 | +
|
| 381 | + Any association type/association type pair that is not in this |
| 382 | + list will not be attempted at all. |
| 383 | +
|
| 384 | + @param association_preferences: The list of allowed |
| 385 | + (association type, association session type) pairs that |
| 386 | + should be allowed for this consumer to use, in order from |
| 387 | + most preferred to least preferred. |
| 388 | + @type association_preferences: [(str, str)] |
| 389 | +
|
| 390 | + @returns: None |
| 391 | +
|
| 392 | + @see: C{L{openid.association.SessionNegotiator}} |
| 393 | + """ |
| 394 | + self.consumer.negotiator = SessionNegotiator(association_preferences) |
| 395 | + |
373 | 396 | class DiffieHellmanSHA1ConsumerSession(object): |
374 | 397 | session_type = 'DH-SHA1' |
375 | 398 | hash_func = staticmethod(cryptutil.sha1) |
@@ -457,6 +480,13 @@ class GenericConsumer(object): |
457 | 480 | """This is the implementation of the common logic for OpenID |
458 | 481 | consumers. It is unaware of the application in which it is |
459 | 482 | running. |
| 483 | +
|
| 484 | + @ivar negotiator: An object that controls the kind of associations |
| 485 | + that the consumer makes. It defaults to |
| 486 | + C{L{openid.association.default_negotiator}}. Assign a |
| 487 | + different negotiator to it if you have specific requirements |
| 488 | + for how associations are made. |
| 489 | + @type negotiator: C{L{openid.association.SessionNegotiator}} |
460 | 490 | """ |
461 | 491 |
|
462 | 492 | # The name of the query parameter that gets added to the return_to |
|
0 commit comments