Changeset c004bc in indico


Ignore:
Timestamp:
11/25/11 09:26:26 (19 months ago)
Author:
Jose Benito <jose.benito.gonzalez@…>
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)
Message:

[IMP] Support persistent api requests (w/o tstamp)

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • doc/guides/ExportAPI/access.rst

    rcd4e48 rc004bc  
    8080You can find example code for Python and PHP in the following sections. 
    8181 
     82If persistent signatures are enabled, you can also omit the timestamp. 
     83In this case the URL is valid forever. When using this feature, please 
     84make sure to use these URLs only where necessary - use timestamped 
     85URLs whenever possible. 
     86 
    8287Request Signing for Python 
    8388^^^^^^^^^^^^^^^^^^^^^^^^^^ 
     
    9196 
    9297 
    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): 
    9499        items = params.items() if hasattr(params, 'items') else list(params) 
    95100        if api_key: 
     
    98103            items.append(('onlypublic', 'yes')) 
    99104        if secret_key: 
    100             items.append(('timestamp', str(int(time.time())))) 
     105            if not persistent: 
     106                items.append(('timestamp', str(int(time.time())))) 
    101107            items = sorted(items, key=lambda x: x[0].lower()) 
    102108            url = '%s?%s' % (path, urllib.urlencode(items)) 
     
    125131    <?php 
    126132 
    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) { 
    128134        if($api_key) { 
    129135            $params['apikey'] = $api_key; 
     
    135141 
    136142        if($secret_key) { 
    137             $params['timestamp'] = time(); 
     143            if(!$persistent) { 
     144                $params['timestamp'] = time(); 
     145            } 
    138146            uksort($params, 'strcasecmp'); 
    139147            $url = $path . '?' . http_build_query($params); 
  • indico/MaKaC/webinterface/rh/api.py

    rfcdc60 rc004bc  
    4747            ak.newKey() 
    4848            ak.newSignKey() 
     49        self._redirect(urlHandlers.UHUserAPI.getURL(self._avatar)) 
     50 
     51class 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()) 
    4964        self._redirect(urlHandlers.UHUserAPI.getURL(self._avatar)) 
    5065 
  • indico/MaKaC/webinterface/tpls/UserAPI.tpl

    rcd4e48 rc004bc  
    6161            <td> 
    6262                % 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.'));"> 
    6464                        <input type="submit" value="${_('Create API key')}" /> 
    6565                    </form> 
    6666                % 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!'));"> 
    6868                        <input type="submit" value="${_('Create a new API key pair')}" /> 
    6969                    </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 
    7079                % endif 
    7180            </td> 
  • indico/MaKaC/webinterface/urlHandlers.py

    raba8f4 rc004bc  
    19771977class UHUserAPICreate( URLHandler ): 
    19781978    _relativeURL = "userAPI.py/create" 
     1979 
     1980class UHUserAPIPersistent( URLHandler ): 
     1981    _relativeURL = "userAPI.py/persistent" 
    19791982 
    19801983class UHUserAPIBlock( URLHandler ): 
  • indico/htdocs/userAPI.py

    re70aac rc004bc  
    88    return api.RHUserAPICreate(req).process(params) 
    99 
     10def persistent(req, **params): 
     11    return api.RHUserAPIPersistent(req).process(params) 
     12 
    1013def block(req, **params): 
    1114    return api.RHUserAPIBlock(req).process(params) 
  • indico/web/http_api/auth.py

    rf9e571 rc004bc  
    4747        self._lastUseAuthenticated = False 
    4848        self._oldKeys = PersistentList() 
     49        self._persistentAllowed = False 
    4950 
    5051    def getUser(self): 
     
    100101        return self._oldKeys 
    101102 
     103    def isPersistentAllowed(self): 
     104        return getattr(self, '_persistentAllowed', False) 
     105 
     106    def setPersistentAllowed(self, val): 
     107        self._persistentAllowed = val 
     108 
    102109    def used(self, ip, path, query, authenticated): 
    103110        self._lastUsedDT = datetime.datetime.now() 
  • indico/web/http_api/handlers.py

    rf2757a rc004bc  
    7575 
    7676 
    77 def validateSignature(key, signature, timestamp, path, query): 
     77def validateSignature(ak, signature, timestamp, path, query): 
    7878    ttl = HelperMaKaCInfo.getMaKaCInfoInstance().getAPISignatureTTL() 
    79     if not timestamp: 
     79    if not timestamp and not ak.isPersistentAllowed(): 
    8080        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: 
    8282        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() 
    8484    if signature != digest: 
    8585        raise HTTPAPIError('Signature invalid', apache.HTTP_FORBIDDEN) 
     
    102102    onlyPublic = False 
    103103    if signature: 
    104         validateSignature(ak.getSignKey(), signature, timestamp, path, query) 
     104        validateSignature(ak, signature, timestamp, path, query) 
    105105    elif apiMode in (API_MODE_SIGNED, API_MODE_ALL_SIGNED): 
    106106        raise HTTPAPIError('Signature missing', apache.HTTP_FORBIDDEN) 
Note: See TracChangeset for help on using the changeset viewer.