Skip to content

Commit 04b9c39

Browse files
Merge pull request #357 from velocitycareerlabs/VL-7806,VL-7806-auth-token-submit-pres
feat: support auth token for feed submission
2 parents 209a219 + e8bd2f0 commit 04b9c39

File tree

19 files changed

+1567
-899
lines changed

19 files changed

+1567
-899
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ dependencies {
9292
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
9393

9494
//--------- Must: be added:
95-
implementation "io.velocitycareerlabs:vcl:2.6.14"
95+
implementation "io.velocitycareerlabs:vcl:2.7.1"
9696
implementation 'com.nimbusds:nimbus-jose-jwt:10.0.1'
9797
implementation "androidx.security:security-crypto:1.1.0-alpha06"
9898
//-------------------------

android/src/main/java/io/velocitycareerlabs/reactnative/VclReactNativeModule.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ import io.velocitycareerlabs.api.VCLProvider
3737
import io.velocitycareerlabs.api.entities.error.VCLError
3838
import io.velocitycareerlabs.api.entities.initialization.VCLInitializationDescriptor
3939
import io.velocitycareerlabs.reactnative.extensions.toThrowable
40+
import io.velocitycareerlabs.reactnative.utlis.Converter.authTokenToMap
4041
import io.velocitycareerlabs.reactnative.utlis.Converter.didJwkToMap
42+
import io.velocitycareerlabs.reactnative.utlis.Converter.mapToAuthToken
43+
import io.velocitycareerlabs.reactnative.utlis.Converter.mapToAuthTokenDescriptor
4144
import io.velocitycareerlabs.reactnative.utlis.Converter.mapToDidJwk
4245
import io.velocitycareerlabs.reactnative.utlis.Converter.mapToDidJwkDescriptor
4346
import io.velocitycareerlabs.reactnative.utlis.Converter.mapToInitializationDescriptor
@@ -152,11 +155,13 @@ class VclReactNativeModule(reactContext: ReactApplicationContext) :
152155
@ReactMethod
153156
fun submitPresentation(
154157
presentationSubmissionMap: ReadableMap,
158+
authTokenMap: ReadableMap? = null,
155159
promise: Promise
156160
) {
157161
try {
158162
vcl.submitPresentation(
159163
presentationSubmission = mapToPresentationSubmission(presentationSubmissionMap),
164+
authToken = mapToAuthToken(authTokenMap),
160165
successHandler = {
161166
promise.resolve(presentationSubmissionResultToMap(it))
162167
},
@@ -294,6 +299,25 @@ class VclReactNativeModule(reactContext: ReactApplicationContext) :
294299
}
295300
}
296301

302+
@ReactMethod
303+
fun getAuthToken(
304+
authTokenDescriptorMap: ReadableMap,
305+
promise: Promise
306+
) {
307+
try {
308+
vcl.getAuthToken(
309+
authTokenDescriptor = mapToAuthTokenDescriptor(authTokenDescriptorMap),
310+
successHandler = {
311+
promise.resolve(authTokenToMap(it))
312+
},
313+
errorHandler = {
314+
promise.reject(it.toThrowable())
315+
})
316+
} catch (ex: Exception) {
317+
promise.reject(VCLError(ex).toThrowable())
318+
}
319+
}
320+
297321
@ReactMethod
298322
fun getCredentialTypesUIFormSchema(
299323
credentialTypesUIFormSchemaDescriptorMap: ReadableMap,

android/src/main/java/io/velocitycareerlabs/reactnative/utlis/Converter.kt

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ object Converter {
242242
)
243243
presentationRequestMap.putMap("deepLink", deepLinkToMap(presentationRequest.deepLink))
244244
presentationRequestMap.putMap("didJwk", didJwkToMap(presentationRequest.didJwk))
245+
presentationRequestMap.putBoolean("feed", presentationRequest.feed)
245246
presentationRequestMap.putMap(
246247
"remoteCryptoServicesToken",
247248
tokenToMap(presentationRequest.remoteCryptoServicesToken)
@@ -471,8 +472,8 @@ object Converter {
471472
VCLIssuingType.Career
472473
),
473474
credentialTypes =
474-
(credentialManifestDescriptorByServiceMap.getArrayOpt("credentialTypes")?.toArrayList()
475-
?.toList() as? List<String>),
475+
(credentialManifestDescriptorByServiceMap.getArrayOpt("credentialTypes")?.toArrayList()
476+
?.toList() as? List<String>),
476477
pushDelegate = mapToPushDelegate(
477478
credentialManifestDescriptorByServiceMap.getMapOpt("pushDelegate")
478479
),
@@ -683,6 +684,46 @@ object Converter {
683684
fun mapToJwt(jwtMap: ReadableMap?) =
684685
VCLJwt(encodedJwt = jwtMap?.getStringOpt("encodedJwt") ?: "")
685686

687+
fun mapToAuthTokenDescriptor(
688+
authTokenDescriptorMap: ReadableMap
689+
): VCLAuthTokenDescriptor {
690+
authTokenDescriptorMap.getMapOpt("presentationRequest")?.let { presentationRequestMap ->
691+
return VCLAuthTokenDescriptor(
692+
presentationRequest = mapToPresentationRequest(
693+
presentationRequestMap
694+
)
695+
)
696+
}
697+
return VCLAuthTokenDescriptor(
698+
authTokenUri = authTokenDescriptorMap.getStringOpt("authTokenUri") ?: "",
699+
refreshToken = mapToToken(authTokenDescriptorMap.getMapOpt("refreshToken")),
700+
walletDid = authTokenDescriptorMap.getStringOpt("walletDid"),
701+
relyingPartyDid = authTokenDescriptorMap.getStringOpt("relyingPartyDid"),
702+
vendorOriginContext = authTokenDescriptorMap.getStringOpt("vendorOriginContext")
703+
)
704+
}
705+
706+
fun authTokenToMap(
707+
authToken: VCLAuthToken
708+
): ReadableMap {
709+
val authTokenMap = Arguments.createMap()
710+
authTokenMap.putMap("payload", authToken.payload.toReadableMap())
711+
authTokenMap.putString("authTokenUri", authToken.authTokenUri)
712+
authTokenMap.putMap("refreshToken", tokenToMap(authToken.refreshToken))
713+
authTokenMap.putString("walletDid", authToken.walletDid)
714+
authTokenMap.putString("relyingPartyDid", authToken.relyingPartyDid)
715+
return authTokenMap
716+
}
717+
718+
fun mapToAuthToken(authTokenMap: ReadableMap?): VCLAuthToken {
719+
return VCLAuthToken(
720+
payload = authTokenMap?.getMapOpt("payload")?.toJsonObject() ?: JSONObject(),
721+
authTokenUri = authTokenMap?.getStringOpt("authTokenUri"),
722+
walletDid = authTokenMap?.getStringOpt("walletDid"),
723+
relyingPartyDid = authTokenMap?.getStringOpt("relyingPartyDid")
724+
)
725+
}
726+
686727
fun mapToCredentialTypesUIFormSchemaDescriptor(
687728
credentialTypesUIFormSchemaDescriptorMap: ReadableMap
688729
) = VCLCredentialTypesUIFormSchemaDescriptor(

example/ios/Podfile

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ require Pod::Executable.execute_command('node', ['-p',
1111
platform :ios, min_ios_version_supported
1212
prepare_react_native_project!
1313

14-
# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
15-
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
16-
#
17-
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
18-
# ```js
19-
# module.exports = {
20-
# dependencies: {
21-
# ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
22-
# ```
23-
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled
24-
2514
linkage = ENV['USE_FRAMEWORKS']
2615
if linkage != nil
2716
Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
@@ -33,28 +22,17 @@ target 'VclReactNativeExample' do
3322

3423
use_react_native!(
3524
:path => config[:reactNativePath],
36-
# Enables Flipper.
37-
#
38-
# Note that if you have use_frameworks! enabled, Flipper will not work and
39-
# you should disable the next line.
40-
# I disabled flipper manually
41-
# :flipper_configuration => flipper_config,
42-
4325
# An absolute path to your application root.
4426
:app_path => "#{Pod::Config.instance.installation_root}/.."
4527
)
4628

47-
target 'VclReactNativeExampleTests' do
48-
inherit! :complete
49-
# Pods for testing
50-
end
51-
5229
post_install do |installer|
5330
# https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
5431
react_native_post_install(
5532
installer,
5633
config[:reactNativePath],
57-
:mac_catalyst_enabled => false
34+
:mac_catalyst_enabled => false,
35+
# :ccache_enabled => true
5836
)
5937
end
6038
end

example/ios/Podfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,12 +1054,12 @@ PODS:
10541054
- React-logger (= 0.73.6)
10551055
- React-perflogger (= 0.73.6)
10561056
- SocketRocket (0.6.1)
1057-
- VCL (2.6.14)
1058-
- velocitycareerlabs-vcl-react-native (2.6.14):
1057+
- VCL (2.7.1)
1058+
- velocitycareerlabs-vcl-react-native (2.7.1):
10591059
- glog
10601060
- RCT-Folly (= 2022.05.16.00)
10611061
- React-Core
1062-
- VCL (= 2.6.14)
1062+
- VCL (= 2.7.1)
10631063
- Yoga (1.14.0)
10641064

10651065
DEPENDENCIES:
@@ -1276,10 +1276,10 @@ SPEC CHECKSUMS:
12761276
React-utils: 288c9cb9a73bb150c273c84df7c2f8546f28e23f
12771277
ReactCommon: 2e5492a3e3a8e72d635c266405e49d12627e5bf0
12781278
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
1279-
VCL: 733b44acfd727cb698d004200496191f70f21d4a
1280-
velocitycareerlabs-vcl-react-native: 0bf8f684f9eb01b265ebf11d47fb802c06893a64
1279+
VCL: c3b7e075776bbbb1f3632f0533d9b44faeafc646
1280+
velocitycareerlabs-vcl-react-native: e0d49c576438d8f2b4d8f471028ae9f3e3ed5eef
12811281
Yoga: 805bf71192903b20fc14babe48080582fee65a80
12821282

1283-
PODFILE CHECKSUM: b019a9f171e06cc915918d81c74115c30ea1b65c
1283+
PODFILE CHECKSUM: dda665d1488c2a02df92eccd852bd6de0cd38761
12841284

12851285
COCOAPODS: 1.16.2

0 commit comments

Comments
 (0)