@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.
- package/package.json +11 -11
- package/.gitlab-ci.yml +0 -69
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -79
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -231
- package/coverage/plugin-auth/api/controller/index.html +0 -111
- package/coverage/plugin-auth/api/controller/user.js.html +0 -368
- package/coverage/plugin-auth/api/model/authorization/index.html +0 -111
- package/coverage/plugin-auth/api/model/authorization/rule.js.html +0 -227
- package/coverage/plugin-auth/api/model/index.html +0 -141
- package/coverage/plugin-auth/api/model/role.js.html +0 -200
- package/coverage/plugin-auth/api/model/user-to-role.js.html +0 -167
- package/coverage/plugin-auth/api/model/user.js.html +0 -752
- package/coverage/plugin-auth/api/policy/authentication.js.html +0 -779
- package/coverage/plugin-auth/api/policy/authorization.js.html +0 -182
- package/coverage/plugin-auth/api/policy/index.html +0 -141
- package/coverage/plugin-auth/api/policy/user.js.html +0 -479
- package/coverage/plugin-auth/api/service/auth/index.html +0 -111
- package/coverage/plugin-auth/api/service/auth/manager.js.html +0 -959
- package/coverage/plugin-auth/api/service/authentication/index.html +0 -126
- package/coverage/plugin-auth/api/service/authentication/passport.js.html +0 -293
- package/coverage/plugin-auth/api/service/authentication/strategies.js.html +0 -929
- package/coverage/plugin-auth/api/service/authorization/index.html +0 -141
- package/coverage/plugin-auth/api/service/authorization/node.js.html +0 -944
- package/coverage/plugin-auth/api/service/authorization/policy-generator.js.html +0 -386
- package/coverage/plugin-auth/api/service/authorization/tree.js.html +0 -983
- package/coverage/plugin-auth/config/auth.js.html +0 -140
- package/coverage/plugin-auth/config/index.html +0 -111
- package/coverage/plugin-auth/index.html +0 -111
- package/coverage/plugin-auth/index.js.html +0 -383
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -170
- package/docs/.vuepress/config.js +0 -55
- package/docs/.vuepress/styles/palette.styl +0 -4
- package/docs/api/config.md +0 -180
- package/docs/api/controller/readme.md +0 -10
- package/docs/api/controller/user.md +0 -44
- package/docs/api/model/authorization-rule.md +0 -38
- package/docs/api/model/readme.md +0 -13
- package/docs/api/model/role.md +0 -22
- package/docs/api/model/user-to-role.md +0 -26
- package/docs/api/model/user.md +0 -50
- package/docs/api/policy/authentication.md +0 -44
- package/docs/api/policy/authorization.md +0 -27
- package/docs/api/policy/readme.md +0 -12
- package/docs/api/policy/user.md +0 -22
- package/docs/api/readme.md +0 -52
- package/docs/api/routing.md +0 -101
- package/docs/api/service/auth-manager.md +0 -86
- package/docs/api/service/authentication-passport.md +0 -21
- package/docs/api/service/authentication-strategies.md +0 -22
- package/docs/api/service/authorization-node.md +0 -102
- package/docs/api/service/authorization-policy-generator.md +0 -66
- package/docs/api/service/authorization-tree.md +0 -123
- package/docs/api/service/readme.md +0 -15
- package/docs/guides/getting-started.md +0 -69
- package/docs/guides/idp-login.png +0 -0
- package/docs/guides/idp-saml-cert.png +0 -0
- package/docs/guides/openid-connect.md +0 -164
- package/docs/guides/readme.md +0 -12
- package/docs/guides/saml.md +0 -161
- package/docs/introduction.md +0 -78
- package/docs/readme.md +0 -11
package/docs/.vuepress/config.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
|
|
3
|
-
*
|
|
4
|
-
* The MIT License (MIT)
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2021 cepharum GmbH
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
* copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
* SOFTWARE.
|
|
25
|
-
*
|
|
26
|
-
* @author: cepharum
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
module.exports = {
|
|
30
|
-
evergreen: true,
|
|
31
|
-
base: "/",
|
|
32
|
-
dest: "public",
|
|
33
|
-
title: "Hitchy Auth Manual",
|
|
34
|
-
themeConfig: {
|
|
35
|
-
displayAllHeaders: true,
|
|
36
|
-
sidebar: "auto",
|
|
37
|
-
repo: "https://gitlab.com/hitchy/plugin-auth",
|
|
38
|
-
repoLabel: "Contribute!",
|
|
39
|
-
nav: [
|
|
40
|
-
{ text: "Home", link: "/" },
|
|
41
|
-
{ text: "Guides", link: "/guides/" },
|
|
42
|
-
{ text: "API", link: "/api/" },
|
|
43
|
-
{ text: "Hitchy", items: [
|
|
44
|
-
{ text: "Core", link: "https://core.hitchy.org/" },
|
|
45
|
-
{ text: "Plugins", items: [
|
|
46
|
-
{ text: "Odem", link: "https://odem.hitchy.org/" },
|
|
47
|
-
{ text: "Auth", link: "/" },
|
|
48
|
-
] },
|
|
49
|
-
{ text: "Tools", items: [
|
|
50
|
-
{ text: "SDT", link: "https://sdt.hitchy.org/" },
|
|
51
|
-
] }
|
|
52
|
-
] },
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
};
|
package/docs/api/config.md
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
prev: /api/service/
|
|
3
|
-
next: routing.md
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Runtime Configuration
|
|
7
|
-
|
|
8
|
-
This plugin's runtime configuration is expected in section `auth` of your application's configuration. When complying with suggested filesystem layout for a Hitchy application, there should be a file **config/auth.js** in your application exposing this section similar to this:
|
|
9
|
-
|
|
10
|
-
```javascript
|
|
11
|
-
module.exports = {
|
|
12
|
-
auth: {
|
|
13
|
-
...
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
The following parameters are supported there:
|
|
19
|
-
|
|
20
|
-
## config.auth.prefix
|
|
21
|
-
|
|
22
|
-
This optional string controls shared prefix of routes set up implicitly for providing basic authentication support. Its default is `/api/auth` resulting in routes `/api/auth/login`, `/api/auth/current` etc.
|
|
23
|
-
|
|
24
|
-
Implicit routing setup can be disabled on providing boolean `false` as prefix here.
|
|
25
|
-
|
|
26
|
-
## config.auth.admin
|
|
27
|
-
|
|
28
|
-
Provides name and/or password of admin user to create initially when no user
|
|
29
|
-
with administration privileges has been found in local database. This optional parameter
|
|
30
|
-
is an object consisting of properties
|
|
31
|
-
|
|
32
|
-
* **role** selecting name of role granting full access to any associated user (default: `admin`),
|
|
33
|
-
* **name** selecting name of user to create on start of application if there is no user associated with that role (default: `admin`) and
|
|
34
|
-
* **password** providing password of that user to be created in clear text (default: `nimda`).
|
|
35
|
-
|
|
36
|
-
```javascript
|
|
37
|
-
module.exports = {
|
|
38
|
-
auth: {
|
|
39
|
-
admin: {
|
|
40
|
-
name: "jane.doe",
|
|
41
|
-
password: "my5ecr3t"
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
:::tip
|
|
48
|
-
Environment variables **HITCHY_ADMIN_NAME**, **HITCHY_ADMIN_PASSWORD** and **HITCHY_ADMIN_ROLE** can be used to override any configuration provided here to e.g. support container-driven setups.
|
|
49
|
-
:::
|
|
50
|
-
|
|
51
|
-
## config.auth.roles
|
|
52
|
-
|
|
53
|
-
Lists role names to create on boot if missing in local database. This list is empty by default.
|
|
54
|
-
|
|
55
|
-
```javascript
|
|
56
|
-
module.exports = {
|
|
57
|
-
auth: {
|
|
58
|
-
roles: [ "guest", "customer", "manager" ],
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## config.auth.authorizations
|
|
64
|
-
|
|
65
|
-
This section grants or revokes access on named resources to/from users and/or roles. These _authorizations_ are loaded on application start before reading custom rules from local database.
|
|
66
|
-
|
|
67
|
-
:::tip
|
|
68
|
-
Authorizations read from local database may replace authorizations given in runtime configuration.
|
|
69
|
-
:::
|
|
70
|
-
|
|
71
|
-
It is an object-style hierarchy mapping resource names into names of users and/or roles access on selected resource is granted to or revoked from.
|
|
72
|
-
|
|
73
|
-
```javascript
|
|
74
|
-
module.exports = {
|
|
75
|
-
auth: {
|
|
76
|
-
authorizations: {
|
|
77
|
-
"backup": "@managers",
|
|
78
|
-
"backup.export": "-@noobs",
|
|
79
|
-
"backup.import": "+@admins, -john.doe"
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Lists of users and roles can be provided as strings using comma for separation as illustrated above. Actual array are supported, too:
|
|
86
|
-
|
|
87
|
-
```javascript
|
|
88
|
-
module.exports = {
|
|
89
|
-
auth: {
|
|
90
|
-
authorizations: {
|
|
91
|
-
"backup": [ "@managers" ],
|
|
92
|
-
"backup.export": [ "-@noobs" ],
|
|
93
|
-
"backup.import": [ "+@admins", "-john.doe" ],
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
Names of resources can be grouped by shared prefixes:
|
|
100
|
-
|
|
101
|
-
```javascript
|
|
102
|
-
module.exports = {
|
|
103
|
-
auth: {
|
|
104
|
-
authorizations: {
|
|
105
|
-
backup: {
|
|
106
|
-
people: [ "@managers" ],
|
|
107
|
-
sub: {
|
|
108
|
-
export: [ "-@noobs" ],
|
|
109
|
-
import: [ "+@admins", "-john.doe" ],
|
|
110
|
-
},
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Resource names concatenate path segments separated by period from each other. Common prefixes can be stripped off when nesting authorizations as demonstrated before. Nesting requires provision of users and roles moved into separate property named `people`.
|
|
118
|
-
|
|
119
|
-
For improved readability, `people` list may be replaced with separate lists for `users` and `roles` as well as with lists `grant` and `revoke` grouping authorizations accordingly:
|
|
120
|
-
|
|
121
|
-
```javascript
|
|
122
|
-
module.exports = {
|
|
123
|
-
auth: {
|
|
124
|
-
authorizations: {
|
|
125
|
-
backup: {
|
|
126
|
-
grant: [ "@managers" ],
|
|
127
|
-
sub: {
|
|
128
|
-
export: {
|
|
129
|
-
revoke: [ "@noobs" ]
|
|
130
|
-
},
|
|
131
|
-
import: {
|
|
132
|
-
users: [ "-john.doe" ],
|
|
133
|
-
roles: [ "+admins" ]
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## config.auth.strategies
|
|
143
|
-
|
|
144
|
-
This optional object maps unique names of supported authentication strategies into related implementations for use with [Passport](https://www.passportjs.org/).
|
|
145
|
-
|
|
146
|
-
```javascript
|
|
147
|
-
const { OAuthStrategy } = require( "passport-oauth" );
|
|
148
|
-
|
|
149
|
-
module.export = {
|
|
150
|
-
auth: {
|
|
151
|
-
strategies: {
|
|
152
|
-
oauth: new OAuthStrategy( options, localUserSelectorFn ),
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
Any strategy listed here will be picked up on [integrating Passport with Hitchy's request routing](service/authentication-passport.md#integratewithhitchy). When implementing [policy-based](policy/authentication.md#login) authenticating requests, name of either strategy must be picked in request's parameter `strategy`:
|
|
159
|
-
|
|
160
|
-
```javascript
|
|
161
|
-
module.exports = function() {
|
|
162
|
-
const { login } = this.runtime.policy.Authentication;
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
routes: {
|
|
166
|
-
"GET /login/:strategy": login()
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
If request parameter is missing, [configured default strategy](#config-auth-defaultstrategy) is used.
|
|
173
|
-
|
|
174
|
-
Provide a custom local strategy in property `local` here to prevent built-in [local strategy](service/authentication-strategies.md#generatelocal) from being used. Omit this configuration to rely on that built-in local strategy for authenticating users against local database, only.
|
|
175
|
-
|
|
176
|
-
## config.auth.defaultStrategy
|
|
177
|
-
|
|
178
|
-
This optional string names strategy to use by default. Defaults to `local` itself.
|
|
179
|
-
|
|
180
|
-
Any custom strategy named here must be [set up](#config-auth-strategies) properly.
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
prev: ../controller/
|
|
3
|
-
next: ../policy/
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# UserController
|
|
7
|
-
|
|
8
|
-
This controller provides request handlers basically suitable for authenticating as a user. However, neither handler is actually triggering a user's authentication or its logout, but provides suitable responses following some [additionally required policies](../policy/user.md).
|
|
9
|
-
|
|
10
|
-
Any of the following request handlers can be used as target in your application's routing declarations in [section `routes`](https://core.hitchy.org/api/hitchy.html#config-routes) of [runtime configuration](https://core.hitchy.org/api/hitchy.html#configuration):
|
|
11
|
-
|
|
12
|
-
```json
|
|
13
|
-
{
|
|
14
|
-
"routes": {
|
|
15
|
-
"/login": "user.authenticate",
|
|
16
|
-
"/logout": "user.unauthenticate"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## authenticate()
|
|
22
|
-
|
|
23
|
-
This handler is responding on successful authentication.
|
|
24
|
-
|
|
25
|
-
It relies on policy [authentication.login](../policy/authentication.md#login) being processed, first.
|
|
26
|
-
|
|
27
|
-
## unauthenticate()
|
|
28
|
-
|
|
29
|
-
This handler is responding on successfully dropping any authentication.
|
|
30
|
-
|
|
31
|
-
It relies on policy [authentication.logout](../policy/authentication.md#logout) being processed, first.
|
|
32
|
-
|
|
33
|
-
## changePassword()
|
|
34
|
-
|
|
35
|
-
This handler is responding on successfully changing user's token.
|
|
36
|
-
|
|
37
|
-
It relies on policy [user.changePassword](../policy/user.md#changepassword) being processed, first.
|
|
38
|
-
|
|
39
|
-
## getCurrent()
|
|
40
|
-
|
|
41
|
-
This handler is delivering additional information on recently authenticated user. See related [routing description for response examples](../routing.md#get-api-auth-current).
|
|
42
|
-
|
|
43
|
-
It doesn't depend on any additional policy being processed first.
|
|
44
|
-
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
prev: user-to-role.md
|
|
3
|
-
next: /api/service/
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# AuthorizationRule
|
|
7
|
-
|
|
8
|
-
An AuthorizationRule is a rule granting access on a [named resource](../../introduction.md#resources) to a [user](user.md) or [role](role.md) or rejecting access on that resource from a user or role. It is an essential part of authorization management.
|
|
9
|
-
|
|
10
|
-
## Properties
|
|
11
|
-
|
|
12
|
-
### selector
|
|
13
|
-
|
|
14
|
-
This mandatory [string](https://odem.hitchy.org/guides/defining-models.html#strings) property selects a [resource](../../introduction.md#resources) (see the [example](../../introduction.md#an-example)) by its name.
|
|
15
|
-
|
|
16
|
-
### user
|
|
17
|
-
|
|
18
|
-
This optional [UUID](https://odem.hitchy.org/guides/defining-models.html#uuids) selects a single user which is granted access to selected resource.
|
|
19
|
-
|
|
20
|
-
::: warning
|
|
21
|
-
A rule must select at least a user or a role. It may select both.
|
|
22
|
-
:::
|
|
23
|
-
|
|
24
|
-
### role
|
|
25
|
-
|
|
26
|
-
This optional [UUID](https://odem.hitchy.org/guides/defining-models.html#uuids) selects a single user which is granted access to selected resource.
|
|
27
|
-
|
|
28
|
-
::: warning
|
|
29
|
-
A rule must select at least a user or a role. It may select both.
|
|
30
|
-
:::
|
|
31
|
-
|
|
32
|
-
### accept
|
|
33
|
-
|
|
34
|
-
This [boolean](https://odem.hitchy.org/guides/defining-models.html#booleans) property indicates, whether rule is granting access to selected resource (`true`) or revoking it (`false`). The default value is `true`.
|
|
35
|
-
|
|
36
|
-
## Methods
|
|
37
|
-
|
|
38
|
-
AuthenticationRules don't have custom methods apart from [basic ones](https://odem.hitchy.org/api/model.html).
|
package/docs/api/model/readme.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
prev: ../
|
|
3
|
-
next: false
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Models
|
|
7
|
-
|
|
8
|
-
Select one of the provided [models](https://core.hitchy.org/internals/components.html#models):
|
|
9
|
-
|
|
10
|
-
* [User](user.md)
|
|
11
|
-
* [Role](role.md)
|
|
12
|
-
* [UserToRole](user-to-role.md)
|
|
13
|
-
* [AuthorizationRule](authorization-rule.md)
|
package/docs/api/model/role.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
prev: user.md
|
|
3
|
-
next: user-to-role.md
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Role
|
|
7
|
-
|
|
8
|
-
This model represents a single _role_ in local database. A role can be applied to multiple users. Authorizations can be granted to or revoked from a role instead of a single user, thus affecting all users the role has been applied to.
|
|
9
|
-
|
|
10
|
-
It is part of access control management at runtime.
|
|
11
|
-
|
|
12
|
-
## Properties
|
|
13
|
-
|
|
14
|
-
These are the properties provided per role:
|
|
15
|
-
|
|
16
|
-
### name
|
|
17
|
-
|
|
18
|
-
For every role, this [string](https://odem.hitchy.org/guides/defining-models.html#strings) property is representing the role's unique name. It is used in authorization rules to grant access on a resource to a set of users or revoke it from them explicitly.
|
|
19
|
-
|
|
20
|
-
## Methods
|
|
21
|
-
|
|
22
|
-
Roles don't have custom methods apart from [basic ones](https://odem.hitchy.org/api/model.html).
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
prev: role.md
|
|
3
|
-
next: authorization-rule.md
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# UserToRole
|
|
7
|
-
|
|
8
|
-
Every instance of this model links an instance of [User model](user.md) with a instance of [Role model](role.md).
|
|
9
|
-
|
|
10
|
-
This model is part of access control management at runtime.
|
|
11
|
-
|
|
12
|
-
## Properties
|
|
13
|
-
|
|
14
|
-
These are the properties provided per role:
|
|
15
|
-
|
|
16
|
-
### user
|
|
17
|
-
|
|
18
|
-
Provides [UUID](https://odem.hitchy.org/guides/defining-models.html#uuids) of user associated with a role.
|
|
19
|
-
|
|
20
|
-
### user
|
|
21
|
-
|
|
22
|
-
Provides [UUID](https://odem.hitchy.org/guides/defining-models.html#uuids) of role associated with a user.
|
|
23
|
-
|
|
24
|
-
## Methods
|
|
25
|
-
|
|
26
|
-
There no custom methods apart from [basic ones](https://odem.hitchy.org/api/model.html).
|
package/docs/api/model/user.md
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
prev: ../model/
|
|
3
|
-
next: role.md
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# User
|
|
7
|
-
|
|
8
|
-
This model represents a single user in local database. It is meant to support access control management at runtime e.g. to have a user-customizable access control.
|
|
9
|
-
|
|
10
|
-
## Properties
|
|
11
|
-
|
|
12
|
-
These are the properties provided per user:
|
|
13
|
-
|
|
14
|
-
### name
|
|
15
|
-
|
|
16
|
-
The user's name is a required [string](https://odem.hitchy.org/guides/defining-models.html#strings) which is meant to be unique. It is used to pick a user for local authentication. Authorization rules are capable of addressing a user by name, too.
|
|
17
|
-
|
|
18
|
-
### password
|
|
19
|
-
|
|
20
|
-
This [string](https://odem.hitchy.org/guides/defining-models.html#strings) provides a salted one-way hash of user's password for local authentication or some other kind of token for use with a non-local strategy.
|
|
21
|
-
|
|
22
|
-
Passwords for use with local authentication are implicitly hashed with [SCRYPT](https://de.wikipedia.org/wiki/Scrypt).
|
|
23
|
-
|
|
24
|
-
### strategy
|
|
25
|
-
|
|
26
|
-
Every user can be associated with a particular passport strategy to use for authentication. This [string](https://odem.hitchy.org/guides/defining-models.html#strings) property is picking a strategy by its name. Default strategy as configured is used in case this property is empty or unset.
|
|
27
|
-
|
|
28
|
-
### strategyData
|
|
29
|
-
|
|
30
|
-
This [string](https://odem.hitchy.org/guides/defining-models.html#strings) property is meant to provide custom data specific to selected strategy. It's format is specific to that strategy. It might be used to pick a remote service confirming the user's authentication or represent additional meta data on it.
|
|
31
|
-
|
|
32
|
-
## Methods
|
|
33
|
-
|
|
34
|
-
### hashPassword()
|
|
35
|
-
|
|
36
|
-
**Signature:** `async hashPassword( cleartext, [ previous ] ): string`
|
|
37
|
-
|
|
38
|
-
This asynchronous method derives salted hash from provided clear-text password. The second argument is optional. When provided, the salt is extracted from it instead of generating a fresh random salt. This is required for comparing password hashes. And it shouldn't be used for anything else. Using fresh salts whenever possible is essential to password security.
|
|
39
|
-
|
|
40
|
-
### setPassword()
|
|
41
|
-
|
|
42
|
-
**Signature:** `async setPassword( password )`
|
|
43
|
-
|
|
44
|
-
Changes password of user as provided in clear text. This is a helper updating hashed password in local instance. You still need to [save the record](https://odem.hitchy.org/api/model.html#instance-save) to persist the change.
|
|
45
|
-
|
|
46
|
-
### verifyPassword()
|
|
47
|
-
|
|
48
|
-
**Signature:** `async verifyPassword( password ): boolean`
|
|
49
|
-
|
|
50
|
-
Compares this user's hashed password with a provided clear-text password by hashing the latter with the same salt extracted from the former and compare the hashes. The method is implicitly loading the record from persistent storage if required. It promises `true` if both hashes are identical and `false` otherwise.
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
prev: ../policy/
|
|
3
|
-
next: authorization.md
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# AuthenticationPolicy
|
|
7
|
-
|
|
8
|
-
This class implements policy handlers for transparently processing requests for logging in and out by means of authenticating as a user relying on a [configured](../config.md#config-auth-strategies) [passport](https://www.passportjs.org/) [strategy](https://www.passportjs.org/packages/).
|
|
9
|
-
|
|
10
|
-
These are the provided handlers:
|
|
11
|
-
|
|
12
|
-
## initialize()
|
|
13
|
-
|
|
14
|
-
This policy handler is basically integrating passport with a request's handling. It is unconditionally injected into every incoming request by default.
|
|
15
|
-
|
|
16
|
-
The handler is adopting [passport's instructions for setting it up as a middleware](https://www.passportjs.org/docs/downloads/html/#middleware) to work in context of Hitchy framework.
|
|
17
|
-
|
|
18
|
-
## login()
|
|
19
|
-
|
|
20
|
-
Handles request for authentication via integrated passport's strategy as configured.
|
|
21
|
-
|
|
22
|
-
This handler is essential for [default route supported to authenticate a user](../routing.md#post-api-auth-login-strategy).
|
|
23
|
-
|
|
24
|
-
::: tip Example
|
|
25
|
-
There is an example for how to use this policy in [section on configuring custom strategies](../config.md#config-auth-strategies).
|
|
26
|
-
:::
|
|
27
|
-
|
|
28
|
-
## logout()
|
|
29
|
-
|
|
30
|
-
This handler is dropping any user currently authenticated in context of this request.
|
|
31
|
-
|
|
32
|
-
It is essential for [default route supported to drop user authentication](../routing.md#get-api-auth-logout).
|
|
33
|
-
|
|
34
|
-
## mustBeAuthenticated()
|
|
35
|
-
|
|
36
|
-
This handler responds with HTTP status 403 in case there is no authenticated user in context of current request. Use this policy if you want to reject all requests to a URL prefix unless some user has authenticated.
|
|
37
|
-
|
|
38
|
-
```json
|
|
39
|
-
{
|
|
40
|
-
"policies": {
|
|
41
|
-
"/api/protected": [ "authentication.mustBeAuthenticated" ]
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
```
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
prev: authentication.md
|
|
3
|
-
next: user.md
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# AuthorizationPolicy
|
|
7
|
-
|
|
8
|
-
This class provides policy handlers helping with common authorization tasks.
|
|
9
|
-
|
|
10
|
-
## mustBeAdmin()
|
|
11
|
-
|
|
12
|
-
This handler responds with HTTP status 403 in case there is no current user or any authenticated user isn't associated with the role configured to provide administrative privileges by means of granting access on all resources.
|
|
13
|
-
|
|
14
|
-
::: tip
|
|
15
|
-
This policy handler can be combined with [authentication.mustBeAuthenticated](authentication.md#mustbeauthenticated) to deliver more useful response messages on requests completely lacking authentication.
|
|
16
|
-
|
|
17
|
-
```json
|
|
18
|
-
{
|
|
19
|
-
"policies": {
|
|
20
|
-
"/api/protected": [
|
|
21
|
-
"authentication.mustBeAuthenticated",
|
|
22
|
-
"authorization.mustBeAdmin"
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
```
|
|
27
|
-
:::
|
package/docs/api/policy/user.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
prev: authorization.md
|
|
3
|
-
next: ../model/
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# UserPolicy
|
|
7
|
-
|
|
8
|
-
This class provides policy handlers helping with common tasks related to some authenticated user.
|
|
9
|
-
|
|
10
|
-
## mustBeMe()
|
|
11
|
-
|
|
12
|
-
This handler tests if current request URL contains parameter named `uuid` matching current user's UUID. The request is rejected with HTTP status 403 **on mismatch**.
|
|
13
|
-
|
|
14
|
-
## mustNotBeMe()
|
|
15
|
-
|
|
16
|
-
This handler tests if current request URL contains parameter named `uuid` matching current user's UUID. The request is rejected with HTTP status 403 **on match**.
|
|
17
|
-
|
|
18
|
-
## changePassword()
|
|
19
|
-
|
|
20
|
-
This request is transparently processing request for changing any currently authenticated user's password. It requires provision of authenticated user's current password and the desired new password in request body.
|
|
21
|
-
|
|
22
|
-
This policy handler is essential to [default route supporting change of a user's password](../routing.md#post-api-auth-password).
|
package/docs/api/readme.md
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
prev: ../guides/
|
|
3
|
-
next: false
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# API Reference
|
|
7
|
-
|
|
8
|
-
## Components
|
|
9
|
-
|
|
10
|
-
This plugin exposes the following [components](https://core.hitchy.org/internals/components.html) in context of your application:
|
|
11
|
-
|
|
12
|
-
### Controllers
|
|
13
|
-
|
|
14
|
-
The following [controlllers](https://core.hitchy.org/internals/components.html#controllers) are provided for implementing some default endpoints:
|
|
15
|
-
|
|
16
|
-
* [User](controller/user.md)
|
|
17
|
-
|
|
18
|
-
### Policies
|
|
19
|
-
|
|
20
|
-
Several [policies](https://core.hitchy.org/internals/components.html#policies) are available for customizing authentication and authorization support in your application:
|
|
21
|
-
|
|
22
|
-
* [Authentication](policy/authentication.md)
|
|
23
|
-
* [Authorization](policy/authorization.md)
|
|
24
|
-
* [User](policy/user.md)
|
|
25
|
-
|
|
26
|
-
### Models
|
|
27
|
-
|
|
28
|
-
These [models](https://core.hitchy.org/internals/components.html#models) are provided to manage access control at runtime:
|
|
29
|
-
|
|
30
|
-
* [User](model/user.md)
|
|
31
|
-
* [Role](model/role.md)
|
|
32
|
-
* [UserToRole](model/user-to-role.md)
|
|
33
|
-
* [AuthorizationRule](model/authorization-rule.md)
|
|
34
|
-
|
|
35
|
-
### Services
|
|
36
|
-
|
|
37
|
-
Commonly useful [services](https://core.hitchy.org/internals/components.html#services) regarding authentication and authorization are:
|
|
38
|
-
|
|
39
|
-
* [AuthenticationPassport](service/authentication-passport.md)
|
|
40
|
-
* [AuthenticationStrategies](service/authentication-strategies.md)
|
|
41
|
-
* [AuthManager](service/auth-manager.md)
|
|
42
|
-
* [AuthorizationNode](service/authorization-node.md)
|
|
43
|
-
* [AuthorizationTree](service/authorization-tree.md)
|
|
44
|
-
* [AuthorizationPolicyGenerator](service/authorization-policy-generator.md)
|
|
45
|
-
|
|
46
|
-
## Configuration
|
|
47
|
-
|
|
48
|
-
In addition to components listed above the plugin is processing some optionally available [runtime configuration](config.md).
|
|
49
|
-
|
|
50
|
-
## Routing defaults
|
|
51
|
-
|
|
52
|
-
Unless [disabled in runtime configuration](config.md#config-auth-prefix), this plugin is always setting up [routes providing basic user authentication](routing.md) to a client.
|