Authentication code example

A code snippet that shows how to authenticate in Onna using the API


💡 1 min read

Authentication requires that you have an Onna account.

import json
import requests

base_url = 'https://enterprise.onna.com'
oauth_path = '/auth/oauth/'
user = "user@domain.com"
container = "container"
account = "account"

resp = requests.get(f'{base_url}/api/{container}/{account}/@oauthgetcode?client_id=canonical&scope={account}')
auth_code = resp.json()['auth_code']

payload = {'grant_type': "user",
           'code': auth_code,
           'username': "user@domain.com",
           'password': 'your-password',
           'scopes': [f"{account}"],
           'client_id': "canonical"
          }
headers = {'Accept': 'application/json'}
resp = requests.post(f'{base_url}/{oauth_path}/get_auth_token', headers=headers, data=json.dumps(payload))
jwt_token = resp.text

headers = {'Accept': 'application/json', 'Authorization': "Bearer {}".format(jwt_token)}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Last Updated: 11/18/2020, 8:14:23 AM