Wiki source code of 1. Registering an OIDC client
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | == Must read before starting == | ||
2 | |||
3 | It's very important to choose the right type of clients and to understand the various OAuth flows. | ||
4 | |||
5 | A very good documentation is this one : | ||
6 | |||
7 | [[https:~~/~~/auth0.com/docs/authorization/which-oauth-2-0-flow-should-i-use>>url:https://auth0.com/docs/authorization/which-oauth-2-0-flow-should-i-use]] | ||
8 | |||
9 | and another one | ||
10 | |||
11 | [[https:~~/~~/dzone.com/articles/the-right-flow-for-the-job-which-oauth-20-flow-sho>>url:https://dzone.com/articles/the-right-flow-for-the-job-which-oauth-20-flow-sho]] | ||
12 | |||
13 | Also a live exemple of client ID creation is available here on our lab, you can perfectly use this notebook to create your client, the next steps in this documentation reproduce the content of the notebook. | ||
14 | |||
15 | [[https:~~/~~/lab.ebrains.eu/user/user-redirect/lab/tree/shared/Collaboratory%20Community%20Apps/Managing%20an%20OpenID%20Connect%20client.ipynb>>https://lab.ebrains.eu/user/messines/lab/tree/shared/Collaboratory%20Community%20Apps/Managing%20an%20OpenID%20Connect%20client.ipynb]] | ||
16 | |||
17 | == Creating your OpenID Connect client == | ||
18 | |||
19 | The steps to create an OpenID Connect (OIDC) client are the following: | ||
20 | |||
21 | 1. Ask the developer accreditation to be authorize to create client | ||
22 | 1. get an access token from the `developer` client | ||
23 | 1. save your registration access token for further modifications of your client | ||
24 | 1. use the token to call the create endpoint | ||
25 | |||
26 | Note that a Jupyter Notebook notebook is available in the Drive of this collab to help you create and modify your OIDC client. Its name is: **//Managing an OpenID Connect client.ipynb//** [add link] | ||
27 | |||
28 | === Ask for developer accreditation === | ||
29 | |||
30 | To be authorize to create an OIDC client you have to be accredited as developer. | ||
31 | |||
32 | Please go on this page and "Request to join" the group [[https:~~/~~/wiki.ebrains.eu/bin/view/Identity/#/groups/app-collaboratory-iam~~-~~-service-providers>>https://wiki.ebrains.eu/bin/view/Identity/#/groups/app-collaboratory-iam--service-providers]] | ||
33 | |||
34 | We will quickly process your request and you will be able to create an OIDC client | ||
35 | |||
36 | === Fetching your developer access token === | ||
37 | |||
38 | Getting your developer token is done in one simple step: authenticate against the developer client with the password grant. | ||
39 | |||
40 | This can be achieved with this sample shell script: | ||
41 | |||
42 | {{code language="bash"}} | ||
43 | # Gather username and password from user | ||
44 | read -p 'Enter your username: ' clb_dev_username | ||
45 | read -s -p 'Enter your password: ' clb_dev_pwd | ||
46 | |||
47 | # Fetch the token | ||
48 | curl -X POST https://iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/token \ | ||
49 | -u developer: \ | ||
50 | -d 'grant_type=password' \ | ||
51 | --data-urlencode "username=${clb_dev_username}" \ | ||
52 | --data-urlencode "password=${clb_dev_pwd}" | | ||
53 | |||
54 | # and pretty-print the JSON response | ||
55 | json_pp | ||
56 | |||
57 | # Erase the credentials from local variables | ||
58 | clb_dev_pwd=''; clb_dev_username='' | ||
59 | {{/code}} | ||
60 | |||
61 | The response will be similar to: | ||
62 | |||
63 | {{code language="json"}} | ||
64 | { | ||
65 | "access_token": "eyJhbGci...", | ||
66 | "expires_in": 108000, | ||
67 | "refresh_expires_in": 14400, | ||
68 | "refresh_token": "eyJhbGci...", | ||
69 | "token_type": "bearer", | ||
70 | "not-before-policy": 1563261088, | ||
71 | "session_state": "0ac3dfcd-aa5e-42eb-b333-2f73496b81f8", | ||
72 | "scope": "" | ||
73 | } | ||
74 | {{/code}} | ||
75 | |||
76 | Store a copy of the "access_token" value. You will need if for the next step. | ||
77 | |||
78 | === Creating the client === | ||
79 | |||
80 | You can now create clients by sending a JSON representation to a specific endpoint: | ||
81 | |||
82 | {{code language="bash"}} | ||
83 | # Set your developer token | ||
84 | clb_dev_token="eyJhbGci..." | ||
85 | |||
86 | # Send the creation request | ||
87 | curl -X POST https://iam.ebrains.eu/auth/realms/hbp/clients-registrations/default/ \ | ||
88 | -H "Authorization: Bearer ${clb_dev_token}" \ | ||
89 | -H 'Content-Type: application/json' \ | ||
90 | -d '{ | ||
91 | "clientId": "my-awesome-client", | ||
92 | "name": "My Awesome App", | ||
93 | "description": "This describes what my app is for end users", | ||
94 | "rootUrl": "https://root.url.of.my.app", | ||
95 | "baseUrl": "/relative/path/to/its/frontpage.html", | ||
96 | "redirectUris": [ | ||
97 | "/relative/redirect/path", | ||
98 | "/these/can/use/wildcards/*" | ||
99 | ], | ||
100 | "webOrigins": ["+"], | ||
101 | "bearerOnly": false, | ||
102 | "consentRequired": true, | ||
103 | "standardFlowEnabled": true, | ||
104 | "implicitFlowEnabled": true, | ||
105 | "directAccessGrantsEnabled": false, | ||
106 | "attributes": { | ||
107 | "contacts": "first.contact@example.com; second.contact@example.com" | ||
108 | } | ||
109 | }' | | ||
110 | |||
111 | # Pretty print the JSON response | ||
112 | json_pp; | ||
113 | {{/code}} | ||
114 | |||
115 | In case of success, the endpoint will return its representation of your client: | ||
116 | |||
117 | {{code language="json"}} | ||
118 | { | ||
119 | "defaultClientScopes" : [ | ||
120 | "web-origins", | ||
121 | "roles" | ||
122 | ], | ||
123 | "redirectUris" : [ | ||
124 | "/relative/redirect/path", | ||
125 | "/these/can/use/wildcards/*" | ||
126 | ], | ||
127 | "nodeReRegistrationTimeout" : -1, | ||
128 | "rootUrl" : "https://root.url.of.my.app", | ||
129 | "webOrigins" : [ | ||
130 | "+" | ||
131 | ], | ||
132 | "authenticationFlowBindingOverrides" : {}, | ||
133 | "baseUrl" : "/relative/path/to/its/frontpage.html", | ||
134 | "description" : "This describes what my app is for end users", | ||
135 | "notBefore" : 0, | ||
136 | "frontchannelLogout" : false, | ||
137 | "enabled" : true, | ||
138 | "registrationAccessToken" : "eyJhbGciOi...", | ||
139 | "consentRequired" : true, | ||
140 | "fullScopeAllowed" : false, | ||
141 | "clientAuthenticatorType" : "client-secret", | ||
142 | "surrogateAuthRequired" : false, | ||
143 | "directAccessGrantsEnabled" : false, | ||
144 | "standardFlowEnabled" : true, | ||
145 | "id" : "551b49a0-ec69-41af-9461-6c10fbc79a35", | ||
146 | "attributes" : { | ||
147 | "contacts" : "first.contact@example.com; second.contact@example.com" | ||
148 | }, | ||
149 | "name" : "My Awesome App", | ||
150 | "secret" : "your-client-secret", | ||
151 | "publicClient" : false, | ||
152 | "clientId" : "my-awesome-client", | ||
153 | "optionalClientScopes" : [], | ||
154 | "implicitFlowEnabled" : true, | ||
155 | "protocol" : "openid-connect", | ||
156 | "bearerOnly" : false, | ||
157 | "serviceAccountsEnabled" : false | ||
158 | } | ||
159 | {{/code}} | ||
160 | |||
161 | Among all the attributes, you should securely save: | ||
162 | |||
163 | * your client **secret** ("secret" attribute): it is needed by your application to **authenticate to the IAM server** when making back-end calls | ||
164 | * your client **registration access token** ("registrationAccessToken"): you will need it to authenticate when **modifying your client in the future** | ||
165 | |||
166 | === Modifying your client === | ||
167 | |||
168 | Update your client with a PUT request: | ||
169 | |||
170 | {{code language="bash"}} | ||
171 | # Set your registration token and client id | ||
172 | clb_reg_token="eyJhbGciOi..." | ||
173 | clb_client_id="my-awesome-client" | ||
174 | |||
175 | # Update the client. Note that the client ID appears both in the endpoint URL and in the body of the request. | ||
176 | curl -X PUT https://iam.ebrains.eu/auth/realms/hbp/clients-registrations/default/${clb_client_id} \ | ||
177 | -H "Authorization: Bearer ${clb_reg_token}" \ | ||
178 | -H 'Content-Type: application/json' \ | ||
179 | -d '{ | ||
180 | "clientId": "'${clb_client_id}'", | ||
181 | "redirectUris": [ | ||
182 | "/relative/redirect/path", | ||
183 | "/these/can/use/wildcards/*", | ||
184 | "/a/new/redirect/uri" | ||
185 | ] | ||
186 | }' | | ||
187 | |||
188 | # Pretty print the JSON response | ||
189 | json_pp | ||
190 | |||
191 | {{/code}} | ||
192 | |||
193 | Note that your need to provide your client id both in the endpoint URL and within the body of the request. | ||
194 | |||
195 | {{warning}} | ||
196 | **⚠ Each time you modify your client, a new registration access token is generated. You need to keep track of your latest token to keep access to your client. ⚠** | ||
197 | {{/warning}} |