|
190 | 190 |
|
191 | 191 | import cgi |
192 | 192 | import copy |
193 | | -from urlparse import urlparse |
| 193 | +from urlparse import urlparse, urldefrag |
194 | 194 |
|
195 | 195 | from openid import fetchers |
196 | 196 |
|
@@ -900,26 +900,36 @@ def _verifyDiscoveryResultsOpenID2(self, resp_msg, endpoint): |
900 | 900 | elif to_match.claimed_id is None: |
901 | 901 | return OpenIDServiceEndpoint.fromOPEndpointURL(to_match.server_url) |
902 | 902 |
|
| 903 | + # Fragments do not influence discovery, so we can't compare a |
| 904 | + # claimed identifier with a fragment to discovered information. |
| 905 | + defragged_claimed_id, _ = urldefrag(to_match.claimed_id) |
| 906 | + |
903 | 907 | # The claimed ID doesn't match, so we have to do discovery |
904 | 908 | # again. This covers not using sessions, OP identifier |
905 | 909 | # endpoints and responses that didn't match the original |
906 | 910 | # request. |
907 | | - elif not endpoint: |
| 911 | + if not endpoint: |
908 | 912 | oidutil.log('No pre-discovered information supplied.') |
909 | | - return self._discoverAndVerify(to_match) |
| 913 | + endpoint = self._discoverAndVerify(to_match) |
910 | 914 |
|
911 | | - elif to_match.claimed_id != endpoint.claimed_id: |
| 915 | + elif defragged_claimed_id != endpoint.claimed_id: |
912 | 916 | oidutil.log('Mismatched pre-discovered session data. ' |
913 | 917 | 'Claimed ID in session=%s, in assertion=%s' % |
914 | | - (endpoint.claimed_id, to_match.claimed_id)) |
915 | | - return self._discoverAndVerify(to_match) |
| 918 | + (endpoint.claimed_id, defragged_claimed_id)) |
| 919 | + endpoint = self._discoverAndVerify(to_match) |
916 | 920 |
|
917 | 921 | # The claimed ID matches, so we use the endpoint that we |
918 | 922 | # discovered in initiation. This should be the most common |
919 | 923 | # case. |
920 | 924 | else: |
921 | 925 | self._verifyDiscoverySingle(endpoint, to_match) |
922 | | - return endpoint |
| 926 | + |
| 927 | + # The endpoint we return should have the claimed ID from the |
| 928 | + # message we just verified, fragment and all. |
| 929 | + if endpoint.claimed_id != to_match.claimed_id: |
| 930 | + endpoint = copy.copy(endpoint) |
| 931 | + endpoint.claimed_id = to_match.claimed_id |
| 932 | + return endpoint |
923 | 933 |
|
924 | 934 | def _verifyDiscoveryResultsOpenID1(self, resp_msg, endpoint): |
925 | 935 | if endpoint is None: |
@@ -967,11 +977,14 @@ def _verifyDiscoverySingle(self, endpoint, to_match): |
967 | 977 | if not endpoint.usesExtension(type_uri): |
968 | 978 | raise TypeURIMismatch(type_uri, endpoint) |
969 | 979 |
|
970 | | - if to_match.claimed_id != endpoint.claimed_id: |
| 980 | + # Fragments do not influence discovery, so we can't compare a |
| 981 | + # claimed identifier with a fragment to discovered information. |
| 982 | + defragged_claimed_id, _ = urldefrag(to_match.claimed_id) |
| 983 | + if defragged_claimed_id != endpoint.claimed_id: |
971 | 984 | raise ProtocolError( |
972 | 985 | 'Claimed ID does not match (different subjects!), ' |
973 | 986 | 'Expected %s, got %s' % |
974 | | - (to_match.claimed_id, endpoint.claimed_id)) |
| 987 | + (defragged_claimed_id, endpoint.claimed_id)) |
975 | 988 |
|
976 | 989 | if to_match.getLocalID() != endpoint.getLocalID(): |
977 | 990 | raise ProtocolError('local_id mismatch. Expected %s, got %s' % |
|
0 commit comments