Changeset c004bc in indico
- Timestamp:
- 11/25/11 09:26:26 (19 months ago)
- Branches:
- master, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.99, b8c30da8ebdbdcbd675a873997cc3e95f567de49, 4287315ec967a3da168d83963c14001db8487d53
- Children:
- dfa9c9
- Parents:
- 71df20
- git-author:
- Adrian Moennich <jerome.ernst.monnich@…> (09/27/11 14:28:29)
- git-committer:
- Jose Benito <jose.benito.gonzalez@…> (11/25/11 09:26:26)
- Files:
-
- 7 edited
-
doc/guides/ExportAPI/access.rst (modified) (5 diffs)
-
indico/MaKaC/webinterface/rh/api.py (modified) (1 diff)
-
indico/MaKaC/webinterface/tpls/UserAPI.tpl (modified) (1 diff)
-
indico/MaKaC/webinterface/urlHandlers.py (modified) (1 diff)
-
indico/htdocs/userAPI.py (modified) (1 diff)
-
indico/web/http_api/auth.py (modified) (2 diffs)
-
indico/web/http_api/handlers.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/guides/ExportAPI/access.rst
rcd4e48 rc004bc 80 80 You can find example code for Python and PHP in the following sections. 81 81 82 If persistent signatures are enabled, you can also omit the timestamp. 83 In this case the URL is valid forever. When using this feature, please 84 make sure to use these URLs only where necessary - use timestamped 85 URLs whenever possible. 86 82 87 Request Signing for Python 83 88 ^^^^^^^^^^^^^^^^^^^^^^^^^^ … … 91 96 92 97 93 def build_indico_request(path, params, api_key=None, secret_key=None, only_public=False ):98 def build_indico_request(path, params, api_key=None, secret_key=None, only_public=False, persistent=False): 94 99 items = params.items() if hasattr(params, 'items') else list(params) 95 100 if api_key: … … 98 103 items.append(('onlypublic', 'yes')) 99 104 if secret_key: 100 items.append(('timestamp', str(int(time.time())))) 105 if not persistent: 106 items.append(('timestamp', str(int(time.time())))) 101 107 items = sorted(items, key=lambda x: x[0].lower()) 102 108 url = '%s?%s' % (path, urllib.urlencode(items)) … … 125 131 <?php 126 132 127 function build_indico_request($path, $params, $api_key = null, $secret_key = null, $only_public = false ) {133 function build_indico_request($path, $params, $api_key = null, $secret_key = null, $only_public = false, $persistent = false) { 128 134 if($api_key) { 129 135 $params['apikey'] = $api_key; … … 135 141 136 142 if($secret_key) { 137 $params['timestamp'] = time(); 143 if(!$persistent) { 144 $params['timestamp'] = time(); 145 } 138 146 uksort($params, 'strcasecmp'); 139 147 $url = $path . '?' . http_build_query($params); -
indico/MaKaC/webinterface/rh/api.py
rfcdc60 rc004bc 47 47 ak.newKey() 48 48 ak.newSignKey() 49 self._redirect(urlHandlers.UHUserAPI.getURL(self._avatar)) 50 51 class RHUserAPIPersistent(RHUserBase): 52 def _checkParams(self, params): 53 RHUserBase._checkParams(self, params) 54 self._ak = self._avatar.getAPIKey() 55 56 def _checkProtection(self): 57 RHUserBase._checkProtection(self) 58 ak = self._avatar.getAPIKey() 59 if ak and ak.isBlocked(): 60 raise AccessError() 61 62 def _process(self): 63 self._ak.setPersistentAllowed(not self._ak.isPersistentAllowed()) 49 64 self._redirect(urlHandlers.UHUserAPI.getURL(self._avatar)) 50 65 -
indico/MaKaC/webinterface/tpls/UserAPI.tpl
rcd4e48 rc004bc 61 61 <td> 62 62 % if not apiKey: 63 <form action="${urlHandlers.UHUserAPICreate.getURL(avatar)}" method="POST" onsubmit="return confirm( '${_("Please only create an API key if you actually need one. Unused API keys might be deleted after some time.")}');">63 <form action="${urlHandlers.UHUserAPICreate.getURL(avatar)}" method="POST" onsubmit="return confirm($T('Please only create an API key if you actually need one. Unused API keys might be deleted after some time.'));"> 64 64 <input type="submit" value="${_('Create API key')}" /> 65 65 </form> 66 66 % else: 67 <form action="${urlHandlers.UHUserAPICreate.getURL(avatar)}" method="POST" onsubmit="return confirm( '${_("Warning: When creating a new API key pair, your old key pair will stop working immediately!")}');">67 <form action="${urlHandlers.UHUserAPICreate.getURL(avatar)}" method="POST" onsubmit="return confirm($T('Warning: When creating a new API key pair, your old key pair will stop working immediately!'));"> 68 68 <input type="submit" value="${_('Create a new API key pair')}" /> 69 69 </form> 70 % if apiKey.isPersistentAllowed(): 71 <form action="${urlHandlers.UHUserAPIPersistent.getURL(avatar)}" method="POST" onsubmit="return confirm($T('When disabling persistent signatures, all signed requests need a valid timestamp again. If you enable them again, old persistent links will start working again - if you need to to invalidate them, you need to create a new API key!'));"> 72 <input type="submit" value="${_('Disable persistent signatures')}" /> 73 </form> 74 % else: 75 <form action="${urlHandlers.UHUserAPIPersistent.getURL(avatar)}" method="POST" onsubmit="return confirm($T('With persistent signatures signed requests without a timestamp are allowed. By enabling them you agree to keep those links private and ensure that no unauthorized people will use them.'));"> 76 <input type="submit" value="${_('Enable persistent signatures')}" /> 77 </form> 78 % endif 70 79 % endif 71 80 </td> -
indico/MaKaC/webinterface/urlHandlers.py
raba8f4 rc004bc 1977 1977 class UHUserAPICreate( URLHandler ): 1978 1978 _relativeURL = "userAPI.py/create" 1979 1980 class UHUserAPIPersistent( URLHandler ): 1981 _relativeURL = "userAPI.py/persistent" 1979 1982 1980 1983 class UHUserAPIBlock( URLHandler ): -
indico/htdocs/userAPI.py
re70aac rc004bc 8 8 return api.RHUserAPICreate(req).process(params) 9 9 10 def persistent(req, **params): 11 return api.RHUserAPIPersistent(req).process(params) 12 10 13 def block(req, **params): 11 14 return api.RHUserAPIBlock(req).process(params) -
indico/web/http_api/auth.py
rf9e571 rc004bc 47 47 self._lastUseAuthenticated = False 48 48 self._oldKeys = PersistentList() 49 self._persistentAllowed = False 49 50 50 51 def getUser(self): … … 100 101 return self._oldKeys 101 102 103 def isPersistentAllowed(self): 104 return getattr(self, '_persistentAllowed', False) 105 106 def setPersistentAllowed(self, val): 107 self._persistentAllowed = val 108 102 109 def used(self, ip, path, query, authenticated): 103 110 self._lastUsedDT = datetime.datetime.now() -
indico/web/http_api/handlers.py
rf2757a rc004bc 75 75 76 76 77 def validateSignature( key, signature, timestamp, path, query):77 def validateSignature(ak, signature, timestamp, path, query): 78 78 ttl = HelperMaKaCInfo.getMaKaCInfoInstance().getAPISignatureTTL() 79 if not timestamp :79 if not timestamp and not ak.isPersistentAllowed(): 80 80 raise HTTPAPIError('Signature invalid (no timestamp)', apache.HTTP_FORBIDDEN) 81 elif abs(timestamp - int(time.time())) > ttl:81 elif timestamp and abs(timestamp - int(time.time())) > ttl: 82 82 raise HTTPAPIError('Signature invalid (bad timestamp)', apache.HTTP_FORBIDDEN) 83 digest = hmac.new( key, normalizeQuery(path, query), hashlib.sha1).hexdigest()83 digest = hmac.new(ak.getSignKey(), normalizeQuery(path, query), hashlib.sha1).hexdigest() 84 84 if signature != digest: 85 85 raise HTTPAPIError('Signature invalid', apache.HTTP_FORBIDDEN) … … 102 102 onlyPublic = False 103 103 if signature: 104 validateSignature(ak .getSignKey(), signature, timestamp, path, query)104 validateSignature(ak, signature, timestamp, path, query) 105 105 elif apiMode in (API_MODE_SIGNED, API_MODE_ALL_SIGNED): 106 106 raise HTTPAPIError('Signature missing', apache.HTTP_FORBIDDEN)
Note: See TracChangeset
for help on using the changeset viewer.
