~roadmr/canonical-identity-provider/fix-deprecation-warnings-1

« back to all changes in this revision

Viewing changes to src/identityprovider/auth.py

  • Committer: Tom Wardill
  • Date: 2018-02-14 14:05:59 UTC
  • mfrom: (1602 work)
  • mto: (1597.1.44 django-1.10)
  • mto: This revision was merged to the branch mainline in revision 1603.
  • Revision ID: tom.wardill@canonical.com-20180214140559-ow5txzwy46nopws2
Merge flake8 changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from django.core.cache import cache
22
22
from django.core.exceptions import ValidationError
23
23
from django.http import HttpResponse
 
24
from django.utils.timezone import now
24
25
from django.utils.translation import ugettext_lazy as _
25
 
from django.utils.timezone import now
 
26
from oauth_backend.models import Token as V1Token
26
27
from oauthlib.oauth1 import RequestValidator, ResourceEndpoint
27
28
from pymacaroons import Macaroon, Verifier
28
29
 
29
 
from identityprovider.login import AuthenticationError, AccountDeactivated
 
30
from identityprovider.login import AccountDeactivated, AuthenticationError
30
31
from identityprovider.models import (
31
32
    Account,
32
33
    AccountPassword,
41
42
    maybe_contextmanager,
42
43
)
43
44
from identityprovider.utils import (
44
 
    validate_launchpad_password, get_object_or_none)
45
 
from oauth_backend.models import Token as V1Token
 
45
    get_object_or_none, validate_launchpad_password)
46
46
 
47
47
 
48
48
logger = logging.getLogger(__name__)
477
477
                token_filter_fn=token_allowed)
478
478
        except ValueError:
479
479
            valid = False
480
 
        except:
 
480
        except Exception:
481
481
            logger.exception(
482
482
                'SSOOAuthAuthentication.is_authenticated: could not validate:')
483
483
            raise
504
504
        # isolate 3rd-party caveat that concerns to us (hinted by 'location')
505
505
        (sso_caveat,) = [c for c in macaroon.third_party_caveats()
506
506
                         if c.location == settings.MACAROON_SERVICE_LOCATION]
507
 
    except:
 
507
    except Exception:
508
508
        # the macaroon doesn't have a location for this service
509
509
        raise AuthenticationError("The received macaroon is not for ours")
510
510
 
534
534
        caveat_info = json.loads(raw_caveat_id)
535
535
        function = _open_caveat_v1
536
536
        stats_key = '1'
537
 
    except:
 
537
    except Exception:
538
538
        # bad data, or maybe the v0 (unversioned, really) format
539
539
        caveat_info = raw_caveat_id
540
540
        function = _open_caveat_v0
542
542
 
543
543
    try:
544
544
        caveat_info = function(caveat_info)
545
 
    except:
 
545
    except Exception:
546
546
        raise ValidationError("Bad info in the caveat_id")
547
547
 
548
548
    stats.increment('macaroon.auth.caveat_version', key=stats_key)
595
595
    """
596
596
    try:
597
597
        root_macaroon = Macaroon.deserialize(root_macaroon_raw)
598
 
    except:
 
598
    except Exception:
599
599
        raise ValidationError("The received Macaroon is corrupt")
600
600
 
601
601
    # get the raw caveat id and the decrypted deserialized info
651
651
            v.verify(macaroon, key)
652
652
        else:
653
653
            v.verify(macaroon, key, [discharge])
654
 
    except:
 
654
    except Exception:
655
655
        raise AuthenticationError("Not verifying macaroons")
656
656
 
657
657
    # verify that the account is still active and password didn't change
671
671
    """Refresh a discharge with a new discharge macaroon."""
672
672
    try:
673
673
        discharge_macaroon = Macaroon.deserialize(discharge_macaroon_raw)
674
 
    except:
 
674
    except Exception:
675
675
        raise ValidationError("The received Macaroons are corrupt")
676
676
 
677
677
    # get the decrypted deserialized info