@pagopa/io-react-native-jwt 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/pagopa/ioreactnativejwt/IoReactNativeJwtModule.kt +22 -4
- package/ios/IoReactNativeJwt.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/IoReactNativeJwt.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/IoReactNativeJwt.xcodeproj/project.xcworkspace/xcuserdata/francesco.grauso.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/IoReactNativeJwt.xcodeproj/xcuserdata/francesco.grauso.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Provides much greater performance for decoding, signing and verifying JWTs!
|
|
|
5
5
|
|
|
6
6
|
🚀 Use only native functions via the following libraries:
|
|
7
7
|
|
|
8
|
-
- 🤖 [nimbus-jose-jwt](https://
|
|
8
|
+
- 🤖 [nimbus-jose-jwt](https://bitbucket.org/connect2id/nimbus-jose-jwt) on Android
|
|
9
9
|
- 📱 [JOSESwift](https://github.com/airsidemobile/JOSESwift/) on iOS
|
|
10
10
|
|
|
11
11
|
## Installation
|
package/android/build.gradle
CHANGED
|
@@ -83,7 +83,7 @@ dependencies {
|
|
|
83
83
|
//noinspection GradleDynamicVersion
|
|
84
84
|
implementation "com.facebook.react:react-native:+"
|
|
85
85
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
86
|
-
implementation 'com.nimbusds:nimbus-jose-jwt:
|
|
86
|
+
implementation 'com.nimbusds:nimbus-jose-jwt:9.30.2'
|
|
87
87
|
implementation 'org.bouncycastle:bcprov-jdk15on:[1.56,)'
|
|
88
88
|
|
|
89
89
|
}
|
|
@@ -7,9 +7,11 @@ import com.facebook.react.bridge.ReactApplicationContext
|
|
|
7
7
|
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
8
8
|
import com.facebook.react.bridge.ReactMethod
|
|
9
9
|
import com.facebook.react.bridge.ReadableMap
|
|
10
|
+
import com.nimbusds.jose.JOSEObject
|
|
10
11
|
import com.nimbusds.jose.JWEEncrypter
|
|
11
12
|
import com.nimbusds.jose.JWEHeader
|
|
12
13
|
import com.nimbusds.jose.JWEObject
|
|
14
|
+
import com.nimbusds.jose.JWSHeader
|
|
13
15
|
import com.nimbusds.jose.Payload
|
|
14
16
|
import com.nimbusds.jose.crypto.ECDSAVerifier
|
|
15
17
|
import com.nimbusds.jose.crypto.RSAEncrypter
|
|
@@ -18,9 +20,11 @@ import com.nimbusds.jose.crypto.bc.BouncyCastleProviderSingleton
|
|
|
18
20
|
import com.nimbusds.jose.crypto.impl.ECDSA.transcodeSignatureToConcat
|
|
19
21
|
import com.nimbusds.jose.jwk.ECKey
|
|
20
22
|
import com.nimbusds.jose.jwk.RSAKey
|
|
21
|
-
import com.nimbusds.
|
|
23
|
+
import com.nimbusds.jose.util.JSONObjectUtils
|
|
24
|
+
import com.nimbusds.jose.util.StandardCharset
|
|
22
25
|
import org.json.JSONObject
|
|
23
26
|
import java.security.MessageDigest
|
|
27
|
+
import java.text.ParseException
|
|
24
28
|
|
|
25
29
|
|
|
26
30
|
class IoReactNativeJwtModule(reactContext: ReactApplicationContext) :
|
|
@@ -37,7 +41,21 @@ class IoReactNativeJwtModule(reactContext: ReactApplicationContext) :
|
|
|
37
41
|
@ReactMethod
|
|
38
42
|
fun verify(token: String, jwk: ReadableMap, promise: Promise) {
|
|
39
43
|
try {
|
|
40
|
-
|
|
44
|
+
|
|
45
|
+
val parts = JOSEObject.split(token)
|
|
46
|
+
if (parts.size != 3) {
|
|
47
|
+
throw ParseException("Unexpected number of Base64URL parts, must be three", 0)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
val headerString = parts[0]
|
|
51
|
+
val headerJson = JSONObjectUtils.parse(headerString.decodeToString(), -1);
|
|
52
|
+
val header = JWSHeader.parse(headerJson, headerString);
|
|
53
|
+
|
|
54
|
+
val payload = Payload(parts[1])
|
|
55
|
+
val signature = parts[2]
|
|
56
|
+
|
|
57
|
+
var signingInput = header.toBase64URL().toString() + '.' + payload.toBase64URL().toString();
|
|
58
|
+
val signingInputByteArray = signingInput.toByteArray(StandardCharset.UTF_8)
|
|
41
59
|
val jwkJson = JSONObject(jwk.toHashMap())
|
|
42
60
|
var isValid = false
|
|
43
61
|
|
|
@@ -45,12 +63,12 @@ class IoReactNativeJwtModule(reactContext: ReactApplicationContext) :
|
|
|
45
63
|
val internalJwk = ECKey.parse(jwkJson.toString())
|
|
46
64
|
val verifier = ECDSAVerifier(internalJwk)
|
|
47
65
|
verifier.jcaContext.provider = BouncyCastleProviderSingleton.getInstance()
|
|
48
|
-
isValid =
|
|
66
|
+
isValid = verifier.verify(header, signingInputByteArray, signature);
|
|
49
67
|
} else {
|
|
50
68
|
val internalJwk = RSAKey.parse(jwkJson.toString())
|
|
51
69
|
val verifier = RSASSAVerifier(internalJwk)
|
|
52
70
|
verifier.jcaContext.provider = BouncyCastleProviderSingleton.getInstance()
|
|
53
|
-
isValid =
|
|
71
|
+
isValid = verifier.verify(header, signingInputByteArray, signature);
|
|
54
72
|
}
|
|
55
73
|
promise.resolve(isValid)
|
|
56
74
|
|
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>SchemeUserState</key>
|
|
6
|
+
<dict>
|
|
7
|
+
<key>IoReactNativeJwt.xcscheme_^#shared#^_</key>
|
|
8
|
+
<dict>
|
|
9
|
+
<key>orderHint</key>
|
|
10
|
+
<integer>0</integer>
|
|
11
|
+
</dict>
|
|
12
|
+
</dict>
|
|
13
|
+
</dict>
|
|
14
|
+
</plist>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagopa/io-react-native-jwt",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Native support for JWT",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"engines": {
|
|
91
91
|
"node": ">= 16.0.0"
|
|
92
92
|
},
|
|
93
|
-
"packageManager": "^yarn@1.22.
|
|
93
|
+
"packageManager": "^yarn@1.22.21",
|
|
94
94
|
"jest": {
|
|
95
95
|
"preset": "react-native",
|
|
96
96
|
"modulePathIgnorePatterns": [
|