Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ehasa-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WIMMA Lab 2019
Overflow
ehasa-backend
Commits
7ed2d801
Commit
7ed2d801
authored
5 years ago
by
L4168
Browse files
Options
Downloads
Patches
Plain Diff
added check for authorization header
parent
a1e7ac42
No related branches found
No related tags found
3 merge requests
!59
Development to master
,
!31
Development
,
!23
Faction tasks + Piirto
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/shared/roles.guard.ts
+11
-4
11 additions, 4 deletions
src/shared/roles.guard.ts
with
11 additions
and
4 deletions
src/shared/roles.guard.ts
+
11
−
4
View file @
7ed2d801
...
@@ -18,7 +18,7 @@ export class RolesGuard implements CanActivate {
...
@@ -18,7 +18,7 @@ export class RolesGuard implements CanActivate {
private
readonly
reflector
:
Reflector
,
private
readonly
reflector
:
Reflector
,
@
InjectRepository
(
Game_PersonEntity
)
@
InjectRepository
(
Game_PersonEntity
)
private
game_PersonRepository
:
Repository
<
Game_PersonEntity
>
,
private
game_PersonRepository
:
Repository
<
Game_PersonEntity
>
,
)
{}
)
{}
async
canActivate
(
context
:
ExecutionContext
):
Promise
<
boolean
>
{
async
canActivate
(
context
:
ExecutionContext
):
Promise
<
boolean
>
{
// get roles that are allowed access, identified by @Roles('role') decorators in controllers
// get roles that are allowed access, identified by @Roles('role') decorators in controllers
...
@@ -27,9 +27,16 @@ export class RolesGuard implements CanActivate {
...
@@ -27,9 +27,16 @@ export class RolesGuard implements CanActivate {
return
true
;
return
true
;
}
}
const
request
=
context
.
switchToHttp
().
getRequest
();
const
request
=
context
.
switchToHttp
().
getRequest
();
const
gameId
=
request
.
params
.
id
// check for authorization header
if
(
!
request
.
headers
.
authorization
)
{
return
false
;
}
const
gameId
=
request
.
params
.
id
;
const
user
=
await
this
.
getUserObject
(
request
.
headers
.
authorization
);
const
user
=
await
this
.
getUserObject
(
request
.
headers
.
authorization
);
const
role
=
await
this
.
game_PersonRepository
.
findOne
({
person
:
user
[
'
id
'
],
game
:
gameId
})
const
role
=
await
this
.
game_PersonRepository
.
findOne
({
person
:
user
[
'
id
'
],
game
:
gameId
,
});
// check that the role matches the criteria and that token is valid for this game
// check that the role matches the criteria and that token is valid for this game
return
role
&&
roles
.
includes
(
role
[
'
role
'
]);
return
role
&&
roles
.
includes
(
role
[
'
role
'
]);
}
}
...
@@ -42,7 +49,7 @@ export class RolesGuard implements CanActivate {
...
@@ -42,7 +49,7 @@ export class RolesGuard implements CanActivate {
// get the token
// get the token
const
token
=
auth
.
split
(
'
'
)[
1
];
const
token
=
auth
.
split
(
'
'
)[
1
];
try
{
try
{
return
await
jwt
.
verify
(
token
,
process
.
env
.
SECRET
)
return
await
jwt
.
verify
(
token
,
process
.
env
.
SECRET
)
;
}
catch
(
err
)
{
}
catch
(
err
)
{
const
message
=
`Token error:
${
err
.
message
||
err
.
name
}
`
;
const
message
=
`Token error:
${
err
.
message
||
err
.
name
}
`
;
throw
new
HttpException
(
message
,
HttpStatus
.
FORBIDDEN
);
throw
new
HttpException
(
message
,
HttpStatus
.
FORBIDDEN
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment