Skip to content
Snippets Groups Projects
grdf.md 3.31 KiB
Newer Older
  • Learn to ignore specific revisions
  • !!! info ""
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
        :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.
    
    ![grdfgrandlyon account](/img/grdf_account.jpg)
    
    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
    
    ![Konnector flow](/img/flowgrdf.jpeg)
    
    !!! 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).