Skip to content

Add keychainAccess param for iOS only #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2025
Merged
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
1 change: 1 addition & 0 deletions ios/AuthsignalPushModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ @interface RCT_EXTERN_MODULE(AuthsignalPushModule, NSObject)
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(addCredential:(NSString)token
withKeychainAccess:(NSString)keychainAccess
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

Expand Down
26 changes: 25 additions & 1 deletion ios/AuthsignalPushModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class AuthsignalPushModule: NSObject {

@objc func addCredential(
_ token: NSString?,
withKeychainAccess keychainAccess: NSString,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock
) -> Void {
Expand All @@ -60,7 +61,8 @@ class AuthsignalPushModule: NSObject {
}

let tokenStr = token as String?
let keychainAccess: KeychainAccess = .whenUnlockedThisDeviceOnly

let keychainAccess = getKeychainAccess(value: keychainAccess as String?)

Task.init {
let response = await authsignal.addCredential(token: tokenStr, keychainAccess: keychainAccess)
Expand Down Expand Up @@ -154,4 +156,26 @@ class AuthsignalPushModule: NSObject {
}
}
}

func getKeychainAccess(value: String?) -> KeychainAccess {
switch value {
case "afterFirstUnlock":
return .afterFirstUnlock

case "afterFirstUnlockThisDeviceOnly":
return .afterFirstUnlockThisDeviceOnly

case "whenUnlocked":
return .whenUnlocked

case "whenUnlockedThisDeviceOnly":
return .whenUnlockedThisDeviceOnly

case "afterFirstUnlock":
return .whenPasscodeSetThisDeviceOnly

default:
return .whenUnlockedThisDeviceOnly
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-authsignal",
"version": "1.3.1",
"version": "1.3.2",
"description": "The official Authsignal React Native library.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
16 changes: 11 additions & 5 deletions src/push.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NativeModules } from 'react-native';
import { NativeModules, Platform } from 'react-native';
import { handleErrorCodes, LINKING_ERROR } from './error';
import type {
AuthsignalResponse,
KeychainAccess,
PushChallenge,
PushCredential,
} from './types';
Expand All @@ -27,6 +28,7 @@ const AuthsignalPushModule = NativeModules.AuthsignalPushModule

interface AddCredentialInput {
token?: string;
keychainAccess?: KeychainAccess;
}

interface UpdateChallengeInput {
Expand Down Expand Up @@ -62,13 +64,17 @@ export class AuthsignalPush {
}
}

async addCredential({ token }: AddCredentialInput = {}): Promise<
AuthsignalResponse<boolean>
> {
async addCredential({
token,
keychainAccess,
}: AddCredentialInput = {}): Promise<AuthsignalResponse<boolean>> {
await this.ensureModuleIsInitialized();

try {
const data = await AuthsignalPushModule.addCredential(token);
const data =
Platform.OS === 'ios'
? await AuthsignalPushModule.addCredential(token, keychainAccess)
: await AuthsignalPushModule.addCredential(token);

return { data };
} catch (ex) {
Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ export interface VerifyDeviceResponse {
userAuthenticatorId: string;
username?: string;
}

export enum KeychainAccess {
afterFirstUnlock = 'afterFirstUnlock',
afterFirstUnlockThisDeviceOnly = 'afterFirstUnlockThisDeviceOnly',
whenUnlocked = 'whenUnlocked',
whenUnlockedThisDeviceOnly = 'whenUnlockedThisDeviceOnly',
whenPasscodeSetThisDeviceOnly = 'whenPasscodeSetThisDeviceOnly',
}
Loading