diff --git a/docs/img/flowgrdf.jpeg b/docs/img/flowgrdf.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..19eeea5ba967111c07ced2ec62ece0197feec0d5 Binary files /dev/null and b/docs/img/flowgrdf.jpeg differ diff --git a/docs/img/grdf_account.jpg b/docs/img/grdf_account.jpg new file mode 100644 index 0000000000000000000000000000000000000000..039c7d85460b86985db2ecab45ae7e1f9516e339 Binary files /dev/null and b/docs/img/grdf_account.jpg differ diff --git a/docs/konnectors/grdf.md b/docs/konnectors/grdf.md index 2f4f692dba5c6228a0130fccce621b4c7e2d7452..9bdb52c1e661dae48904f63f6d09f88db674dc15 100644 --- a/docs/konnectors/grdf.md +++ b/docs/konnectors/grdf.md @@ -1,2 +1,61 @@ !!! info "" - :construction: Section under Construction :construction: \ No newline at end of file + :construction: Section under Construction :construction: + +This konnector fetches consumptions measures from Grdf Adict API. This is an Oauth Konnector, meaning the authentification performed to access all data is made following an Oauth2 protocol. +You can clone the project [here](https://forge.grandlyon.com/web-et-numerique/llle_project/grdf-adict-konnector). + +You should also check Cozy's official documentations for konnectors : +[https://docs.cozy.io/en/tutorials/konnector/getting-started/](https://docs.cozy.io/en/tutorials/konnector/getting-started/) +[https://docs.cozy.io/en/tutorials/konnector/oauth/](https://docs.cozy.io/en/tutorials/konnector/oauth/) + +## Grdf Adict Konnector + +The Oauth protocol does not take place in the konnector code, therefore it is also important to take a look at the [proxy](../proxy/description.md) to fully understand all the interactions that will be told below. + +All the actions performed by the stack are targetted from pre-registered paramaters, here is the list of all parameters needed by the stack to perform the Oauth protocol and allow the konnector to fetch data. + + + +On its first launch, following the Oauth Client Connect authentification. + +- The cozy stack calls the **authentification_endpoint** and start the oauth protocol, see [proxy doc](../proxy/description.md). +- The account has now an access_token and an id_token from the oauth call + +!!! info "" + id_token is only given when requesting the token endpoint in *authorization_code* grant_type. + This token holds several meta datas, including the pce_id (id of user's meter) that will be needed further to fetch user's datas. + +- Konnector starts, fails to find a pce_id in database on first launch therefore decodes the id_token to store the pce_id in db (see [addData](https://docs.cozy.io/en/cozy-konnector-libs/api/#adddata_1)). +- Konnector restarts, this time knowing a pce_id, it fails to fetch datas because the access_token from oauth call has a reduced scope (only scoping for meta data requests). +- Konnector launches a refresh call, the proxy knows to answer it with a *client_credentials* grant_type call to grdf /access_token. +- Konnector restarts with everyting needed in database to fetch datas and store them in couchdb. + +- Further jobs will not need to change scope again and will only ask for refresh tokens. + + +### Flow summarized + + + +!!! info "to do" + :construction: Request PCE's frequency :construction: + Grdf owns different type of meters, some are read twice a year (every six months therefore called 6M), others are 1M or 1D + +## Launch on standalone + +In the project repository type `yarn standalone` to launch the konnector without a cozy stack running. + +## Installation + +Build the konnector with `yarn build`. + +### Install on easy-cozy (development purposes) + +```sudo docker cp /home/easy-cozy/fun/grdf-konnector/build/ $container_id:/tmp/grdf-oauth``` + +```sudo docker-compose exec cozy ./cozy konnectors install grdf-oauth --domain "$alphaDomain" file:///tmp/grdf-oauth $container_id ``` + +### Install on production + +Type `yarn deploy` to build on a dedicated branch. +Build branch is stored as a docker image in a registry : [Container Registry](https://forge.grandlyon.com/web-et-numerique/llle_project/grdf-adict-konnector/container_registry).