-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched to Godot 4 support, Repaired broken RS256 implementation. (#10)
* Fixed RS256, Switched to Godot 4 Syntax, Updated README * random_secret() and JWTBuilder.neW() now respects the passed parameters * Switch from tabs to spaces * Switch from tabs to spaces
- Loading branch information
1 parent
632e4a1
commit 91d2473
Showing
13 changed files
with
156 additions
and
84 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
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,5 +3,5 @@ | |
name="JWT" | ||
description="" | ||
author="Nicolò (fenix-hub) Santilio" | ||
version="1.5" | ||
version="1.0" | ||
script="plugin.gd" |
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,4 +1,4 @@ | ||
tool | ||
@tool | ||
extends EditorPlugin | ||
|
||
|
||
|
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
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,29 +1,48 @@ | ||
extends Reference | ||
extends RefCounted | ||
class_name JWTAlgorithmBuilder | ||
|
||
|
||
static func random_secret(length: int = 10) -> String: | ||
return Crypto.new().generate_random_bytes(10).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._hash = JWTAlgorithm.Type.HMAC1 | ||
algorithm._alg = JWTAlgorithm.Type.HMAC1 | ||
return algorithm | ||
|
||
|
||
static func HS1(secret: String) -> JWTAlgorithm: | ||
return HSA1(secret) | ||
|
||
|
||
static func HSA256(secret: String) -> JWTAlgorithm: | ||
var algorithm: JWTAlgorithm = JWTAlgorithm.new() | ||
algorithm._secret = secret | ||
algorithm._hash = JWTAlgorithm.Type.HMAC256 | ||
algorithm._alg = JWTAlgorithm.Type.HMAC256 | ||
return algorithm | ||
|
||
static func RSA256(public_key: CryptoKey, private_key: CryptoKey) -> JWTAlgorithm: | ||
|
||
static func HS256(secret: String) -> JWTAlgorithm: | ||
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 | ||
|
||
static func sign(text: String, algorithm: JWTAlgorithm) -> PoolByteArray: | ||
|
||
static func RS256(public_key: CryptoKey, private_key: CryptoKey) -> JWTAlgorithm: | ||
return RSA256(public_key, private_key) | ||
|
||
|
||
static func sign(text: String, algorithm: JWTAlgorithm) -> PackedByteArray: | ||
return algorithm.sign(text) | ||
|
||
|
||
static func verify(jwt: JWTDecoder, algorithm: JWTAlgorithm) -> bool: | ||
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
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,4 +1,4 @@ | ||
extends Reference | ||
extends RefCounted | ||
class_name JWTClaims | ||
|
||
|
||
|
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,11 +1,11 @@ | ||
extends Reference | ||
extends RefCounted | ||
class_name JWTUtils | ||
|
||
static func base64URL_encode(input: PoolByteArray) -> String: | ||
static func base64URL_encode(input: PackedByteArray) -> String: | ||
return Marshalls.raw_to_base64(input).replacen("+","-").replacen("/","_").replacen("=","") | ||
|
||
static func base64URL_decode(input: String) -> String: | ||
static func base64URL_decode(input: String) -> PackedByteArray: | ||
match (input.length() % 4): | ||
2: input += "==" | ||
3: input += "=" | ||
return Marshalls.base64_to_utf8(input.replacen("_","/").replacen("-","+")) | ||
return Marshalls.base64_to_raw(input.replacen("_","/").replacen("-","+")) |
Oops, something went wrong.