-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
428 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ extends EditorPlugin | |
|
||
|
||
func _enter_tree(): | ||
pass | ||
pass | ||
|
||
|
||
func _exit_tree(): | ||
pass | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
extends RefCounted | ||
class_name JWT | ||
extends RefCounted | ||
|
||
|
||
static func create( | ||
algorithm: JWTAlgorithm = null, header_claims: Dictionary = {}, payload_claims: Dictionary = {} | ||
) -> JWTBuilder: | ||
return JWTBuilder.new(algorithm, header_claims, payload_claims) | ||
|
||
static func create(algorithm: JWTAlgorithm = null, header_claims: Dictionary = {}, payload_claims: Dictionary = {}) -> JWTBuilder: | ||
return JWTBuilder.new(algorithm, header_claims, payload_claims) | ||
|
||
static func decode(jwt: String) -> JWTDecoder: | ||
return JWTDecoder.new(jwt) | ||
return JWTDecoder.new(jwt) | ||
|
||
|
||
static func require(algorithm: JWTAlgorithm) -> JWTVerifierBuilder: | ||
return JWTVerifierBuilder.new(algorithm) | ||
return JWTVerifierBuilder.new(algorithm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
extends RefCounted | ||
class_name JWTAlgorithmBuilder | ||
extends RefCounted | ||
|
||
|
||
static func random_secret(length: int = 10) -> String: | ||
return Crypto.new().generate_random_bytes(length).get_string_from_utf8() | ||
return Crypto.new().generate_random_bytes(length).get_string_from_utf8() | ||
|
||
|
||
static func HSA1(secret: String) -> JWTAlgorithm: | ||
var algorithm: JWTAlgorithm = JWTAlgorithm.new() | ||
algorithm._secret = secret | ||
algorithm._alg = JWTAlgorithm.Type.HMAC1 | ||
return algorithm | ||
var algorithm: JWTAlgorithm = JWTAlgorithm.new() | ||
algorithm._secret = secret | ||
algorithm._alg = JWTAlgorithm.Type.HMAC1 | ||
return algorithm | ||
|
||
|
||
static func HS1(secret: String) -> JWTAlgorithm: | ||
return HSA1(secret) | ||
return HSA1(secret) | ||
|
||
|
||
static func HSA256(secret: String) -> JWTAlgorithm: | ||
var algorithm: JWTAlgorithm = JWTAlgorithm.new() | ||
algorithm._secret = secret | ||
algorithm._alg = JWTAlgorithm.Type.HMAC256 | ||
return algorithm | ||
var algorithm: JWTAlgorithm = JWTAlgorithm.new() | ||
algorithm._secret = secret | ||
algorithm._alg = JWTAlgorithm.Type.HMAC256 | ||
return algorithm | ||
|
||
|
||
static func HS256(secret: String) -> JWTAlgorithm: | ||
return HSA256(secret) | ||
return HSA256(secret) | ||
|
||
|
||
static func RSA256(public_key: CryptoKey, private_key: CryptoKey = CryptoKey.new()) -> JWTAlgorithm: | ||
var algorithm: JWTAlgorithm = JWTAlgorithm.new() | ||
algorithm._public_crypto = public_key | ||
algorithm._private_crypto = private_key | ||
algorithm._alg = JWTAlgorithm.Type.RSA256 | ||
return algorithm | ||
var algorithm: JWTAlgorithm = JWTAlgorithm.new() | ||
algorithm._public_crypto = public_key | ||
algorithm._private_crypto = private_key | ||
algorithm._alg = JWTAlgorithm.Type.RSA256 | ||
return algorithm | ||
|
||
|
||
static func RS256(public_key: CryptoKey, private_key: CryptoKey) -> JWTAlgorithm: | ||
return RSA256(public_key, private_key) | ||
return RSA256(public_key, private_key) | ||
|
||
|
||
static func sign(text: String, algorithm: JWTAlgorithm) -> PackedByteArray: | ||
return algorithm.sign(text) | ||
return algorithm.sign(text) | ||
|
||
|
||
static func verify(jwt: JWTDecoder, algorithm: JWTAlgorithm) -> bool: | ||
return algorithm.verify(jwt) | ||
return algorithm.verify(jwt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,75 @@ | ||
extends RefCounted | ||
class_name JWTBaseBuilder | ||
extends RefCounted | ||
|
||
|
||
func with_header(header_claims: Dictionary) -> JWTBaseBuilder: | ||
self.header_claims = header_claims | ||
return self | ||
self.header_claims = header_claims | ||
return self | ||
|
||
|
||
func with_algorithm(algorithm: String) -> JWTBaseBuilder: | ||
self.header_claims[JWTClaims.Public.ALGORITHM] = algorithm | ||
return self | ||
self.header_claims[JWTClaims.Public.ALGORITHM] = algorithm | ||
return self | ||
|
||
|
||
func with_type(type: String) -> JWTBaseBuilder: | ||
self.header_claims[JWTClaims.Public.TYPE] = type | ||
return self | ||
self.header_claims[JWTClaims.Public.TYPE] = type | ||
return self | ||
|
||
|
||
func with_key_id(key_id: String) -> JWTBaseBuilder: | ||
self.header_claims[JWTClaims.Public.KEY_ID] = key_id | ||
return self | ||
self.header_claims[JWTClaims.Public.KEY_ID] = key_id | ||
return self | ||
|
||
|
||
func with_issuer(issuer: String) -> JWTBaseBuilder: | ||
add_claim(JWTClaims.Public.ISSUER, issuer) | ||
return self | ||
add_claim(JWTClaims.Public.ISSUER, issuer) | ||
return self | ||
|
||
|
||
func with_subject(subject: String) -> JWTBaseBuilder: | ||
add_claim(JWTClaims.Public.SUBJECT, subject) | ||
return self | ||
add_claim(JWTClaims.Public.SUBJECT, subject) | ||
return self | ||
|
||
|
||
func with_audience(audience: PackedStringArray) -> JWTBaseBuilder: | ||
add_claim(JWTClaims.Public.AUDIENCE, audience) | ||
return self | ||
add_claim(JWTClaims.Public.AUDIENCE, audience) | ||
return self | ||
|
||
|
||
# Expires At in UNIX time (Time.get_unix_time_from_system()) | ||
func with_expires_at(expires_at: int) -> JWTBaseBuilder: | ||
add_claim(JWTClaims.Public.EXPIRES_AT, expires_at) | ||
return self | ||
add_claim(JWTClaims.Public.EXPIRES_AT, expires_at) | ||
return self | ||
|
||
|
||
# Not Before in UNIX time (Time.get_unix_time_from_system()) | ||
func with_not_before(not_before: int) -> JWTBaseBuilder: | ||
add_claim(JWTClaims.Public.NOT_BEFORE, not_before) | ||
return self | ||
add_claim(JWTClaims.Public.NOT_BEFORE, not_before) | ||
return self | ||
|
||
|
||
# Issued At in UNIX time (Time.get_unix_time_from_system()) | ||
func with_issued_at(issued_at: int) -> JWTBaseBuilder: | ||
add_claim(JWTClaims.Public.ISSUED_AT, issued_at) | ||
return self | ||
add_claim(JWTClaims.Public.ISSUED_AT, issued_at) | ||
return self | ||
|
||
|
||
func with_jwt_id(jwt_id: String) -> JWTBaseBuilder: | ||
self.header_claims[JWTClaims.Public.JWT_ID] = jwt_id | ||
return self | ||
self.header_claims[JWTClaims.Public.JWT_ID] = jwt_id | ||
return self | ||
|
||
|
||
func with_claim(name: String, value) -> JWTBaseBuilder: | ||
add_claim(name, str(value)) | ||
return self | ||
add_claim(name, str(value)) | ||
return self | ||
|
||
|
||
func with_payload(claims: Dictionary) -> JWTBaseBuilder: | ||
for claim in claims.keys(): | ||
add_claim(claim, claims[claim]) | ||
return self | ||
for claim in claims.keys(): | ||
add_claim(claim, claims[claim]) | ||
return self | ||
|
||
|
||
func add_claim(_claim_name: String, _claim_value) -> void: | ||
return | ||
return |
Oops, something went wrong.