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" description: "JSON Web Token"
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
EIS: "name=JSON Web Token (JWT)", "src=https://tools.ietf.org/html/rfc7519", "protocol=uri"
deferred class deferred class
JWT JWT

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -6,6 +6,7 @@ note
]" ]"
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
EIS: "name=JOSE Header", "src=https://tools.ietf.org/html/rfc7519#section-5", "protocol=uri"
class class
JWT_HEADER JWT_HEADER
@@ -52,6 +53,10 @@ feature -- Access
-- The issuer can freely set an algorithm to verify the signature on the token. -- The issuer can freely set an algorithm to verify the signature on the token.
-- However, some supported algorithms are insecure. -- 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 feature -- Conversion
string: STRING string: STRING
@@ -67,7 +72,13 @@ feature -- Conversion
end end
Result.append (",%"alg%":%"") Result.append (",%"alg%":%"")
Result.append (algorithm) 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 end
feature -- Element change feature -- Element change
@@ -84,13 +95,21 @@ feature -- Element change
set_algorithm (alg: detachable READABLE_STRING_8) set_algorithm (alg: detachable READABLE_STRING_8)
do do
if alg = Void then if
alg = Void or else
alg.is_case_insensitive_equal ("none")
then
algorithm := "none" algorithm := "none"
else else
algorithm := alg algorithm := alg.as_upper
end end
end end
set_private_key_id (a_id: detachable READABLE_STRING_8)
do
private_key_id := a_id
end
feature -- Element change feature -- Element change
import_json (a_json: READABLE_STRING_8) 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 if attached {JSON_STRING} jo.item ("alg") as j_alg then
set_algorithm (j_alg.unescaped_string_8) set_algorithm (j_alg.unescaped_string_8)
end end
if attached {JSON_STRING} jo.item ("kid") as j_kid then
set_private_key_id (j_kid.unescaped_string_8)
end
end end
end end

View File

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

View File

@@ -57,6 +57,22 @@ feature -- Test
assert ("signature", jwt.encoded_string ("secret").same_string ("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.pcHcZspUvuiqIPVB_i_qmcvCJv63KLUgIAKIlXI1gY8")) assert ("signature", jwt.encoded_string ("secret").same_string ("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.pcHcZspUvuiqIPVB_i_qmcvCJv63KLUgIAKIlXI1gY8"))
end 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 test_jwt
local local
jwt: JWS jwt: JWS