Skip to content

[Bug]: joserfc>1.6.8 breaks diracx #943

Description

@chaen

Search before creating an issue

  • I have searched existing issues and confirmed this is not a duplicate

Bug Description

pixi run pytest-diracx-routers tests/auth/test_legacy_exchange.py::test_valid --no-cov -s

Definitely related to authlib/joserfc#99

../diracx-logic/src/diracx/logic/auth/token.py:368: in create_token                                                                                     
    return _sign_token_payload(payload.model_dump(), settings)                                                                                          
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                          
../diracx-logic/src/diracx/logic/auth/token.py:385: in _sign_token_payload                                                                              
    return jwt.encode(                                                      
../.pixi/envs/diracx-routers/lib/python3.11/site-packages/joserfc/jwt.py:83: in encode                                                                                                                                                                                                                          
    return serialize_compact(_header, payload, key, algorithms, registry)                                                                               
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                               
../.pixi/envs/diracx-routers/lib/python3.11/site-packages/joserfc/jws.py:119: in serialize_compact                                                                                                                                                                                                              
    out = sign_compact(obj, alg, key)                                       
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^                                       
../.pixi/envs/diracx-routers/lib/python3.11/site-packages/joserfc/_rfc7515/compact.py:26: in sign_compact                                                                                                                                                                                                       
    signature = urlsafe_b64encode(alg.sign(signing_input, key))                                                                                         
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                          
../.pixi/envs/diracx-routers/lib/python3.11/site-packages/joserfc/_rfc9864/jws_eddsa.py:24: in sign                                                                                                                                                                                                             
    op_key = t.cast(t.Union[Ed25519PrivateKey, Ed448PrivateKey], key.get_op_key("sign"))                                                                                                                                                                                                                        
                                                                 ^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                         
../.pixi/envs/diracx-routers/lib/python3.11/site-packages/joserfc/_rfc7517/models.py:256: in get_op_key                                                                                                                                                                                                         
    self.check_key_op(operation)                                            
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _                                                                                                                                         

self = <joserfc._rfc8037.okp_key.OKPKey object at 0x7fb3ea199950>, operation = 'sign'                                                                                                                                                                                                                           

    def check_key_op(self, operation: str) -> None:                                                                                                     
        """Check if the given key_op is supported by this key.                                                                                          
                                                                            
        :param operation: key operation value, such as "sign", "encrypt".                                                                               
        :raise UnsupportedKeyOperationError: if the operation is not supported by this key.                                                                                                                                                                                                                     
        """                                                                 
        key_ops = self.get("key_ops")                                       
        if key_ops is not None and operation not in key_ops:                                                                                            
            raise UnsupportedKeyOperationError(f"Unsupported key_op '{operation}'")                                                                     
                                                                            
        assert operation in self.operation_registry                                                                                                     
        reg = self.operation_registry[operation]                                                                                                        
        if reg.private and not self.is_private:                                                                                                         
>           raise UnsupportedKeyOperationError(f"Invalid key_op '{operation}' for public key")                                                                                                                                                                                                                  
E           joserfc.errors.UnsupportedKeyOperationError: unsupported_key_operation: Invalid key_op 'sign' for public key                                                                                                                                                                                        

../.pixi/envs/diracx-routers/lib/python3.11/site-packages/joserfc/_rfc7517/models.py:247: UnsupportedKeyOperationError                                                                                                                                                                                          
=========================================================================== warnings summary ============================

Steps to Reproduce

No response

Expected Behavior

No response

Actual Behavior

No response

Environment

No response

Relevant Log Output

Additional Context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions