Skip to content
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
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ dependencies {

implementation "androidx.browser:browser:1.2.0"

implementation("com.authsignal:authsignal-android:3.0.3")
implementation("com.authsignal:authsignal-android:3.1.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
}

@ReactMethod
fun getCredential(promise: Promise) {
fun getCredential(username: String?, promise: Promise) {
launch(promise) {
val response = it.getCredential()
val response = it.getCredential(username = username)

if (response.error != null) {
val errorCode = response.errorCode ?: defaultError
Expand All @@ -64,10 +64,18 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
@ReactMethod
fun addCredential(
token: String?,
username: String?,
promise: Promise
) {
launch(promise) {
val response = it.addCredential(token, null)
val response = it.addCredential(
token = token,
deviceName = null,
userAuthenticationRequired = false,
timeout = 0,
authorizationType = 0,
username = username,
)

if (response.error != null) {
val errorCode = response.errorCode ?: defaultError
Expand All @@ -86,9 +94,9 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
}

@ReactMethod
fun removeCredential(promise: Promise) {
fun removeCredential(username: String?, promise: Promise) {
launch(promise) {
val response = it.removeCredential()
val response = it.removeCredential(username = username)

if (response.error != null) {
val errorCode = response.errorCode ?: defaultError
Expand All @@ -103,10 +111,11 @@ class AuthsignalInAppModule(private val reactContext: ReactApplicationContext) :
@ReactMethod
fun verify(
action: String?,
username: String?,
promise: Promise
) {
launch(promise) {
val response = it.verify(action)
val response = it.verify(action = action, username = username)

if (response.error != null) {
val errorCode = response.errorCode ?: defaultError
Expand Down
8 changes: 6 additions & 2 deletions ios/AuthsignalInAppModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ @interface RCT_EXTERN_MODULE(AuthsignalInAppModule, NSObject)
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(getCredential:(RCTPromiseResolveBlock)resolve
RCT_EXTERN_METHOD(getCredential:(NSString)username
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(addCredential:(NSString)token
withRequireUserAuthentication:(BOOL)requireUserAuthentication
withKeychainAccess:(NSString)keychainAccess
withUsername:(NSString)username
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(removeCredential:(RCTPromiseResolveBlock)resolve
RCT_EXTERN_METHOD(removeCredential:(NSString)username
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(verify:(NSString)action
withUsername:(NSString)username
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

Expand Down
23 changes: 17 additions & 6 deletions ios/AuthsignalInAppModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ class AuthsignalInAppModule: NSObject {
}

@objc func getCredential(
_ resolve: @escaping RCTPromiseResolveBlock,
_ username: NSString?,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock
) -> Void {
guard let authsignal = authsignal else {
resolve(nil)
return
}

let usernameStr = username as String?

Task.init {
let response = await authsignal.getCredential()
let response = await authsignal.getCredential(username: usernameStr)

if let error = response.error {
reject(response.errorCode ?? "unexpected_error", error, nil)
Expand All @@ -54,6 +57,7 @@ class AuthsignalInAppModule: NSObject {
_ token: NSString?,
withRequireUserAuthentication requireUserAuthentication: Bool,
withKeychainAccess keychainAccess: NSString,
withUsername username: NSString?,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock
) -> Void {
Expand All @@ -65,12 +69,14 @@ class AuthsignalInAppModule: NSObject {
let tokenStr = token as String?
let userPresenceRequired = requireUserAuthentication as Bool
let keychainAccess = getKeychainAccess(value: keychainAccess as String?)
let usernameStr = username as String?

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

if let error = response.error {
Expand All @@ -91,16 +97,19 @@ class AuthsignalInAppModule: NSObject {
}

@objc func removeCredential(
_ resolve: @escaping RCTPromiseResolveBlock,
_ username: NSString?,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock
) -> Void {
guard let authsignal = authsignal else {
resolve(nil)
return
}

let usernameStr = username as String?

Task.init {
let response = await authsignal.removeCredential()
let response = await authsignal.removeCredential(username: usernameStr)

if let error = response.error {
reject(response.errorCode ?? "unexpected_error", error, nil)
Expand All @@ -112,6 +121,7 @@ class AuthsignalInAppModule: NSObject {

@objc func verify(
_ action: NSString?,
withUsername username: NSString?,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock
) -> Void {
Expand All @@ -121,9 +131,10 @@ class AuthsignalInAppModule: NSObject {
}

let actionStr = action as String?
let usernameStr = username as String?

Task.init {
let response = await authsignal.verify(action: actionStr)
let response = await authsignal.verify(action: actionStr, username: usernameStr)

if let error = response.error {
reject(response.errorCode ?? "unexpected_error", error, nil)
Expand Down
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": "2.0.3",
"version": "2.1.0",
"description": "The official Authsignal React Native library.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
2 changes: 1 addition & 1 deletion react-native-authsignal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Pod::Spec.new do |s|
s.source_files = "ios/**/*.{h,m,mm,swift}"

s.dependency "React-Core"
s.dependency 'Authsignal', '2.0.3'
s.dependency 'Authsignal', '2.1.0'

# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
Expand Down
28 changes: 18 additions & 10 deletions src/inapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import type {
AppCredential,
InAppVerifyRequest,
InAppVerifyResponse,
AddCredentialInput,
InAppAddCredentialInput,
InAppGetCredentialInput,
InAppRemoveCredentialInput,
} from './types';

interface ConstructorArgs {
Expand Down Expand Up @@ -38,13 +40,15 @@ export class AuthsignalInApp {
this.enableLogging = enableLogging;
}

async getCredential(): Promise<
async getCredential({
username,
}: InAppGetCredentialInput): Promise<
AuthsignalResponse<AppCredential | undefined>
> {
await this.ensureModuleIsInitialized();

try {
const data = await AuthsignalInAppModule.getCredential();
const data = await AuthsignalInAppModule.getCredential(username);

return { data };
} catch (ex) {
Expand All @@ -60,7 +64,8 @@ export class AuthsignalInApp {
token,
requireUserAuthentication = false,
keychainAccess,
}: AddCredentialInput = {}): Promise<AuthsignalResponse<AppCredential>> {
username,
}: InAppAddCredentialInput = {}): Promise<AuthsignalResponse<AppCredential>> {
await this.ensureModuleIsInitialized();

try {
Expand All @@ -69,9 +74,10 @@ export class AuthsignalInApp {
? await AuthsignalInAppModule.addCredential(
token,
requireUserAuthentication,
keychainAccess
keychainAccess,
username
)
: await AuthsignalInAppModule.addCredential(token);
: await AuthsignalInAppModule.addCredential(token, username);

return { data };
} catch (ex) {
Expand All @@ -83,11 +89,13 @@ export class AuthsignalInApp {
}
}

async removeCredential(): Promise<AuthsignalResponse<boolean>> {
async removeCredential({
username,
}: InAppRemoveCredentialInput): Promise<AuthsignalResponse<boolean>> {
await this.ensureModuleIsInitialized();

try {
const data = await AuthsignalInAppModule.removeCredential();
const data = await AuthsignalInAppModule.removeCredential(username);
return { data };
} catch (ex) {
if (this.enableLogging) {
Expand All @@ -98,13 +106,13 @@ export class AuthsignalInApp {
}
}

async verify({ action }: InAppVerifyRequest = {}): Promise<
async verify({ action, username }: InAppVerifyRequest = {}): Promise<
AuthsignalResponse<InAppVerifyResponse>
> {
await this.ensureModuleIsInitialized();

try {
const data = await AuthsignalInAppModule.verify(action);
const data = await AuthsignalInAppModule.verify(action, username);

return { data };
} catch (ex) {
Expand Down
13 changes: 13 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,21 @@ export interface UpdateChallengeInput {
verificationCode?: string | null;
}

export interface InAppGetCredentialInput {
username?: string;
}

export interface InAppAddCredentialInput extends AddCredentialInput {
username?: string;
}

export interface InAppRemoveCredentialInput {
username?: string;
}

export interface InAppVerifyRequest {
action?: string;
username?: string;
}

export interface InAppVerifyResponse {
Expand Down
Loading