@hitchy/plugin-auth 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/package.json +11 -11
  2. package/.gitlab-ci.yml +0 -69
  3. package/coverage/base.css +0 -224
  4. package/coverage/block-navigation.js +0 -79
  5. package/coverage/favicon.png +0 -0
  6. package/coverage/index.html +0 -231
  7. package/coverage/plugin-auth/api/controller/index.html +0 -111
  8. package/coverage/plugin-auth/api/controller/user.js.html +0 -368
  9. package/coverage/plugin-auth/api/model/authorization/index.html +0 -111
  10. package/coverage/plugin-auth/api/model/authorization/rule.js.html +0 -227
  11. package/coverage/plugin-auth/api/model/index.html +0 -141
  12. package/coverage/plugin-auth/api/model/role.js.html +0 -200
  13. package/coverage/plugin-auth/api/model/user-to-role.js.html +0 -167
  14. package/coverage/plugin-auth/api/model/user.js.html +0 -752
  15. package/coverage/plugin-auth/api/policy/authentication.js.html +0 -779
  16. package/coverage/plugin-auth/api/policy/authorization.js.html +0 -182
  17. package/coverage/plugin-auth/api/policy/index.html +0 -141
  18. package/coverage/plugin-auth/api/policy/user.js.html +0 -479
  19. package/coverage/plugin-auth/api/service/auth/index.html +0 -111
  20. package/coverage/plugin-auth/api/service/auth/manager.js.html +0 -959
  21. package/coverage/plugin-auth/api/service/authentication/index.html +0 -126
  22. package/coverage/plugin-auth/api/service/authentication/passport.js.html +0 -293
  23. package/coverage/plugin-auth/api/service/authentication/strategies.js.html +0 -929
  24. package/coverage/plugin-auth/api/service/authorization/index.html +0 -141
  25. package/coverage/plugin-auth/api/service/authorization/node.js.html +0 -944
  26. package/coverage/plugin-auth/api/service/authorization/policy-generator.js.html +0 -386
  27. package/coverage/plugin-auth/api/service/authorization/tree.js.html +0 -983
  28. package/coverage/plugin-auth/config/auth.js.html +0 -140
  29. package/coverage/plugin-auth/config/index.html +0 -111
  30. package/coverage/plugin-auth/index.html +0 -111
  31. package/coverage/plugin-auth/index.js.html +0 -383
  32. package/coverage/prettify.css +0 -1
  33. package/coverage/prettify.js +0 -2
  34. package/coverage/sort-arrow-sprite.png +0 -0
  35. package/coverage/sorter.js +0 -170
  36. package/docs/.vuepress/config.js +0 -55
  37. package/docs/.vuepress/styles/palette.styl +0 -4
  38. package/docs/api/config.md +0 -180
  39. package/docs/api/controller/readme.md +0 -10
  40. package/docs/api/controller/user.md +0 -44
  41. package/docs/api/model/authorization-rule.md +0 -38
  42. package/docs/api/model/readme.md +0 -13
  43. package/docs/api/model/role.md +0 -22
  44. package/docs/api/model/user-to-role.md +0 -26
  45. package/docs/api/model/user.md +0 -50
  46. package/docs/api/policy/authentication.md +0 -44
  47. package/docs/api/policy/authorization.md +0 -27
  48. package/docs/api/policy/readme.md +0 -12
  49. package/docs/api/policy/user.md +0 -22
  50. package/docs/api/readme.md +0 -52
  51. package/docs/api/routing.md +0 -101
  52. package/docs/api/service/auth-manager.md +0 -86
  53. package/docs/api/service/authentication-passport.md +0 -21
  54. package/docs/api/service/authentication-strategies.md +0 -22
  55. package/docs/api/service/authorization-node.md +0 -102
  56. package/docs/api/service/authorization-policy-generator.md +0 -66
  57. package/docs/api/service/authorization-tree.md +0 -123
  58. package/docs/api/service/readme.md +0 -15
  59. package/docs/guides/getting-started.md +0 -69
  60. package/docs/guides/idp-login.png +0 -0
  61. package/docs/guides/idp-saml-cert.png +0 -0
  62. package/docs/guides/openid-connect.md +0 -164
  63. package/docs/guides/readme.md +0 -12
  64. package/docs/guides/saml.md +0 -161
  65. package/docs/introduction.md +0 -78
  66. package/docs/readme.md +0 -11
@@ -1,164 +0,0 @@
1
- ---
2
- prev: getting-started.md
3
- next: saml.md
4
- ---
5
-
6
- # OpenID Connect
7
-
8
- [OpenID Connect](https://en.wikipedia.org/wiki/OpenID#OpenID_Connect_(OIDC)) is a security protocol for authenticating in distributed applications as a centrally managed user without exposing its credentials to either application.
9
-
10
- OpenID Connect supports different flows. This example is about [Authorization Code Flow](https://auth0.com/docs/flows/authorization-code-flow).
11
-
12
- ## Prerequisites
13
-
14
- This protocol depends on a remotely set up _identity provider_ (IdP). This tutorial is illustrating how to enable a Hitchy-based application to support authentication against such an IdP via OpenID Connect. Setting up an IdP is beyond its scope, though.
15
-
16
- There are plenty of solutions available for running your own IdP. There are multiple options including commercial and open-source software. [Keycloak](https://www.keycloak.org/) and [authentik](https://goauthentik.io/) are examples for the latter. See our rough [step-by-step tutorial for setting up Keycloak on a server using a stack of Docker containers](https://gist.github.com/soletan/02e141993a811221ce8347c5a6129021). This tutorial is based on Keycloak.
17
-
18
- ## Create custom strategy
19
-
20
- This plugin relies on [passport.js](https://www.passportjs.org/) which in turn supports so called _strategies_ to support different kinds of authentication services and security protocols. The strategy used in this example is included with 3rd-party package [openid-client](https://www.npmjs.com/package/openid-client) which you need to install in context of your application:
21
-
22
- ```bash
23
- npm i openid-client
24
- ```
25
-
26
- **@hitchy/plugin-auth** is picking up all [strategies configured in its runtime configuration](../api/config.md#config-auth-strategies) on application start. It includes a factory service offering methods for generating strategies from a set of configuration options. That's what we use here.
27
-
28
- Open file **config/auth.js** of your project and add the `oidc` property to the list of strategies as illustrated in this example:
29
-
30
- ```javascript
31
- "use strict";
32
-
33
- module.exports = async function() {
34
- const { service } = this.runtime;
35
-
36
- return {
37
- auth: {
38
- strategies: {
39
- oidc: await service.AuthenticationStrategies.generateOpenIdConnect( "oidc", {
40
- // Provides URL of IdP for discovering settings for this
41
- // application's authentication realm.
42
- discovery_url: "https://idp.cepharum.de/auth/realms/hitchy-plugin-auth-ci-test",
43
-
44
- // Provides this application's name in context of discovered
45
- // IdP realm. Think of it as the application's username for
46
- // authenticating itself at the IdP.
47
- client_id: "ci-openid-test",
48
-
49
- // Provides IdP-specific secret used to authenticate this
50
- // application as a valid client of IdP. Think of it as the
51
- // application's password for authenticating itself.
52
- client_secret: "some-random-secret",
53
-
54
- // Lists valid URLs user may be redirected to after logging
55
- // in successfully at IdP.
56
- redirect_uris: ["http://localhost:3000/api/auth/login/oidc"],
57
-
58
- // Lists metadata/attributes of authenticated user to be
59
- // delivered by IdP in redirect after successful login.
60
- response_types: ["code"],
61
-
62
- // Lists valid URLs user may be redirected to after logging
63
- // out from IdP.
64
- post_logout_redirect_uris: ["http://localhost:3000/api/auth/logout"],
65
- } ),
66
- },
67
- }
68
- };
69
- };
70
- ```
71
-
72
- :::tip Multiple strategies?
73
- It's fine to have multiple strategies of different name being set up like that. Just make sure name of property is different, URL-safe and provided as first argument to the generator method.
74
- :::
75
-
76
- The strategy in this example is named `oidc`. Thus, the same name is given as first argument to the generator function, too. Its second argument provides configuration options for used to set up the strategy in detail.
77
-
78
- :::warning Adapt to your IdP
79
- The configuration in code example is for illustration, only. You need to adapt the settings to work with your IdP.
80
- :::
81
-
82
- * The **discovery_url** is addressing your IdP's meta settings which is a computable set of configuration parameters the client will pick up and adapt to your IdP properly. In our case, which is based on Keycloak, it is [https://idp.cepharum.de/auth/realms/hitchy-plugin-auth-ci-test](https://idp.cepharum.de/auth/realms/hitchy-plugin-auth-ci-test). Click the link to see all meta settings related to a realm named `hitchy-plugin-auth-ci-test`.
83
- * **client_id** and **client_secret** are just like a user's name and password, but this time they are suitable for authenticating your application at your IdP.
84
- * A list of **redirect_uris** can be provided, but usually it consists of a single URL, only. In Authorization Code Flow, users are redirected to that URL right after successful authentication. Additional data on authenticated user is passed in query parameters there. The strategy is required to process that request, too. Thus, in case of **hitchy/plugin-auth**, this is usually referring to the same login endpoint used to trigger the authentication in the first place, e.g. [http://localhost:3000/api/auth/login/oidc](http://localhost:3000/api/auth/login/oidc). This support is based on some [routing defaults](../api/routing.md).
85
- * Similar to that, another list of possible redirect URIs is given in **post_logout_redirect_uris**, this time for redirecting a user's browser after successful logout at IdP. The target is meant to finish the logout process on behalf of your application, thus you should point it to the logout URL [http://localhost:3000/api/auth/logout](http://localhost:3000/api/auth/logout) accordingly.
86
- * A list of required meta attributes to deliver on an authenticated user can be configured, too. Requesting `code` response type is essential to Authorization Code Flow. That's referring to the user's name. You might query for additional data such as the user's mail address or similar.
87
-
88
- :::tip Additional options
89
- All but the **discovery_url** are metadata options supported by the underlying **openid-client** package, thus you should look into [its documentation](https://github.com/panva/node-openid-client/blob/main/docs/README.md#new-clientmetadata-jwks-options) for additional options available. Some of them might be failing to work because of the way the client is integrated with Hitchy.
90
- :::
91
-
92
- ## Restart and test
93
-
94
- Restart your hitchy instance. Open browser at [http://localhot:3000/api/auth/current](http://localhot:3000/api/auth/current) and get a response like this one:
95
-
96
- ```json
97
- {"success":true,"authenticated":false}
98
- ```
99
-
100
- The request has succeeded, but no user is authenticated currently.
101
-
102
- Trigger authentication by opening URL [http://localhost:3000/api/auth/login/oidc](http://localhost:3000/api/auth/login/oidc) next. Last segment in this URL is referring to the strategy name you've picked when integrating it with the list of configured strategies.
103
-
104
- This will redirect the browser to your IdP for prompting to log in:
105
-
106
- ![screenshot of IdP login](./idp-login.png)
107
-
108
- After logging in there, your browser is instantly redirected back to the URL [http://localhost:3000/api/auth/login/oidc](http://localhost:3000/api/auth/login/oidc) as given in configuration above. This time it is succeeding with a response:
109
-
110
- ```json
111
- {"success":true,"authenticated":true}
112
- ```
113
-
114
- You are authenticated!
115
-
116
- Return to the first URL requested above. It's providing a different set of information this time:
117
-
118
- ```json
119
- {"success":true,"authenticated":{"uuid":"d778afae-1234-4a58-a254-b56b1f36e914","name":"your-user","roles":[]}}
120
- ```
121
-
122
- Try repeating this request if you like. Unless closing your browser, you stay authenticated.
123
-
124
- If you happen to close the browser, just return to the login URL and - based on your IdP configuration - you will be re-authenticated instantly without being prompted for entering username and password again.
125
-
126
- Next send a request to [http://localhost:3000/api/auth/logout](http://localhost:3000/api/auth/logout). It gets approved:
127
-
128
- ```json
129
- {"success":true}
130
- ```
131
-
132
- Fetch current state of authentication at [https://localhost:3000/api/auth/current](https://localhost:3000/api/auth/current) once again.
133
-
134
- ```json
135
- {"success":true,"authenticated":false}
136
- ```
137
-
138
- Try to re-authenticate instantly at [http://localhost:3000/api/auth/login/oidc](http://localhost:3000/api/auth/login/oidc). It's going to prompt for username and password at your IdP again.
139
-
140
- ## How to welcome users?
141
-
142
- Well, if you don't want your application's users to see the approval of logging in as raw JSON data, you simply have to replace the controller for route `GET /api/auth/login/oidc` and make it provide any other response, e.g. some redirection to a welcome page of your application.
143
-
144
- Adjust your application's file **config/routes.js** accordingly:
145
-
146
- ```javascript
147
- exports.routes = {
148
- "GET /api/auth/login/oidc": ( _, res ) => res.redirect( 301, "/welcome" ),
149
- };
150
- ```
151
-
152
- This is possible in a custom policy [processed after this plugin's policy](https://core.hitchy.org/internals/routing-basics.html#routing-slots), either. This could be your **config/policies.js** file:
153
-
154
- ```javascript
155
- exports.policies = {
156
- "GET /api/auth/login/oidc"( req, res, next ) {
157
- if ( req.user ) {
158
- res.redirect( 301, "/welcome" );
159
- } else {
160
- next();
161
- }
162
- },
163
- };
164
- ```
@@ -1,12 +0,0 @@
1
- ---
2
- prev: ../introduction.md
3
- next: false
4
- ---
5
-
6
- # Guides
7
-
8
- This section provides simple tutorials explaining how to work with this plugin:
9
-
10
- * [Getting started](getting-started.md)
11
- * [OpenID Connect](openid-connect.md)
12
- * [SAML 2.0](saml.md)
@@ -1,161 +0,0 @@
1
- ---
2
- prev: openid-connect.md
3
- next: ../api/
4
- ---
5
-
6
- # SAML 2.0
7
-
8
- [SAML 2.0](https://en.wikipedia.org/wiki/SAML_2.0) is a security protocol for authenticating centrally managed users in multiple distributed applications without exposing their credentials to either application.
9
-
10
- ## Prerequisites
11
-
12
- This protocol depends on a remotely set up identity provider (IdP). This tutorial is illustrating how to enable a Hitchy-based application to support authentication against such an IdP via SAML 2.0. Setting up an IdP is beyond its scope, though.
13
-
14
- There are plenty of solutions available for running your own IdP. There are multiple options including commercial and open-source software. [Keycloak](https://www.keycloak.org/) and [authentik](https://goauthentik.io/) are examples for the latter. See our rough [step-by-step tutorial for setting up Keycloak on a server using a stack of Docker containers](https://gist.github.com/soletan/02e141993a811221ce8347c5a6129021). This tutorial is based on Keycloak.
15
-
16
- ## Create custom strategy
17
-
18
- This plugin relies on [passport.js](https://www.passportjs.org/) which in turn supports so called _strategies_ to support different kinds of authentication services and security protocols. The strategy used in this example is included with 3rd-party package [passport-saml](https://www.npmjs.com/package/passport-saml) which you need to install in context of your application:
19
-
20
- ```bash
21
- npm i passport-saml
22
- ```
23
- **@hitchy/plugin-auth** is picking up all [strategies configured in its runtime configuration](../api/config.md#config-auth-strategies) on application start. It includes a factory service offering methods for generating strategies from a set of configuration options. That's what we use here.
24
-
25
- Open file **config/auth.js** of your project and add the `saml` property to the list of strategies as illustrated in this example:
26
-
27
- ```javascript
28
- "use strict";
29
-
30
- module.exports = async function() {
31
- const { service } = this.runtime;
32
-
33
- return {
34
- auth: {
35
- strategies: {
36
- saml: service.AuthenticationStrategies.generateSaml( "saml", {
37
- // URL of IdP receiving SAML requests
38
- entryPoint: "https://idp.cepharum.de/auth/realms/hitchy-plugin-auth-ci-test/protocol/saml",
39
-
40
- // name of this client as registered with the IdP
41
- issuer: "ci-saml-test",
42
-
43
- // signature algorithm to use (set to prevent insecure
44
- // SHA-1 used by default)
45
- signatureAlgorithm: "sha256",
46
-
47
- // URL for redirecting user to after successful login
48
- callbackUrl: "http://localhost:3000/api/auth/login/saml",
49
-
50
- // URL of local application's endpoint for logging
51
- // out to be exposed as meta of this service provider
52
- logoutCallbackUrl: "http://localhost:3000/api/auth/logout",
53
-
54
- // public certificate of IdP's realm used for signing
55
- // SAML responses
56
- cert: "MIICwzCCAasCfB5l4jANBg...SDuuWWgsPnlrNpCnOnM6ycT/PCDyad",
57
- } ),
58
- },
59
- }
60
- };
61
- };
62
- ```
63
-
64
- :::tip Multiple strategies?
65
- It's fine to have multiple strategies of different name being set up like that. Just make sure name of property is different, URL-safe and provided as first argument to the generator method.
66
- :::
67
-
68
- The strategy in this example is named `saml`. Thus, the same name is given as first argument to the generator function, too. Its second argument provides configuration options for used to set up the strategy in detail.
69
-
70
- :::warning Adapt to your IdP
71
- The configuration in code example is for illustration, only. You need to adapt the settings to work with your IdP.
72
- :::
73
-
74
- * The **entryPoint** URL [https://idp.example.com/auth/realms/app-users/protocol/saml](https://idp.example.com/auth/realms/app-users/protocol/saml) is your IdP's URL for the realm of users meant to gain access to your application. In Keycloak this is called _Master SAML Processing URL_.
75
- * The **issuer** `ci-saml-test` is the name of your application as registered with your IdP. In Keycloak that's the name of a registered _client_.
76
- * The **signatureAlgorithm** must be changed due to `passport-saml` is defaulting to the more insecure `sha1` otherwise.
77
- * The **cert**ificate - it's been significantly shortened in example above - is provided by your IdP for validating its signatures. It is required by `passport-saml` to validate signatures on responses provided by IdP.
78
-
79
- In Keycloak the certificate to be used is found in your realm's settings, in tab _Keys_:
80
-
81
- ![screenshot of Keycloak providing signing certificate](./idp-saml-cert.png)
82
-
83
- * The **callbackUrl** [http://localhost:3000/api/auth/login/saml](http://localhost:3000/api/auth/login/saml) is your application's absolute URL processing login requests returning from IdP via redirecting the user's browser after successful authentication. The path should be addressing the same endpoint triggering the authentication, thus it should be very similar to the example. It works due to [routing defaults](../api/routing.md).
84
-
85
- No matter your eventual redirect URI, you have to configure it as a _valid redirect URI_ at your IdP.
86
-
87
- * According to that, the **logoutCallbackUrl** [http://localhost:3000/api/auth/logout](http://localhost:3000/api/auth/logout) is your application's absolute URL processing logout requests after returning from IdP via redirecting the user's browser. Just like before, the path should be addressing the same endpoint triggering the logout. Don't forget to declare it a _valid redirect URI_ at your IdP, too.
88
-
89
- ## Restart and test
90
-
91
- Restart your hitchy instance. Open browser at [http://localhot:3000/api/auth/current](http://localhot:3000/api/auth/current) and get a response like this one:
92
-
93
- ```json
94
- {"success":true,"authenticated":false}
95
- ```
96
-
97
- The request has succeeded, but no user is authenticated currently.
98
-
99
- Trigger authentication by opening URL [http://localhost:3000/api/auth/login/saml](http://localhost:3000/api/auth/login/saml) next. Last segment in this URL is referring to the strategy name you've picked when integrating it with the list of configured strategies.
100
-
101
- This will redirect the browser to your IdP for prompting to log in:
102
-
103
- ![screenshot of IdP login](./idp-login.png)
104
-
105
- After logging in there, your browser is instantly redirected back to the URL [http://localhost:3000/api/auth/login/saml](http://localhost:3000/api/auth/login/saml) as given in configuration above. This time it is succeeding with a response:
106
-
107
- ```json
108
- {"success":true,"authenticated":true}
109
- ```
110
-
111
- You are authenticated!
112
-
113
- Return to the first URL requested above. It's providing a different set of information this time:
114
-
115
- ```json
116
- {"success":true,"authenticated":{"uuid":"d778afae-1234-4a58-a254-b56b1f36e914","name":"your-user","roles":[]}}
117
- ```
118
-
119
- Try repeating this request if you like. Unless closing your browser, you stay authenticated.
120
-
121
- If you happen to close the browser, just return to the login URL and - based on your IdP configuration - you will be re-authenticated instantly without being prompted for entering username and password again.
122
-
123
- Next send a request to [http://localhost:3000/api/auth/logout](http://localhost:3000/api/auth/logout). It gets approved:
124
-
125
- ```json
126
- {"success":true}
127
- ```
128
-
129
- Fetch current state of authentication at [https://localhost:3000/api/auth/current](https://localhost:3000/api/auth/current) once again.
130
-
131
- ```json
132
- {"success":true,"authenticated":false}
133
- ```
134
-
135
- Try to re-authenticate instantly at [http://localhost:3000/api/auth/login/saml](http://localhost:3000/api/auth/login/saml). It's going to prompt for username and password at your IdP again.
136
-
137
- ## How to welcome users?
138
-
139
- Well, if you don't want your application's users to see the approval of logging in as raw JSON data, you simply have to replace the controller for route `GET /api/auth/login/saml` and make it provide any other response, e.g. some redirection to a welcome page of your application.
140
-
141
- Adjust your application's file **config/routes.js** accordingly:
142
-
143
- ```javascript
144
- exports.routes = {
145
- "GET /api/auth/login/saml": ( _, res ) => res.redirect( 301, "/welcome" ),
146
- };
147
- ```
148
-
149
- This is possible in a custom policy [processed after this plugin's policy](https://core.hitchy.org/internals/routing-basics.html#routing-slots), either. This could be your **config/policies.js** file:
150
-
151
- ```javascript
152
- exports.policies = {
153
- "GET /api/auth/login/saml"( req, res, next ) {
154
- if ( req.user ) {
155
- res.redirect( 301, "/welcome" );
156
- } else {
157
- next();
158
- }
159
- },
160
- };
161
- ```
@@ -1,78 +0,0 @@
1
- ---
2
- prev: /
3
- next: /guides/
4
- ---
5
-
6
- # Introduction
7
-
8
- **@hitchy/plugin-auth** is a plugin for the server-side framework [Hitchy](https://core.hitchy.org). It provides request handlers and policies for server-side request [authentication](#authentication) and [authorization](#authorization). It processes [authorization rules](api/config.md#config-auth-authorizations) in [runtime configuration](https://core.hitchy.org/api/hitchy.html#configuration). There are [ODM-based](https://odem.hitchy.org) [models](https://core.hitchy.org/internals/components.html#models) for managing [users](api/model/user.md), [roles](api/model/role) and their authorizations using [rules](api/model/authorization-rule.md) at runtime, too.
9
-
10
- ## Authentication
11
-
12
- Authentication refers to the process of assuring a user's identity.
13
-
14
- This plugin includes request handlers for instantly supporting basic authentication against some local database managed with [Odem](https://odem.hitchy.org/).
15
-
16
- ::: tip Supported authentication strategies
17
- This plugin integrates with [Passport](http://www.passportjs.org/) to handle authentication. Passport provides a wide array of [strategies](http://www.passportjs.org/packages/) that can handle all kinds of authentication which might work with external sources, as well. There is a built-in strategy for local authentication used by default.
18
- :::
19
-
20
- ### Users
21
-
22
- Requests may include data for authenticating as a user selected by its name. Usually, this involves additional provision of some identification token such as a password.
23
-
24
- Server-side sessions keep track of authentication requests once they succeeded to consider follow-up requests of same client as authenticated, too. This relies on separate plugins [session](https://www.npmjs.com/package/@hitchy/plugin-session) and [cookies](https://www.npmjs.com/package/@hitchy/plugin-cookies).
25
-
26
- ## Authorization
27
-
28
- Authorization is the process of controlling an [identified user's](#authentication) permissions to access certain resources such as features, functions, data etc.
29
-
30
- By intention, users have restricted access to your application. [Authorization rules](api/model/authorization-rule.md) associate a named resource with one or more [users](api/model/user.md) and/or [roles](api/model/role.md) for granting or revoking access on those resources.
31
-
32
- ### Administrator account
33
-
34
- On every start of application, the plugin checks if there is a [configurable](api/config.md#config-auth-admin) [user](api/model/user.md) with full access to all routes and models and creates it if missing. Unless [configured](api/config.md#config-auth-admin) otherwise, that user's name is `admin` and its password is `nimda`.
35
-
36
- ### Resources
37
-
38
- A resource is basically just a name, e.g. of a feature or some data entity in your application. It doesn't mean anything to this plugin on its own. In context of your application the name is meant to represent something you want to control access on.
39
-
40
- Resource names work hierarchically by design. They consist of segments similar to a filesystem's pathname. However, segments of a resource name are separated by periods instead of slashes.
41
-
42
- ### Roles
43
-
44
- Roles are an addition to managing users. There is a model for managing roles in a database. Every role is meant to represent a group of users. They simplify access control based on authorization rules.
45
-
46
- ### An example
47
-
48
- Let's assume your application provides a set of dedicated features and you want to control who's permitted to use what feature. Every such feature is a _resource_. For example, your application could have a _print_ feature and an _export_ feature. The latter could be divided into different supported export formats such as _PDF_ and _Excel spreadsheet_.
49
-
50
- On naming related resources, consider future improvements relying on resources not representing some feature, such as controlling access on individual data records of your application. Thus, you should start naming your resources with a type name such as `features`. Group features as good as possible and pick a second-level name for either group, e.g. `print` and `export`. If you've combined features in such a group, add another segment for either individual feature in that group, e.g. `pdf` and `excel` for the `export` group.
51
-
52
- ```
53
- +- features
54
- +- print
55
- +- export
56
- +- pdf
57
- +- excel
58
- ```
59
-
60
- In this case, resulting resource names are `features.print`, `features.export.pdf` and `features.export.excel`.
61
-
62
- [Authorization rules](api/model/authorization-rule.md) are capable of granting/revoking access on either particular feature selected by its name as given above. In addition, authorization rules may address groups of features or all features altogether by using partial resource names such as `features` or `features.export`.
63
-
64
- ```json
65
- {
66
- "features": "@platinum",
67
- "features.export": "@gold,@silver",
68
- "features.export.pdf": "-@silver,john.doe"
69
- }
70
- ```
71
-
72
- :::tip Example explained
73
- Users with `platinum` role are granted access to all features. Users with `gold` role may access all export features. Eventually, users with `silver` role may access all export features except for the PDF export. Without regards to being assigned to either role, user `john.doe` has been granted access on PDF export feature.
74
- :::
75
-
76
- On checking a user's authorization to access some resource, you provide that resource's qualified resource name. All rules addressing this resource or any of its superordinated resources will be checked for granting/revoking access to/from current user and/or some role this user is associated with.
77
-
78
- Your application's code can check a user's authorization using some service. In addition, a policy generator is included with this plugin to create separate policies to be injected into your application's routing configuration.
package/docs/readme.md DELETED
@@ -1,11 +0,0 @@
1
- ---
2
- sidebar: false
3
- ---
4
-
5
- # Authentication and authorization
6
-
7
- This plugin implements generic support for authentication and authorization and easily integrates with your [Hitchy](https://core.hitchy.org)-based application.
8
-
9
- * [Introduction](introduction.md)
10
- * [Getting Started](guides/getting-started.md)
11
- * [API](api)