Authentication¤
The first thing you'll need in order for you to be able to use the LumApps Api's is a valid token.
You can see them here
The LumApps sdk can help you when using a service account or a regular token, all you have to do is to give the sdk the credentials infos and the subsequent calls made by the tool will be authenticated using those credentials.
Note:
Be sure to target the right lumapps environment, by default the sdk use site.lumapps.com as an environment. If your env is different (eg, sites-ms.lumapps.com) you can precise it like so:
from lumapps.api.base_client import BaseClient
api_info = {
"base_url": "https://sites-ms.lumapps.com"
}
client = BaseClient(token="<your_token>", api_info=api_info)
Using a regular token¤
To authenticate with a regular, short lived token, instanciate the sdk like so:
from lumapps.api.base_client import BaseClient
client = BaseClient(token="<your_token>")
Using an authorized service account¤
By default a service account does not allows you to contact all LumApps API endpoints, to do so you need to get a token as a given user and then use this token to authenticate the requests
An example with curl
The flow is as follow:
-
With your service account get a google access token
To know how to get this token with curl and you service account follow this tutorial
For an extended documentation on that process you can follow the google documentation -
Use this token as the bearer token to call the user/get endpoint
curl -s -X GET https://
/_ah/api/lumsites/v1/user/getToken?customerId= &email= \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " -
Use the returned LumApps access token to authenticate your subsequent requests to LumApps Api's.
For instance you can call the user/get endpoint:curl -s -X GET https://
/_ah/api/lumsites/v1/user/get \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer "
An example with Postman
The flow is the same as with curl but to do it with postman there are some specificities and that's why we provide a collection that illustrate it.
This collection uses postman variables and you have to set some to use it:
- sa_private_key: Private of the service account
- sa_email: Service account email
- lumapps_base_env_url: The base url of the LumApps env (eg, https://sites.lumapps.com)
You'll also have to execute in order, the requests are numbered so make sure to execute them from 1 to 4.
With the LumApps sdk
The sdk BaseClient offers two methods to help with that `get_new_client_as` and `get_new_client_as_using_dwd` that allows you to get a new BaseClient correctly authenticated.
from lumapps.api.base_client import BaseClient
my_service_account = {...}
my_platform_id="<your_plaform_id>"
user_to_authenticate_on_behalf_of = "<user_email>"
client = BaseClient(
auth_info=my_service_account)
.get_new_client_as(
user_email=user_to_authenticate_on_behalf_of,
customer=platform_id
)
Note:
The LumApps bearer token you get in that case extends to 24h instead of 1h.