Skip to content

Commit

Permalink
authentication: Update calls to use the new client id/secret
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Moser committed Jun 11, 2020
1 parent 2218094 commit b6100e9
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions source/guidelines/authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,27 @@ is the method shown here.

.. rubric:: Request an access token

In order to receive an access token, you need in advance to have
credentials for the Open Data Hub. If you do not have them, please
open a ticket on issues.opendatahub.bz.it or send an email to
:email:`help@opendatahub.bz.it`.

With your username and password
(:strong:`my_username`. :strong:`my_password`), the access token is
granted to you with the following call:
In order to receive an access token, you need in advance to have credentials for
the Open Data Hub. If you do not have them, please open a ticket on
issues.opendatahub.bz.it or send an email to :email:`help@opendatahub.bz.it`.
The same holds, if you plan to create an application that retrieves closed data
from the Open Data Hub. For this, also other OAuth2 flows exist.

With your username and password, and a client secret (:strong:`my_username`,
:strong:`my_password`, :strong:`the_client_secret`), the access token is granted
to you with the following call:

.. code-block:: bash
:name: grant-token
:caption: Receiving an access topic
curl -X POST -L -H 'Content-Type:application/x-www-form-urlencoded' \
"https://auth.opendatahub.bz.it/auth/realms/noi/protocol/openid-connect/token" \
-d 'grant_type=password&username=my_username&password=my_password&client_id=odh-mobility-v2'
curl -X POST -L "https://auth.opendatahub.bz.it/auth/realms/noi/protocol/openid-connect/token" \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=my_username' \
--data-urlencode 'password=my_password' \
--data-urlencode 'client_id=odh-generic-client' \
--data-urlencode 'client_secret=the_client_secret'
Since the token expires after a given amount of time, it might prove
necessary to refresh it, an action that can be done by replacing the
Expand All @@ -130,9 +135,12 @@ parameters given in the query above with
:name: refresh-token
:caption: Refreshing the access token
curl -X POST -L -H 'Content-Type:application/x-www-form-urlencoded' \
"https://auth.opendatahub.bz.it/auth/realms/noi/protocol/openid-connect/token" \
-d 'grant_type=refresh_token&refresh_token=*****&client_id=odh-mobility-v2'
curl -X POST -L "https://auth.opendatahub.bz.it/auth/realms/noi/protocol/openid-connect/token" \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=refresh_token' \
--data-urlencode 'refresh_token=the_refresh_token' \
--data-urlencode 'client_id=odh-generic-client' \
--data-urlencode 'client_secret=the_client_secret'
Here, use the refresh token received from :numref:`grant-token`.

Expand All @@ -147,10 +155,9 @@ requests. The following API call shows how to get all
:name: get-closed-data
:caption: Retrieving data with the access token
curl -X GET \
'https://mobility.api.opendatahub.bz.it/v2/api/flat/VMS/*/latest?select=sname,mvalue' \
-H 'content-type: application/json' \
-H 'Authorization: bearer your-access-token'
curl -X GET "https://mobility.api.opendatahub.bz.it/v2/flat/VMS/*/latest?select=sname,mvalue" \
--header 'Content-Type: application/json' \
--header 'Authorization: bearer your-access-token'
Currently, data retrieved from the Open Data Hub are always open,
except for some of the latest values and historical data: Only a
Expand Down

4 comments on commit b6100e9

@stefanodavid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Piiit would it be possible to open issues for every change instead of committing code directly on master, in order to keep track of changes you make? Thanks!

@Piiit
Copy link
Contributor

@Piiit Piiit commented on b6100e9 Jun 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefanodavid You mean create a PR for the changes?

@stefanodavid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Piiit I try to be very precise, open issues even for small changes in order to be tracked by everyone and keeps things ordered. If you commit some change directly into master branch, everything you do is almost unknown to me. In this particular case I realised that you changed something directly on master branch only after half an hour of trying to understand why on the fancy earth I had completely different calls in the same file in different branches.

@Piiit
Copy link
Contributor

@Piiit Piiit commented on b6100e9 Jun 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefanodavid It is good that you are precise, but this is a shared project, so in the future it is even possible that we have several authors, and some small bugfixes must be done fast and direct, otherwise I fear that we do not have the time to discuss every little bit. For bigger changes, or discussions you are absolutely right, that we should not commit directly to the master branch.

This was a PR review, where some small things were missing, so I fixed them directly and moved on...
Shared code ownership is a best practice in open source projects, so you need to check master from time to time and sync it with your working branch... if you need help with that I can show you how it works.

We will prepare additional documentation about these workflows, because several people complained about changing branches and merge conflicts. So, we are preparing workflow images etc.... currently to better understand how things work

Please sign in to comment.