Skip to content

FileSystemTokenBackend doesn't support cryptography_manager parameter despite documentation suggesting encryption support #1185

@royhancn

Description

@royhancn

Bug Description

The FileSystemTokenBackend class constructor doesn't seem to accept a cryptography_manager parameter, despite this document suggested so: https://o365.github.io/python-o365/latest/usage/utils/token.html

Environment

  • O365 Version: 2.1.7
  • Python Version: 3.12.1
  • Operating System: Windows 11

Expected Behavior

cryptography_manager should be a valid parameter in FileSystemTokenBackend.

Actual Behavior

The FileSystemTokenBackend constructor only accepts token_path and token_filename parameters:

FileSystemTokenBackend.__init__(self, token_path=None, token_filename=None)

Attempting to pass a cryptography_manager parameter results in:

TypeError: FileSystemTokenBackend.__init__() got an unexpected keyword argument 'cryptography_manager'

Code to Reproduce

from O365 import Account, FileSystemTokenBackend
from cryptography.fernet import Fernet
import os

# This fails with TypeError
key = Fernet.generate_key()
f = Fernet(key)
token_backend = FileSystemTokenBackend(
    token_path="/path/to/tokens", 
    token_filename="token.txt", 
    cryptography_manager=f  # This parameter is not accepted
)

Investigation

I inspected the FileSystemTokenBackend class and confirmed its signature:

>>> from O365.utils.token import FileSystemTokenBackend
>>> import inspect
>>> print(inspect.signature(FileSystemTokenBackend.__init__))
(self, token_path=None, token_filename=None)

Suggested Solutions

class FileSystemTokenBackend:
    def __init__(self, token_path=None, token_filename=None, cryptography_manager=None):
        self.cryptography_manager = cryptography_manager

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions