vgrem / Office365-REST-Python-Client

Microsoft 365 & Microsoft Graph Library for Python
MIT License
1.24k stars 323 forks source link

Context expiry when using certificates #819

Open ssmails opened 4 months ago

ssmails commented 4 months ago

I am using the below with certificates to get the context for a site. Is it accurate to say that the context will expire when the certificate expires ? I don't see any option to explicitly close the context as part of this package. Assuming, as a client of this library, we don't need to close it.

     cert_credentials = {
        "tenant": tenant_id,
        "client_id": client_id,
        "thumbprint": cert_thumbprint,
        "private_key": cert_pem,
    }
    ctx = ClientContext(site_url).with_client_certificate(**cert_credentials)

Also, what would be the right way to check if the context is valid (just run some basic query on it) ?

Danxx26hub commented 4 months ago

When you create your cert you can select its lifespan. Once it expires your code will not be able to authenticate until you replace the cert and thumbprint.

ssmails commented 4 months ago

Also, what would be the right way to check if the context is valid (just run some basic query on it) ?

ssmails commented 4 months ago

And is it preferable to store and reuse the context associated with a site, or recreate as below each time we want to run a query on that site ?

ctx = ClientContext(site_url).with_client_certificate(**cert_credentials)

The reason I ask is because- we may be using this library wrapped into another SDK, where we deal with several sites.

ssmails commented 3 months ago

@vgrem Appreciate any help on this -

Is it preferable to store and reuse the context associated with a site, or recreate as below each time we want to run a query on that site ? Does the library provide any mechanism for us to reuse the site context ? If not, and we need to recreate the connection each time, is there any limit from Sharepoint that we should be aware of for the number of allowed connections to a particular site?

melihsunbul commented 1 month ago

@vgrem Appreciate any help on this -

Is it preferable to store and reuse the context associated with a site, or recreate as below each time we want to run a query on that site ? Does the library provide any mechanism for us to reuse the site context ? If not, and we need to recreate the connection each time, is there any limit from Sharepoint that we should be aware of for the number of allowed connections to a particular site?

Hi, did you able to find any answer for this question?