Skip to content
Snippets Groups Projects
grdf.md 7.19 KiB

Grdf Adict Konnector

This konnector fetches consumption measures from Grdf Adict API. This is an Oauth Konnector, meaning the authentication performed to access all data is made following an Oauth2 protocol. You can clone the project here.

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/oauth/

The Oauth protocol does not take place in the konnector code, therefore it is also important to take a look at the proxy documentation to fully understand all the interactions that will be told below.

All the actions performed by the stack are targeted from pre-registered parameters, 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

On its first launch, following the Oauth Client Connect authentication.

  • The cozy stack calls the authentication_endpoint and start the oauth protocol, see proxy doc.
  • 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 data, including the pce_id (id of user's meter) that will be needed further to fetch user's data.

  • 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).

  • Konnector restarts, this time knowing a pce_id, it fails to fetch data 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 everything needed in database to fetch data and store them in CouchDB.

  • Further jobs will not need to change scope again and will only ask for refresh tokens.