Using Pydio Cells API with python

I wrote to migrate Old Ajaxplorer to Pydio 8 but not migrate the server yet so I’m trying to adapt it to Pydio Cells.
I try searching some doc about OAuth2 with python but I didn’t found anything working yet with Pydio Cells API.
I’m able to retrieve an authentication token but not able to do a request on the API. I also try some libs like OAuthlib but no success.

Does anyone use this API with Python?

Hi,

I do not personally use the Pydio Cells API with python, but I know it is used internally, among others within the sync process.

Yet, once you get a valid JWT token, querying the API should be language agnostic and straight forward.

You should only add following header to your request:

key: Authorization
value: Bearer

Format of the value is “Bearer” then one space, then the value of the retrieved token as string.

Note that the JWT token for the API as a quite short validity period (10mn).

Let me know if it helps or please add further details.

Cheers,

Bruno

Hi,

I finally be able to have something working by building requests and headers. But it would be nice to use an advanced lib like OAuthlib to manage and refresh token properly but it’s could enough for scripting.
Is it possible to increase the token validity period?

An example of API request:

import requests, json, string, random

token_url = '[DEX Endpoint]/dex/token'
api_url = '[API Endpoint]'

client_id = '[DEX Client ID]'
client_secret = '[DEX Client Secret]'
username = '[USERNAME]'
password = '[PASSWORD]'

api_session = requests.session()
api_session.headers['Cache-Control'] = 'no-cache'

api_session.verify = False
requests.packages.urllib3.disable_warnings()

def generate_pwd(N=8, lower=True, upper=True, digits=True, ponctuation=False):
    chars = ''
    chars += string.ascii_lowercase if lower else ''
    chars += string.ascii_uppercase if upper else ''
    chars += string.digits if digits else ''
    chars += string.punctuation if ponctuation else ''
    pwd = ''
    for _ in range(N):
        pwd += random.choice(chars)
    return pwd

res = api_session.post(token_url,
                    auth=(client_id,client_secret),
                    headers={
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                    data={
                        'grant_type':'password',
                        'username':username,
                        'password':password,
                        'scope':'email profile pydio',
                        'nonce':generate_pwd(16)
                    }
)

id_token = res.json()['id_token']

api_session.headers['Authorization'] = 'Bearer {0}'.format(id_token)
res = api_session.get(api_url + "/config/datasource")
print res.content

Yes, you can extends JWT validity period by manually editing the pydio.json config file that is in your installation directory (typically: ~/.config/pydio/cells/pydio.json, if you installed it on a linux machine folloing the Admin Guide)

You can then edit this parameter:

“expiry”: {
“idTokens”: “10m”
},