Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Daily Thought App
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COM3014-Coursework
Daily Thought App
Commits
ca8d5a65
Commit
ca8d5a65
authored
1 year ago
by
Felipe D'Abrantes
Browse files
Options
Downloads
Patches
Plain Diff
Update feed-service JWT structure
parent
83b39452
No related branches found
Branches containing commit
No related tags found
1 merge request
!20
Prevent non-admin users from inserting a question"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
backend-services/feed-service/app/models/actions/AuthenticationRequest.scala
+7
-6
7 additions, 6 deletions
...ed-service/app/models/actions/AuthenticationRequest.scala
with
7 additions
and
6 deletions
backend-services/feed-service/app/models/actions/AuthenticationRequest.scala
+
7
−
6
View file @
ca8d5a65
...
...
@@ -14,7 +14,7 @@ import play.api.libs.json.Json
import
javax.inject.Inject
class
AuthenticationRequest
[
A
](
val
jwt
:
String
,
val
requesterId
:
Option
[
ObjectId
],
request
:
Request
[
A
])
class
AuthenticationRequest
[
A
](
val
jwt
:
String
,
val
requesterId
:
Option
[
ObjectId
],
val
isAdmin
:
Boolean
,
request
:
Request
[
A
])
extends
WrappedRequest
[
A
](
request
)
...
...
@@ -30,8 +30,8 @@ class AuthenticationTransformer @Inject() (implicit val executionContext: Execut
* @return The new parameter to pass to the Action block.
*/
override
def
transform
[
A
](
request
:
Request
[
A
])
=
Future
.
successful
{
val
(
jwt
:
String
,
requesterId
:
Option
[
ObjectId
])
=
processJWT
(
request
)
new
AuthenticationRequest
(
jwt
,
requesterId
,
request
)
val
(
jwt
:
String
,
requesterId
:
Option
[
ObjectId
]
,
isAdmin
:
Boolean
)
=
processJWT
(
request
)
new
AuthenticationRequest
(
jwt
,
requesterId
,
isAdmin
,
request
)
}
/**
...
...
@@ -40,7 +40,7 @@ class AuthenticationTransformer @Inject() (implicit val executionContext: Execut
* @param request The incoming request.
* @return The user ID specified in the JWT's payload.
*/
def
processJWT
[
A
](
request
:
Request
[
A
])
:
(
String
,
Option
[
ObjectId
])
=
{
def
processJWT
[
A
](
request
:
Request
[
A
])
:
(
String
,
Option
[
ObjectId
]
,
Boolean
)
=
{
val
privateKey
=
ConfigFactory
.
load
().
getString
(
"jwt.privateKey"
)
try
{
...
...
@@ -53,13 +53,14 @@ class AuthenticationTransformer @Inject() (implicit val executionContext: Execut
val
content
=
payload
.
get
.
content
val
jsonContent
=
Json
.
parse
(
content
)
val
requesterId
=
(
jsonContent
\
"userId"
).
as
[
String
]
val
isAdmin
=
(
jsonContent
\
"admin"
).
as
[
Boolean
]
(
token
,
Some
(
new
ObjectId
(
requesterId
)))
(
token
,
Some
(
new
ObjectId
(
requesterId
))
,
isAdmin
)
}
catch
{
case
ex
:
Throwable
=>
{
println
(
s
"JWT Error: $ex"
)
(
""
,
None
)
(
""
,
None
,
false
)
}
}
}
...
...
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