예제 #1
0
    def server(self):
        """
        All in one endpoints. This property is created automaticly
        if you have implemented all the getters and setters.
        """
        ctx = self.context
        cfg = ctx._config
        _validator = ctx.get('_validator', None)
        if _validator is not None:
            return Server(_validator)

        _clientgetter = ctx.get('_clientgetter', None)
        _tokengetter = ctx.get('_tokengetter', None)
        _tokensetter = ctx.get('_tokensetter', None)
        _noncegetter = ctx.get('_noncegetter', None)
        _noncesetter = ctx.get('_noncesetter', None)
        _grantgetter = ctx.get('_grantgetter', None)
        _grantsetter = ctx.get('_grantsetter', None)
        _verifiergetter = ctx.get('_verifiergetter', None)
        _verifiersetter = ctx.get('_verifiersetter', None)

        if _clientgetter is not None and \
            _tokengetter is not None and \
            _tokensetter is not None and \
            _noncegetter is not None and \
            _noncesetter is not None and \
            _grantgetter is not None and \
            _grantsetter is not None and \
            _verifiergetter is not None and \
            _verifiersetter is not None:

            validator = OAuth1RequestValidator(
                _clientgetter,
                _tokengetter,
                _tokensetter,
                _grantgetter,
                _grantsetter,
                _noncegetter,
                _noncesetter,
                _verifiergetter,
                _verifiersetter,
                config=cfg,
            )

            ctx._validator = validator
            server = Server(validator)
            testing = getattr(ctx.app, 'testing', False)
            if testing:
                # It will always be false, since the redirect_uri
                # didn't match when doing the testing
                server._check_signature = lambda *args, **kwargs: True
            return server
        raise RuntimeError(
            'oauth1 provider plugin not bound to required getters and setters')
예제 #2
0
    def server(self):
        """
        All in one endpoints. This property is created automaticly
        if you have implemented all the getters and setters.
        """
        if hasattr(self, '_validator'):
            return Server(self._validator)

        if hasattr(self, '_clientgetter') and \
           hasattr(self, '_tokengetter') and \
           hasattr(self, '_tokensetter') and \
           hasattr(self, '_noncegetter') and \
           hasattr(self, '_noncesetter') and \
           hasattr(self, '_grantgetter') and \
           hasattr(self, '_grantsetter') and \
           hasattr(self, '_verifiergetter') and \
           hasattr(self, '_verifiersetter'):

            validator = OAuth1RequestValidator(
                clientgetter=self._clientgetter,
                tokengetter=self._tokengetter,
                tokensetter=self._tokensetter,
                grantgetter=self._grantgetter,
                grantsetter=self._grantsetter,
                noncegetter=self._noncegetter,
                noncesetter=self._noncesetter,
                verifiergetter=self._verifiergetter,
                verifiersetter=self._verifiersetter,
                config=self.app.config,
            )

            self._validator = validator
            server = Server(validator)
            if self.app.testing:
                # It will always be false, since the redirect_uri
                # didn't match when doing the testing
                server._check_signature = lambda *args, **kwargs: True
            return server
        raise RuntimeError(
            'application not bound to required getters and setters'
        )
예제 #3
0
    def __init__(self,
                 pyramid_request,
                 validator_api_hooks=None,
                 validator_class=None):
        """Builds a new Provider

        :param pyramid_request: pyramid `request` object.
        :param validator_api_hooks: A subclass of `base_OAuth1RequestValidator_Hooks`
        :param validator_class: A subclass of `OAuth1RequestValidator` or None
            (defaults to OAuth1RequestValidator)
        """
        self.pyramid_request = pyramid_request
        self._validator_api_hooks = validator_api_hooks
        self._validator_class = validator_class or OAuth1RequestValidator

        self._validator = self._validator_class(
            pyramid_request, validator_api_hooks=self._validator_api_hooks)
        self.server = Server(self._validator)