Debian Codegraph @

doc/sources/admin/webserviceprotection.rst

raw
1 WebServices / API
2 =================
3
4 Presentation
5 ------------
6
7 WebServices and API are mostly requested by an application, and not the
8 end-user itself. In this case, you can not rely on LL::NG standard
9 Handler to protect the webservice, as it will expect a cookie, which is
10 not defined in the application requesting the service.
11
12 LL::NG offers several solutions to protect this kind of service.
13
14 ServiceToken Handler
15 --------------------
16
17 Two Handlers will be used:
18
19 - The frontal Handler that will protect the web application, and will
20 forge a specific token
21 - The backend Handler that will protect the web service, and will
22 consume the token
23
24 See :doc:`ServiceToken Handler documentation<servertoserver>`.
25
26 OAuth2 endpoints
27 ----------------
28
29 We suppose here that LL::NG is acting as
30 :doc:`OpenID Connect provider<idpopenidconnect>`. The web application
31 will then be able to get an access token from LL::NG. This token could
32 be sent to the webservice that can then validate it against LL::NG
33 OAuth2 endpoints.
34
35 UserInfo
36 ~~~~~~~~
37
38 You can use the UserInfo endpoint, which requires the Access Token to
39 provide user attributes.
40
41 For example:
42
43 ::
44
45 curl \
46 -H "Authorization: Bearer a74d504ec9e784785e70a1da2b95d1d2" \
47 https://auth.example.com/oauth2/userinfo | json_pp
48
49 .. code-block:: javascript
50
51 {
52 "family_name" : "OUDOT",
53 "name" : "Clément OUDOT",
54 "email" : "[email protected]",
55 "sub" : "coudot"
56 }
57
58 Introspection
59 ~~~~~~~~~~~~~
60
61 Introspection endpoint is defined in :rfc:`7662`. It requires an authentication
62 (same as the authentication for the tokens endpoint) and consumes an Access Token
63 as parameter.
64
65 For example:
66
67 ::
68
69 curl \
70 -H "Authorization: Basic bGVtb25sZGFwOnNlY3JldA==" \
71 -X POST -d "token=a74d504ec9e784785e70a1da2b95d1d2" \
72 https://auth.example.com/oauth2/introspect | json_pp
73
74 .. code-block:: javascript
75
76 {
77 "client_id" : "lemonldap",
78 "sub" : "coudot",
79 "exp" : 1572446485,
80 "active" : true,
81 "scope" : "openid profile address email phone"
82 }
83
84 OAuth2 Handler
85 --------------
86
87 We also suppose here that LL::NG is acting as
88 :doc:`OpenID Connect provider<idpopenidconnect>`. But the webservice
89 will be protected by the OAuth2 Handler and will just have to read the
90 HTTP headers to know which user is connected.
91
92 ::
93
94 curl \
95 -H "Authorization: Bearer a74d504ec9e784785e70a1da2b95d1d2" \
96 https://oauth2.example.com/rest/myapi
97
98 .. code-block:: javascript
99
100 {
101 "check" : "true",
102 "user" : "coudot"
103 }
104
105 See :doc:`OAuth2 Handler documentation<oauth2handler>`.