-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscala-jwt-hardcoded-secret-scala-test.yml
52 lines (52 loc) · 1.4 KB
/
scala-jwt-hardcoded-secret-scala-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
id: scala-jwt-hardcoded-secret-scala
valid:
- |
invalid:
- |
import com.auth0.jwt.algorithms.Algorithm
class App {
def bad1(): Unit = {
try {
val algorithm = Algorithm.HMAC256("secret")
val token = JWT.create()
.withIssuer("auth0")
.sign(algorithm)
} catch {
case exception: JWTCreationException =>
println(s"Error creating JWT: ${exception.getMessage}")
}
}
}
- |
import com.auth0.jwt.algorithms.Algorithm
class SessionService {
def createSessionToken(userId: String): String = {
try {
val algorithm = Algorithm.HMAC512("secretKey")
val token = JWT.create()
.withIssuer("auth0")
.withClaim("userId", userId)
.sign(algorithm)
token
} catch {
case e: JWTCreationException =>
""
}
}
}
- |
import com.auth0.jwt.algorithms.Algorithm
class AuthService {
def createAuthToken(username: String): String = {
try {
val algorithm = Algorithm.HMAC384("secretKey")
val token = JWT.create()
.withIssuer("auth0")
.withClaim("username", username)
.sign(algorithm)
token
} catch {
case e: JWTCreationException =>
}
}
}