Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
token-based-authz-middleware
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
tools
token-based-authz-middleware
Commits
d25089ff
Commit
d25089ff
authored
Oct 30, 2019
by
Vadym Gidulian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added README.md
parent
f0370302
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
0 deletions
+77
-0
README.md
README.md
+77
-0
No files found.
README.md
0 → 100644
View file @
d25089ff
# token-based-authz-middleware
An Express middleware for token-based authorization.
## Usage
```
js
app
.
use
(
authzMiddleware
(
options
))
```
### Options
-
`headerName`
`[string]`
Default:
`X-Token`
Header name used to pass a token.
-
`pathToRules`
`[string]`
Path to file containing tokens and rules associated with them.
### Rules
Rules are a JSON file containing a single object with tokens as keys and rules associated with them as values.
```
{
"token1": <tokenRules>,
"token2": <tokenRules>,
...
}
```
`<tokenRules>`
may be one of the following:
-
`boolean`
- if
`true`
access is allowed, denied otherwise.
-
`<tokenRule>`
- an object, which may contain the following properties:
-
`methods`
- an array of allowed HTTP methods
-
`paths`
- an array of paths access to which is allowed. Path is a
`RegExp`
string.
_At least one property must be specified._
-
`Array`
- an array of
`<tokenRule>`
s. The resulting rule is a union of listed rules.
Tokens specified in rules are trimmed. Spaces around tokens should be avoided because it may lead to ambiguous behavior.
Empty string may be used to define rules for requests w/o token or w/ empty one.
#### Example
```
json
{
"token1"
:
false
,
"token2"
:
true
,
"token3"
:
{
"methods"
:
[
"get"
]
},
"token4"
:
{
"paths"
:
[
"^/admin"
]
},
"token5"
:
[
{
"methods"
:
[
"get"
]
},
{
"methods"
:
[
"post"
],
"paths"
:
[
"comment"
]
}
],
""
:
{
"methods"
:
[
"get"
]
}
}
```
-
`token1`
- All requests will be blocked.
-
`token2`
- All requests will pass.
-
`token3`
- Only
`GET`
requests will pass.
-
`token4`
- All requests to paths beginning with
`admin`
will pass.
-
`token5`
- Only
`GET`
requests or
`POST`
requests to paths containing
`comment`
will pass.
-
All
`GET`
requests w/o token or w/ empty one will pass.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment