Wiki source code of Community App Developer Guide

Version 10.1 by allan on 2019/11/26 16:55

Hide last authors
allan 4.3 1 Developers can extend the Collaboratory capabilities by providing applications to its community of users.
allan 1.1 2
allan 4.3 3 This guide describes the steps to make this possible.
allan 1.1 4
5 == Becoming a contributor ==
6
allan 9.1 7 The first step is for you to **get the developer accreditation**. Contributors can register and manage applications within the Community Apps Catalogue.
allan 1.1 8
allan 4.3 9 Send an email to [[support@humanbrainproject.eu>>mailto:support@humanbrainproject.eu]] with a short summary of your intentions.
allan 1.1 10
allan 4.3 11 The support team will apply the permissions to your user: your account will be upgraded with developers privileges the next time you will login.
allan 1.1 12
13 (% class="box infomessage" %)
14 (((
allan 9.1 15 Only SGA2 accredited users will be automatically granted the developer accreditation.
allan 1.1 16 )))
17
allan 10.1 18 (% class="wikigeneratedid" %)
19 == Making your app available to users ==
allan 1.1 20
allan 9.1 21 In order for you application to be installable by users, it needs to be registered within the [[Community Apps Catalogue>>doc:Apps.WebHome]].
allan 2.1 22
allan 10.1 23 Once this simple step is complete, users will be able to install your app within their collabs.
24
25 === Registering an application in the Catalogue ===
26
allan 9.1 27 Navigate to the catalogue and click on **+Create App** in the top right corner. Enter a name for your app and click on **Create**.
allan 2.1 28
allan 9.1 29 Fill the form with the following information:
30
31 * **main URL**: the URL of the homepage of your app. This is where user will be directed when then open your app in a collab.
32 * **settings URL**: the URL of the your settings management page if you have one.
33 * **description**: a description of what your app does to help users select it.
34 * **under development?**: should be checked if you don't want your app to be available by default by other users.
35 * **category**: a category to help structuring the applications.
36 * **maintainers**: a list of users who maintain the app. The users need to have logged in the wiki at least once to be found. Maintainers are granted the right to modify an app registration.
37 * **documentation URL**: if your app has online user documentation, a link will be provided to users when they use your app.
38 * **repository**: a URL to a public repository so users can check the sources of your app.
39
40 Click on **Save**. Your app is now registered and waiting for users to install it!
41
allan 10.1 42 === Installing your app in a collab ===
43
44 1. In order to install your app, you need to navigate to a collab where you have either the **editor** or **administrator** role.
45 1. Click on **Create**. Enter a title for this instance of your app and select **Community App** in the right selector.
46 1. Click on **Create**. You will be presented with the Community App Catalogue. The app you will see are the public apps and the ones your a maintainer of.
47 1. Select your app and click on **Save and View**.
48
49 You should now see how your app looks like within a collab.
50
allan 2.1 51 == Creating your OpenID Connect client ==
52
53 The steps to create an OpenID Connect client are the following:
54
allan 3.2 55 1. get an access token from the `developer` client
56 1. use the token to call the create endpoint
57 1. save your registration access token for further modifications of your client
allan 2.1 58
59 === Fetching your developer access token ===
60
allan 4.3 61 Getting your developer token is done in one simple step: authenticate against the developer client with the password grant.
allan 2.1 62
allan 3.2 63 This can be achieved with this sample shell script:
allan 2.1 64
65 {{code language="bash"}}
66 # Gather username and password from user
allan 2.2 67 echo '\nEnter your username' && read clb_dev_username &&
68 echo '\nEnter your password' && read -s clb_dev_pwd &&
allan 2.1 69
70 # Fetch the token
71 curl -X POST https://iam.humanbrainproject.eu/auth/realms/hbp/protocol/openid-connect/token \
72 -u developer: \
73 -d 'grant_type=password' \
74 -d "username=${clb_dev_username}" \
allan 2.2 75 -d "password=${clb_dev_pwd}" |
76
77 # Prettify the JSON response
78 json_pp;
allan 2.1 79
80 # Erase the credentials from local variables
81 clb_dev_pwd='';clb_dev_username=''
82 {{/code}}
83
84 The response will be similar to:
85
86 {{code language="json"}}
87 {
88 "access_token": "eyJhbGci...",
89 "expires_in": 108000,
90 "refresh_expires_in": 14400,
91 "refresh_token": "eyJhbGci...",
92 "token_type": "bearer",
93 "not-before-policy": 1563261088,
94 "session_state": "0ac3dfcd-aa5e-42eb-b333-2f73496b81f8",
95 "scope": ""
96 }
97 {{/code}}
98
allan 4.3 99 Copy the "access_token" value, you will need if for the next step.
allan 2.2 100
101 === Creating the client ===
102
allan 4.3 103 You can now create clients by sending a JSON representation to a specific endpoint:
allan 2.3 104
105 {{code language="bash"}}
106 # Set your developer token
107 clb_dev_token=...
108
109 # Send the creation request
110 curl -X POST https://iam.humanbrainproject.eu/auth/realms/hbp/clients-registrations/default/ \
111 -H "Authorization: Bearer ${clb_dev_token}" \
112 -H 'Content-Type: application/json' \
113 -d '{
114 "clientId": "my-awesome-client",
115 "name": "My Awesome App",
116 "description": "This describes what my app is for end users",
117 "rootUrl": "https://root.url.of.my.app",
118 "baseUrl": "/relative/path/to/its/frontpage.html",
119 "redirectUris": [
120 "/relative/redirect/path",
121 "/these/can/use/wildcards/*"
122 ],
123 "webOrigins": ["+"],
124 "bearerOnly": false,
125 "consentRequired": true,
126 "standardFlowEnabled": true,
127 "implicitFlowEnabled": true,
128 "directAccessGrantsEnabled": false,
129 "attributes": {
130 "contacts": "first.contact@example.com; second.contact@example.com"
131 }
132 }' |
133
134 # Prettify the JSON response
135 json_pp;
136 {{/code}}
137
138 In case of success, the endpoint will return its representation of your client:
139
140 {{code language="json"}}
141 {
142 "defaultClientScopes" : [
143 "web-origins",
144 "roles"
145 ],
146 "redirectUris" : [
147 "/relative/redirect/path",
148 "/these/can/use/wildcards/*"
149 ],
150 "nodeReRegistrationTimeout" : -1,
151 "rootUrl" : "https://root.url.of.my.app",
152 "webOrigins" : [
153 "+"
154 ],
155 "authenticationFlowBindingOverrides" : {},
156 "baseUrl" : "/relative/path/to/its/frontpage.html",
157 "description" : "This describes what my app is for end users",
158 "notBefore" : 0,
159 "frontchannelLogout" : false,
160 "enabled" : true,
161 "registrationAccessToken" : "eyJhbGciOi...",
162 "consentRequired" : true,
163 "fullScopeAllowed" : false,
164 "clientAuthenticatorType" : "client-secret",
165 "surrogateAuthRequired" : false,
166 "directAccessGrantsEnabled" : false,
167 "standardFlowEnabled" : true,
168 "id" : "551b49a0-ec69-41af-9461-6c10fbc79a35",
169 "attributes" : {
170 "contacts" : "first.contact@example.com; second.contact@example.com"
171 },
172 "name" : "My Awesome App",
173 "secret" : "your-client-secret",
174 "publicClient" : false,
175 "clientId" : "my-awesome-client",
176 "optionalClientScopes" : [],
177 "implicitFlowEnabled" : true,
178 "protocol" : "openid-connect",
179 "bearerOnly" : false,
180 "serviceAccountsEnabled" : false
181 }
182 {{/code}}
183
184 Among all the attributes, you should securely save:
185
allan 4.3 186 * your client **secret** ("secret" attribute): it is needed by your application to **authenticate to the IAM server** when making backend calls
187 * your client **registration access token** ("registrationAccessToken"): you will need it to authenticate when **modifying your client in the future**
allan 4.1 188
189 === Modifying your client ===
190
allan 4.3 191 Update your client with a PUT request:
allan 4.1 192
193 {{code language="bash"}}
194 # Set your registration token and client id
195 clb_reg_token=...
196
197 # Update the client
198 curl -X PUT https://iam.humanbrainproject.eu/auth/realms/hbp/clients-registrations/default/my-awesome-client \
199 -H "Authorization: Bearer ${clb_reg_token}" \
200 -H 'Content-Type: application/json' \
201 -d '{
202 "clientId": "my-awesome-client",
203 "redirectUris": [
204 "/relative/redirect/path",
205 "/these/can/use/wildcards/*",
206 "/a/new/redirect/uri"
207 ]
208 }' |
209
210 # Prettify the JSON response
211 json_pp;
212 {{/code}}
allan 4.2 213
allan 4.3 214 Note that your need to provide your client id both in the endpoint URL and within the body of the request.
allan 4.2 215
216 {{warning}}
allan 4.3 217 /!\ ** Each time you modify your client, a new registration access token will be generated. You need to track of your token changes to keep access to your client.   **/!\
allan 4.2 218 {{/warning}}
allan 9.1 219
220 == ==