Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.module.annotations.ReactModule
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -57,14 +56,11 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
_requireUserAuthentication: Boolean,
_keychainAccess: String?,
username: String?,
appAttestationMap: ReadableMap?,
appAttestation: Boolean,
promise: Promise
) {
val appAttestation = appAttestationMap?.let { map ->
val attestationToken = map.getString("token") ?: return@let null
val keyId = if (map.hasKey("keyId")) map.getString("keyId") else null
AppAttestation(token = attestationToken, keyId = keyId)
}
// Pass a sentinel AppAttestation to signal the native SDK to generate attestation internally
val appAttestationValue = if (appAttestation) AppAttestation(token = "") else null

launch(promise) {
val response = it.addCredential(
Expand All @@ -74,7 +70,7 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
timeout = 0,
authorizationType = 0,
username = username,
appAttestation = appAttestation,
appAttestation = appAttestationValue,
)

if (response.error != null) {
Expand Down
2 changes: 1 addition & 1 deletion ios/AuthsignalInAppModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ @interface RCT_EXTERN_MODULE(AuthsignalInAppModule, NSObject)
withRequireUserAuthentication:(BOOL)requireUserAuthentication
withKeychainAccess:(NSString)keychainAccess
withUsername:(NSString)username
withAppAttestation:(NSDictionary)appAttestation
withAppAttestation:(BOOL)appAttestation
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

Expand Down
14 changes: 4 additions & 10 deletions ios/AuthsignalInAppModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AuthsignalInAppModule: NSObject {
withRequireUserAuthentication requireUserAuthentication: Bool,
withKeychainAccess keychainAccess: NSString?,
withUsername username: NSString?,
withAppAttestation appAttestationDict: NSDictionary?,
withAppAttestation appAttestation: Bool,
resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock
) -> Void {
Expand All @@ -73,22 +73,16 @@ class AuthsignalInAppModule: NSObject {
let keychainAccess = getKeychainAccess(value: keychainAccess as String?)
let usernameStr = username as String?

var appAttestation: AppAttestation? = nil
if let dict = appAttestationDict,
let attestationToken = dict["token"] as? String {
appAttestation = AppAttestation(
token: attestationToken,
keyId: dict["keyId"] as? String
)
}
// Pass a sentinel AppAttestation to signal the native SDK to generate attestation internally
let appAttestationValue: AppAttestation? = appAttestation ? AppAttestation(attestationToken: "", keyId: nil) : nil

Task.init {
let response = await authsignal.addCredential(
token: tokenStr,
keychainAccess: keychainAccess,
userPresenceRequired: userPresenceRequired,
username: usernameStr,
appAttestation: appAttestation
appAttestation: appAttestationValue
)

if let error = response.error {
Expand Down
2 changes: 1 addition & 1 deletion src/NativeAuthsignalInAppModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface Spec extends TurboModule {
withRequireUserAuthentication: boolean,
withKeychainAccess: string | null,
withUsername: string | null,
withAppAttestation: Object | null
withAppAttestation: boolean
): Promise<Object | null>;
removeCredential(username: string | null): Promise<boolean>;
verify(
Expand Down
2 changes: 1 addition & 1 deletion src/inapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class AuthsignalInApp {
requireUserAuthentication,
keychainAccess ?? null,
username ?? null,
appAttestation ?? null
appAttestation ?? false
)) as AppCredential;

return { data };
Expand Down
7 changes: 1 addition & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,11 @@ export interface VerifyResponse {
failureReason?: string;
}

export interface AppAttestation {
token: string;
keyId?: string;
}

export interface AddCredentialInput {
token?: string;
requireUserAuthentication?: boolean;
keychainAccess?: KeychainAccess;
appAttestation?: AppAttestation;
appAttestation?: boolean;
}

export interface AppChallenge {
Expand Down
Loading