Changes for page 2. Authenticating with your OIDC client and fetch collab user info
Last modified by messines on 2021/06/08 17:32
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki.m morgan1 +XWiki.messines - Content
-
... ... @@ -1,15 +1,15 @@ 1 1 == Abstract == 2 2 3 - Inordertocreatean OIDC client,see [[1. RegisteringanOIDC client>>https://wiki.ebrains.eu/bin/view/Collabs/collaboratory-community-apps/Community%20App%20Developer%20Guide/1.%20Registering%20an%20OIDC%20client/]]. Aftercreating theOIDC client, you haveespondingaccesstoken andcret.3 +You had been creating an OIDC client following our guide [[https:~~/~~/wiki.ebrains.eu/bin/view/Collabs/collaboratory-community-apps/Community%20App%20Developer%20Guide/Registering%20an%20OIDC%20client/>>https://wiki.ebrains.eu/bin/view/Collabs/collaboratory-community-apps/Community%20App%20Developer%20Guide/Registering%20an%20OIDC%20client/]] 4 4 5 - For the examplebelow,weconsiderthecaseofsomeonewantingtoprovideaccesstohttps:~/~/www.getpostman.comasan appforCollaboratoryusersto accessfromtheircollabs.YoushouldreplacethatURLbytheoneof yourownapp.5 +The redirect_uri is set with the url of your application, in this exemple we will use postman, a platform for api developement, use your own application, for exemple when you loggin to this wiki, the redirect uri is [[https:~~/~~/wiki.ebrains.eu/*>>https://wiki.ebrains.eu/*]] 6 6 7 -The redirect_uriisset withthe URL of yourapplicationto whichyourusers willbe redirectedafter havingbeen authenticatedbytheirEBRAINS account.For example whenyou login to thiswiki,theedirectURIis[[https:~~/~~/wiki.ebrains.eu/*>>https://wiki.ebrains.eu/*]]7 +The client is confidential with a secret, you obtain it throught the registering oidc client tutorial above. 8 8 9 9 [[image:Screenshot 2020-07-15 at 17.47.12.png||height="517" width="758"]] 10 10 11 11 12 -The whole authentication flow presented here is based on the official OAuth2 RFCdescribedin the section 4.1.12 +The whole authentication flow presented here is based on the official OAuth2 rfc describe in the section 4.1 13 13 14 14 [[https:~~/~~/tools.ietf.org/html/rfc6749#section-4.1>>https://tools.ietf.org/html/rfc6749#section-4.1]] 15 15 ... ... @@ -17,68 +17,63 @@ 17 17 18 18 == Authentication flow == 19 19 20 -=== Authorization Code Request ===20 +=== Authorization Code Grant === 21 21 22 -The first step of the authentication protocol is to fetch an **authorization code **for your client and your user. This is done by directing your users to the URL of the EBRAINS login page (**IAM**) where they can enter their username and password. 23 - 24 24 ==== Request ==== 25 25 26 -The orization **code**is fetchedbyanHTTP request:24 +/GET on [[https:~~/~~/iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/auth >>https://iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/auth]] 27 27 28 - /GET: [[https:~~/~~/iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/auth>>https://iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/auth]]26 +with query parameters 29 29 30 -with the following parameters: 31 - 32 32 * response_type=code 29 +* client_id=community-apps-tutorial 30 +* redirect_uri=[[https:~~/~~/www.getpostman.com/oauth2/callback>>https://www.getpostman.com/oauth2/callback]] 33 33 * login=true 34 -* client_id=**//community-apps-tutorial//** 35 -* redirect_uri=**//https:~/~/www.getpostman.com/oauth2/callback//** 36 -* scope=openid**//+group+team//** 32 +* scope=openid+group+team 37 37 38 - with the italicsindicating the fields you customize for your own app. The URL will look like:34 +so 39 39 40 -https:~/~/iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/auth?response_type=code&login=true&client_id= //**community-apps-tutorial**//&redirect_uri=//**https:~/~/www.getpostman.com/oauth2/callback**//&scope=openid//**+group+team**//36 +[[https:~~/~~/iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/auth?response_type=code&client_id=community-apps-tutorial&redirect_uri=https:~~/~~/www.getpostman.com/oauth2/callback&login=true&scope=openid+group+team>>https://iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/auth?response_type=code&client_id=community-apps-tutorial&redirect_uri=https://www.getpostman.com/oauth2/callback&login=true&scope=openid+group+team]] 41 41 42 - The**scope**parameter can includeacombinationof severalvalues. Each userwill beaskedto consentto sharingthat scopewith yourapp upon firstaccess.38 +Of course replace **client_id** and **redirect_uri** with your own configuration 43 43 44 -* **openid: **This scope is required because we use the OIDC protocol. It will give your app access to the user's basic information such as username, email and full name. 45 -* **group **(optional)**: **If you request this scope, the future access token generated will authorize your app to identify which units and groups the user belongs to. 46 -* **team **(optional)**: **This scope is like the group scope lets your app identify the permissions of the user, but by identifying what collabs the user has access to and with what roles. 40 +This will redirect you to the login page of **iam **where your user must enter they username/password 47 47 48 -{{info}} 49 -The group and team scopes are a simple way for your app to grant permissions to its services and resources when you want to grant access to a very few units, groups, or collab teams. For more complex permission management, contact support. 50 -{{/info}} 42 +==== Scope ==== 51 51 44 +In the request you can see a scope **parameter** 45 + 46 +* **openid : **This scope is required in oidc, it contains basic information of the user such as it username, email and full name. 47 +* **group **( optional ) **: **This scope is provided by our service, if you add it to your authorization code grant request, the futur access token generated will be able to read which units and groups the logged user belongs, it can be very important for your application. You can notice on the screenshot in the abstract section that **Consent required **is **on, **it means that at loggin time, the user will be asked if he allow your application to access there unit and group membership 48 +* **team **( optional ) **: **Very same than group, but for collab, with this scope your application will know in which collab the authenticated user belong 49 + 52 52 ==== Response ==== 53 53 54 - Once theuser hasloggedin, yourappgetsanHTTP301 redirectionfollowed byanHTTP200 success response with anauthorization**code** inside. A typical response might look like:52 +After the loggin, you got a 301 redirection and 200 success http response with a **code** inside 55 55 56 -https:~/~/www.getpostman.com/oauth2/callback?session_state=a0ff8a68-2654-43ef-977a-6c15ce343546&code= **f3f04f93-hbp-482d-ac3d-demo.turtorial.7122c1d9-3f7e-4d80-9c4f-dcd244bc2ec7**54 +[[https:~~/~~/www.getpostman.com/oauth2/callback?session_state=a0ff8a68-2654-43ef-977a-6c15ce343546&code=f3f04f93-hbp-482d-ac3d-demo.turtorial.7122c1d9-3f7e-4d80-9c4f-dcd244bc2ec7>>https://www.getpostman.com/oauth2/callback?session_state=a0ff8a68-2654-43ef-977a-6c15ce598886&code=f3f04f93-b98d-482d-ac3d-414cead54de0.a0ff8a68-2654-43ef-977a-6c15ce598886.7122c1d9-3f7e-4d80-9c4f-dcd244bc2ec7]] 57 57 58 58 (% class="box infomessage" %) 59 59 ((( 60 - Theauthorization **code**isthe partinboldintheresponseabove.58 +the code is very important for the next step here the code is //f3f04f93-hbp-482d-ac3d-demo.turtorial.7122c1d9-3f7e-4d80-9c4f-dcd244bc2ec7// 61 61 ))) 62 62 61 + 63 63 === Access Token Request === 64 64 65 -(% class="wikigeneratedid" id="HRequest-1" %) 66 -Now that your app has the **authorization** **code** for a user, it can fetch the user access token 67 - 68 -(% class="wikigeneratedid" %) 69 69 ==== Request ==== 70 70 71 - /POST:[[https:/iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/token>>url:https:/iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/token]]66 +Now that you have the **authorization** **code, **you can reach the **/token **endpoint and fetch the user access token 72 72 73 - withthefollowing parameters:68 +/POST : https:/iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/token 74 74 75 -* grant_type: authorization_code 76 -* code: **//f3f04f93-hbp-482d-ac3d-demo.turtorial.7122c1d9-3f7e-4d80-9c4f-dcd244bc2ec7//** 77 -* redirect_uri: **//[[https:~~/~~/www.getpostman.com/oauth2/callback>>https://www.getpostman.com/oauth2/callback]]//** 78 -* client_id: **//community-apps-tutorial//** 79 -* client_secret: **//your client secret obtained during client creation//** 70 +with params 80 80 81 -The image below shows a sample POST request generated from the Postman tool. [The fact that this page is based on getpostman.com as an example is pure coincidence.] 72 +* grant_type : authorization_code 73 +* code : //f3f04f93-hbp-482d-ac3d-demo.turtorial.7122c1d9-3f7e-4d80-9c4f-dcd244bc2ec7// 74 +* redirect_uri : [[https:~~/~~/www.getpostman.com/oauth2/callback>>https://www.getpostman.com/oauth2/callback]] 75 +* client_id : community-apps-tutorial 76 +* client_secret : your client secret obtained during client creation 82 82 83 83 [[image:Screenshot 2020-07-15 at 18.20.34.png]] 84 84 ... ... @@ -102,32 +102,32 @@ 102 102 } 103 103 ))) 104 104 105 -You rappgetsa response containing the**access token**and otherinformation.100 +You get a response containing the access token and others 106 106 107 107 == Access user info == 108 108 109 -Now that your app has the access token of a user, it can fetch the user's info. 110 - 111 111 ==== Request ==== 112 112 113 - /GET:[[https:/iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/userinfo>>url:https:/iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/userinfo]]106 +Now that your application got the access token of your user, it's really easy to fetch user info 114 114 115 -with the following parameters: 108 +(% class="box infomessage" %) 109 +((( 110 +/GET https:/iam.ebrains.eu/auth/realms/hbp/protocol/openid-connect/userinfo 111 +))) 116 116 117 - *Authorization:the access tokenprecededbythestring"Bearer"113 +and just provide the access token as **Authentication** header 118 118 119 -The image below shows a sample GET request generated from the Postman tool. [The fact that this page is based on getpostman.com as an example is pure coincidence.] 120 - 121 121 [[image:Screenshot 2020-07-15 at 18.28.28.png||height="161" width="566"]] 122 122 117 + 123 123 ==== Response ==== 124 124 125 -As response you rapp receivesaJSONwith all the information on the logged user120 +As response you will have a json with all the information on the logged user, for my user 126 126 127 127 (% class="box" %) 128 128 ((( 129 129 { 130 - "sub": "fa2db206-3 ...0ebaba98e1",125 + "sub": "fa2db206-3eb4-403c-894a-810ebaba98e1", 131 131 "unit": [ 132 132 "/collab-devs", 133 133 "/collab-team", ... ... @@ -143,23 +143,13 @@ 143 143 "feature:authenticate" 144 144 ], 145 145 "team": [ 146 - " **collab**-collaboratory-community-apps-**editor**"141 + "collab-collaboratory-community-apps-editor" 147 147 ], 148 148 "group": [ 149 - " **group**-collaboratory-developers",150 - " **unit**-all-projects-hbp-consortium-sga2-sp05-administrator"144 + "group-collaboratory-developers", 145 + "unit-all-projects-hbp-consortium-sga2-sp05-administrator" 151 151 ] 152 152 }, 153 - "mitreid-sub": "30 ...62"148 + "mitreid-sub": "305862" 154 154 } 155 155 ))) 156 - 157 -The group field above lists Collaboratory Groups in the form "group-//groupname//" and Collaboratory Units in the form "unit-//unitname//" with the unitname using dashes instead of the colons you see in the Collaboratory UI. 158 - 159 -The team field above lists Collaboratory Teams in the form "collab-//collabname//-//role//" where //role //is one of admin, editor, or viewer according to the user's role in collab //collabname//. 160 - 161 -jupyterhub and xwiki are OIDC clients. 162 - 163 -The unit field above lists [useless noise?]. 164 - 165 -