def __init__(
        self,
        master_secret=None,
        private_key=None,
        private_key_file=None,
        public_key=None,
        public_key_file=None,
        algorithm='HS256',
        expiration_delta=timedelta(minutes=30),
        leeway=0,
        allow_refresh=False,
        refresh_delta=timedelta(days=7),
        refresh_nonce_handler=None,
        verify_expiration_on_refresh=False,
        issuer=None,
        auth_header_prefix='JWT',
        userid_claim='sub'
    ):
        """Initiate the JWTIdentityPolicy with the given settings."""
        _public_key = master_secret
        if public_key is not None:
            _public_key = public_key
        if public_key_file is not None:
            with open(public_key_file, 'r') as key_pub_file:
                _public_key = key_pub_file.read()
        self.public_key = _public_key

        _private_key = master_secret
        if private_key is not None:
            _private_key = private_key
        if private_key_file is not None:
            with open(private_key_file, 'r') as key_priv_file:
                _private_key = key_priv_file.read()
        self.private_key = _private_key

        self.algorithm = algorithm

        if isinstance(expiration_delta, timedelta):
            expiration_delta = expiration_delta.total_seconds()
        self.expiration_delta = expiration_delta

        if leeway is None:
            leeway = 0
        elif isinstance(leeway, timedelta):
            leeway = leeway.total_seconds()
        self.leeway = leeway

        self.allow_refresh = allow_refresh

        if isinstance(refresh_delta, timedelta):
            refresh_delta = refresh_delta.total_seconds()
        self.refresh_delta = refresh_delta

        if isinstance(refresh_nonce_handler, str):
            self.refresh_nonce_handler = handler(refresh_nonce_handler)
        else:
            self.refresh_nonce_handler = refresh_nonce_handler
        self.verify_expiration_on_refresh = verify_expiration_on_refresh
        self.issuer = issuer
        self.auth_header_prefix = auth_header_prefix
        self.userid_claim = userid_claim
def __init__ ( self , master_secret = None , private_key = None , private_key_file = None , public_key = None , public_key_file = None , algorithm = 'HS256' , expiration_delta = timedelta ( minutes = 30 ) , leeway = 0 , allow_refresh = False , refresh_delta = timedelta ( days = 7 ) , refresh_nonce_handler = None , verify_expiration_on_refresh = False , issuer = None , auth_header_prefix = 'JWT' , userid_claim = 'sub' ) : _public_key = master_secret if public_key is not None : _public_key = public_key if public_key_file is not None : with open ( public_key_file , 'r' ) as key_pub_file : _public_key = key_pub_file . read ( ) self . public_key = _public_key _private_key = master_secret if private_key is not None : _private_key = private_key if private_key_file is not None : with open ( private_key_file , 'r' ) as key_priv_file : _private_key = key_priv_file . read ( ) self . private_key = _private_key self . algorithm = algorithm if isinstance ( expiration_delta , timedelta ) : expiration_delta = expiration_delta . total_seconds ( ) self . expiration_delta = expiration_delta if leeway is None : leeway = 0 elif isinstance ( leeway , timedelta ) : leeway = leeway . total_seconds ( ) self . leeway = leeway self . allow_refresh = allow_refresh if isinstance ( refresh_delta , timedelta ) : refresh_delta = refresh_delta . total_seconds ( ) self . refresh_delta = refresh_delta if isinstance ( refresh_nonce_handler , str ) : self . refresh_nonce_handler = handler ( refresh_nonce_handler ) else : self . refresh_nonce_handler = refresh_nonce_handler self . verify_expiration_on_refresh = verify_expiration_on_refresh self . issuer = issuer self . auth_header_prefix = auth_header_prefix self . userid_claim = userid_claim
Initiate the JWTIdentityPolicy with the given settings.