Updated JWT library with class descriptions and better features names.

JWT library fixed to use agorithms names in upper case.
Updated README.
This commit is contained in:
2018-11-16 19:26:12 +01:00
parent 7f36e539f1
commit 4f8341e04e
9 changed files with 53 additions and 18 deletions

View File

@@ -2,6 +2,7 @@ note
description: "JSON Web Token"
date: "$Date$"
revision: "$Revision$"
EIS: "name=JSON Web Token (JWT)", "src=https://tools.ietf.org/html/rfc7519", "protocol=uri"
deferred class
JWT

View File

@@ -1,6 +1,5 @@
note
description: "Summary description for {JWT_ALG}."
author: ""
description: "JWT signature is based on Current algorithm"
date: "$Date$"
revision: "$Revision$"

View File

@@ -1,6 +1,5 @@
note
description: "Summary description for {JWT_ALG_HS256}."
author: ""
description: "JWT signature is based on HS256=HMAC+SHA256 algorithm."
date: "$Date$"
revision: "$Revision$"
@@ -12,7 +11,7 @@ inherit
feature -- Access
name: STRING = "hs256"
name: STRING = "HS256"
encoded_string (a_message: READABLE_STRING_8; a_secret: READABLE_STRING_8): STRING
do

View File

@@ -1,9 +1,8 @@
note
description: "Summary description for {JWT_ALG_NONE}."
author: ""
description: "Object representing algorithm `NONE'"
date: "$Date$"
revision: "$Revision$"
EIS: "name=Algorithm none", "src=https://tools.ietf.org/html/rfc7518#section-3.6", "protocol=uri"
class
JWT_ALG_NONE

View File

@@ -1,8 +1,9 @@
note
description: "Summary description for {JWT_ALGORITHMS}."
author: ""
description: "JSON Web Algorithms (JWA)"
date: "$Date$"
revision: "$Revision$"
EIS: "name= JSON Web Algorithms", "src=https://tools.ietf.org/html/rfc7518", "protocol=uri"
class
JWT_ALGORITHMS

View File

@@ -1,9 +1,8 @@
note
description: "Summary description for {JWT_CLAIMSET}."
author: ""
description: "Object representing a JWT claim set"
date: "$Date$"
revision: "$Revision$"
EIS: "name=JWT claims", "src=https://tools.ietf.org/html/rfc7519#section-4", "protocol=uri"
class
JWT_CLAIMSET

View File

@@ -6,6 +6,7 @@ note
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=JOSE Header", "src=https://tools.ietf.org/html/rfc7519#section-5", "protocol=uri"
class
JWT_HEADER
@@ -52,6 +53,10 @@ feature -- Access
-- The issuer can freely set an algorithm to verify the signature on the token.
-- However, some supported algorithms are insecure.
private_key_id: detachable READABLE_STRING_8
-- For the kid field in the header, specify your service account's private key ID.
-- You can find this value in the private_key_id field of your service account JSON file.
feature -- Conversion
string: STRING
@@ -67,7 +72,13 @@ feature -- Conversion
end
Result.append (",%"alg%":%"")
Result.append (algorithm)
Result.append ("%"}")
Result.append ("%"")
if attached private_key_id as kid then
Result.append (",%"kid%":%"")
Result.append (kid)
Result.append ("%"")
end
Result.append ("}")
end
feature -- Element change
@@ -84,13 +95,21 @@ feature -- Element change
set_algorithm (alg: detachable READABLE_STRING_8)
do
if alg = Void then
if
alg = Void or else
alg.is_case_insensitive_equal ("none")
then
algorithm := "none"
else
algorithm := alg
algorithm := alg.as_upper
end
end
set_private_key_id (a_id: detachable READABLE_STRING_8)
do
private_key_id := a_id
end
feature -- Element change
import_json (a_json: READABLE_STRING_8)
@@ -111,6 +130,9 @@ feature -- Element change
if attached {JSON_STRING} jo.item ("alg") as j_alg then
set_algorithm (j_alg.unescaped_string_8)
end
if attached {JSON_STRING} jo.item ("kid") as j_kid then
set_private_key_id (j_kid.unescaped_string_8)
end
end
end

View File

@@ -1,6 +1,5 @@
note
description: "Summary description for {JWT_UTILITIES}."
author: ""
date: "$Date$"
revision: "$Revision$"

View File

@@ -57,6 +57,22 @@ feature -- Test
assert ("signature", jwt.encoded_string ("secret").same_string ("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.pcHcZspUvuiqIPVB_i_qmcvCJv63KLUgIAKIlXI1gY8"))
end
test_jwt_alg_caseless
local
jwt: JWS
ut: JWT_UTILITIES
do
create jwt
jwt.set_algorithm ("HS256")
assert("HS256", jwt.algorithm.same_string ("HS256"))
create jwt
jwt.set_algorithm ("hs256")
assert("hs256", jwt.algorithm.same_string ("HS256"))
create jwt
jwt.set_algorithm ("None")
assert("None", jwt.algorithm.same_string ("none"))
end
test_jwt
local
jwt: JWS