From d8ff1287764a25fd5cfe6b8a602fef258805bf93 Mon Sep 17 00:00:00 2001 From: Chris McLeod Date: Sun, 9 Oct 2022 16:15:22 -0500 Subject: [PATCH 01/22] Update auth0-provider.js Fix issue passing Other configuration options to authorize call --- ios/A0Auth0.m | 4 ++-- ios/CredentialsManagerBridge.swift | 37 ++++++++++++++++++++++++++++-- src/credentials-manager/index.js | 4 +++- src/hooks/auth0-provider.js | 2 +- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/ios/A0Auth0.m b/ios/A0Auth0.m index 1842f6ad..93c4cb05 100644 --- a/ios/A0Auth0.m +++ b/ios/A0Auth0.m @@ -68,8 +68,8 @@ - (dispatch_queue_t)methodQueue [self.credentialsManagerBridge clearCredentialsWithResolve:resolve reject:reject]; } -RCT_EXPORT_METHOD(enableLocalAuthentication:(NSString *)title cancelTitle:(NSString *)cancelTitle fallbackTitle:(NSString *)fallbackTitle) { - [self.credentialsManagerBridge enableLocalAuthenticationWithTitle:title cancelTitle:title fallbackTitle:title]; +RCT_EXPORT_METHOD(enableLocalAuthentication:(NSString *)title cancelTitle:(NSString *)cancelTitle fallbackTitle:(NSString *)fallbackTitle evaluationPolicy:(nonnull NSNumber *)evaluationPolicy) { + [self.credentialsManagerBridge enableLocalAuthenticationWithTitle:title cancelTitle:cancelTitle fallbackTitle:fallbackTitle evaluationPolicy: evaluationPolicy]; } RCT_EXPORT_METHOD(showUrl:(NSString *)urlString diff --git a/ios/CredentialsManagerBridge.swift b/ios/CredentialsManagerBridge.swift index c8a494ad..c1a01269 100644 --- a/ios/CredentialsManagerBridge.swift +++ b/ios/CredentialsManagerBridge.swift @@ -82,9 +82,42 @@ public class CredentialsManagerBridge: NSObject { resolve(credentialsManager.clear()) } - @objc public func enableLocalAuthentication(title: String?, cancelTitle: String?, fallbackTitle: String?) { + @objc public func enableLocalAuthentication(title: String?, cancelTitle: String?, fallbackTitle: String?, evaluationPolicy: NSNumber?) { let titleValue = title ?? "Please authenticate to continue" - self.credentialsManager.enableBiometrics(withTitle: titleValue, cancelTitle: cancelTitle, fallbackTitle: fallbackTitle) + let policyValue = self.convertPolicyInt(policyInt: evaluationPolicy); + self.credentialsManager.enableBiometrics(withTitle: titleValue, cancelTitle: cancelTitle, fallbackTitle: fallbackTitle, evaluationPolicy: policyValue as LAPolicy) + } + + func convertPolicyInt(policyInt: NSNumber?) -> LAPolicy { + if(policyInt == nil || policyInt == 1) { + return LAPolicy.deviceOwnerAuthenticationWithBiometrics; + } + + if(policyInt == 2) { + return LAPolicy.deviceOwnerAuthentication; + } + + #if os(macOS) + if(policyInt == 3) { + if #available(macOS 10.15, macCatalyst 13.0, *) { + return LAPolicy.deviceOwnerAuthenticationWithWatch; + } + } + + if(policyInt == 4) { + return LAPolicy.deviceOwnerAuthenticationWithBiometricsOrWatch; + } + #endif + + #if os(watchOS) + if(policyInt == 5) { + if #available(watchOS 9.0, *) { + return LAPolicy.deviceOwnerAuthenticationWithWristDetection; + } + } + #endif + + return LAPolicy.deviceOwnerAuthenticationWithBiometrics; } } diff --git a/src/credentials-manager/index.js b/src/credentials-manager/index.js index 69399122..3fc3bbce 100644 --- a/src/credentials-manager/index.js +++ b/src/credentials-manager/index.js @@ -90,6 +90,7 @@ class CredentialsManager { description, cancelTitle, fallbackTitle, + policy = 1, ) { try { await this._ensureCredentialManagerIsInitialized(); @@ -98,9 +99,10 @@ class CredentialsManager { title, cancelTitle, fallbackTitle, + policy ); } else { - await this.Auth0Module.enableLocalAuthentication(title, description); + await this.Auth0Module.enableLocalAuthentication(title, description, undefined, policy); } } catch (e) { const json = { diff --git a/src/hooks/auth0-provider.js b/src/hooks/auth0-provider.js index 54f44294..ec9e3595 100644 --- a/src/hooks/auth0-provider.js +++ b/src/hooks/auth0-provider.js @@ -72,7 +72,7 @@ const Auth0Provider = ({domain, clientId, children}) => { opts.scope = Array.from(scopeSet).join(' '); - const credentials = await client.webAuth.authorize(opts); + const credentials = await client.webAuth.authorize(opts, options[1]); const user = getIdTokenProfileClaims(credentials.idToken); await client.credentialsManager.saveCredentials(credentials); From 3473808f661f63d7a872751eaef5db25ce492260 Mon Sep 17 00:00:00 2001 From: Chris McLeod Date: Sun, 9 Oct 2022 16:15:22 -0500 Subject: [PATCH 02/22] Update auth0-provider.js Fix issue passing Other configuration options to authorize call --- ios/A0Auth0.m | 4 +-- ios/CredentialsManagerBridge.swift | 37 +++++++++++++++++++++++++-- src/credentials-manager/index.js | 4 ++- src/hooks/__tests__/use-auth0.spec.js | 4 +++ src/hooks/auth0-provider.js | 2 +- 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/ios/A0Auth0.m b/ios/A0Auth0.m index 1842f6ad..93c4cb05 100644 --- a/ios/A0Auth0.m +++ b/ios/A0Auth0.m @@ -68,8 +68,8 @@ - (dispatch_queue_t)methodQueue [self.credentialsManagerBridge clearCredentialsWithResolve:resolve reject:reject]; } -RCT_EXPORT_METHOD(enableLocalAuthentication:(NSString *)title cancelTitle:(NSString *)cancelTitle fallbackTitle:(NSString *)fallbackTitle) { - [self.credentialsManagerBridge enableLocalAuthenticationWithTitle:title cancelTitle:title fallbackTitle:title]; +RCT_EXPORT_METHOD(enableLocalAuthentication:(NSString *)title cancelTitle:(NSString *)cancelTitle fallbackTitle:(NSString *)fallbackTitle evaluationPolicy:(nonnull NSNumber *)evaluationPolicy) { + [self.credentialsManagerBridge enableLocalAuthenticationWithTitle:title cancelTitle:cancelTitle fallbackTitle:fallbackTitle evaluationPolicy: evaluationPolicy]; } RCT_EXPORT_METHOD(showUrl:(NSString *)urlString diff --git a/ios/CredentialsManagerBridge.swift b/ios/CredentialsManagerBridge.swift index c8a494ad..c1a01269 100644 --- a/ios/CredentialsManagerBridge.swift +++ b/ios/CredentialsManagerBridge.swift @@ -82,9 +82,42 @@ public class CredentialsManagerBridge: NSObject { resolve(credentialsManager.clear()) } - @objc public func enableLocalAuthentication(title: String?, cancelTitle: String?, fallbackTitle: String?) { + @objc public func enableLocalAuthentication(title: String?, cancelTitle: String?, fallbackTitle: String?, evaluationPolicy: NSNumber?) { let titleValue = title ?? "Please authenticate to continue" - self.credentialsManager.enableBiometrics(withTitle: titleValue, cancelTitle: cancelTitle, fallbackTitle: fallbackTitle) + let policyValue = self.convertPolicyInt(policyInt: evaluationPolicy); + self.credentialsManager.enableBiometrics(withTitle: titleValue, cancelTitle: cancelTitle, fallbackTitle: fallbackTitle, evaluationPolicy: policyValue as LAPolicy) + } + + func convertPolicyInt(policyInt: NSNumber?) -> LAPolicy { + if(policyInt == nil || policyInt == 1) { + return LAPolicy.deviceOwnerAuthenticationWithBiometrics; + } + + if(policyInt == 2) { + return LAPolicy.deviceOwnerAuthentication; + } + + #if os(macOS) + if(policyInt == 3) { + if #available(macOS 10.15, macCatalyst 13.0, *) { + return LAPolicy.deviceOwnerAuthenticationWithWatch; + } + } + + if(policyInt == 4) { + return LAPolicy.deviceOwnerAuthenticationWithBiometricsOrWatch; + } + #endif + + #if os(watchOS) + if(policyInt == 5) { + if #available(watchOS 9.0, *) { + return LAPolicy.deviceOwnerAuthenticationWithWristDetection; + } + } + #endif + + return LAPolicy.deviceOwnerAuthenticationWithBiometrics; } } diff --git a/src/credentials-manager/index.js b/src/credentials-manager/index.js index 69399122..3fc3bbce 100644 --- a/src/credentials-manager/index.js +++ b/src/credentials-manager/index.js @@ -90,6 +90,7 @@ class CredentialsManager { description, cancelTitle, fallbackTitle, + policy = 1, ) { try { await this._ensureCredentialManagerIsInitialized(); @@ -98,9 +99,10 @@ class CredentialsManager { title, cancelTitle, fallbackTitle, + policy ); } else { - await this.Auth0Module.enableLocalAuthentication(title, description); + await this.Auth0Module.enableLocalAuthentication(title, description, undefined, policy); } } catch (e) { const json = { diff --git a/src/hooks/__tests__/use-auth0.spec.js b/src/hooks/__tests__/use-auth0.spec.js index f5ed387e..577b3961 100644 --- a/src/hooks/__tests__/use-auth0.spec.js +++ b/src/hooks/__tests__/use-auth0.spec.js @@ -131,6 +131,8 @@ describe('The useAuth0 hook', () => { scope: 'custom-scope', audience: 'http://my-api', customParam: '1234', + }, { + ephemeralSession: true }); await waitForNextUpdate(); @@ -139,6 +141,8 @@ describe('The useAuth0 hook', () => { scope: 'custom-scope openid profile email', audience: 'http://my-api', customParam: '1234', + }, { + ephemeralSession: true }); }); diff --git a/src/hooks/auth0-provider.js b/src/hooks/auth0-provider.js index 54f44294..ec9e3595 100644 --- a/src/hooks/auth0-provider.js +++ b/src/hooks/auth0-provider.js @@ -72,7 +72,7 @@ const Auth0Provider = ({domain, clientId, children}) => { opts.scope = Array.from(scopeSet).join(' '); - const credentials = await client.webAuth.authorize(opts); + const credentials = await client.webAuth.authorize(opts, options[1]); const user = getIdTokenProfileClaims(credentials.idToken); await client.credentialsManager.saveCredentials(credentials); From d393aba4cfba438442dfc917bbed50fe0e87083a Mon Sep 17 00:00:00 2001 From: Chris McLeod Date: Sat, 15 Oct 2022 13:24:49 -0500 Subject: [PATCH 03/22] no message --- src/hooks/__tests__/use-auth0.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/__tests__/use-auth0.spec.js b/src/hooks/__tests__/use-auth0.spec.js index f1cdc2cf..3b45c50c 100644 --- a/src/hooks/__tests__/use-auth0.spec.js +++ b/src/hooks/__tests__/use-auth0.spec.js @@ -5,7 +5,7 @@ import * as React from 'react'; import {renderHook} from '@testing-library/react-hooks'; import Auth0Provider from '../auth0-provider'; import useAuth0 from '../use-auth0'; -import { LAPolicy } from '../../..'; +import LAPolicy from '../../credentials-manager/la-policies'; function makeJwt(claims) { const header = {alg: 'RS256', typ: 'JWT'}; From e9b75f1342f67c38e17502937d77f86fa6538776 Mon Sep 17 00:00:00 2001 From: Chris McLeod Date: Sat, 15 Oct 2022 13:26:18 -0500 Subject: [PATCH 04/22] no message --- src/credentials-manager/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/credentials-manager/index.js b/src/credentials-manager/index.js index efdf2b34..62ef88e4 100644 --- a/src/credentials-manager/index.js +++ b/src/credentials-manager/index.js @@ -83,7 +83,7 @@ class CredentialsManager { * @param {String} description Android Only - optional - the text to use as description in the authentication screen. On some Android versions it might not be shown. Passing null will result in using the OS's default value. * @param {String} cancelTitle iOS Only - optional - the cancel message to display on the local authentication prompt. * @param {String} fallbackTitle iOS Only - optional - the fallback message to display on the local authentication prompt after a failed match. - * @param {String} accessPolicy iOS Only - optional - the access policy to use when accessing the credentials + * @param {String} evaluationPolicy iOS Only - optional - the evaluation policy to use when accessing the credentials * @returns {Promise} */ async requireLocalAuthentication( @@ -91,7 +91,7 @@ class CredentialsManager { description, cancelTitle, fallbackTitle, - accessPolicy = 1, + evaluationPolicy = 1, ) { try { await this._ensureCredentialManagerIsInitialized(); @@ -100,7 +100,7 @@ class CredentialsManager { title, cancelTitle, fallbackTitle, - accessPolicy + evaluationPolicy ); } else { await this.Auth0Module.enableLocalAuthentication(title, description); From 96662dc32f2a3388951aa58741ee91089939563b Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Wed, 25 Jan 2023 13:48:27 +0530 Subject: [PATCH 05/22] Code review changes and rename LAPolicy to Security Level --- index.js | 2 +- ios/A0Auth0.m | 2 +- ios/CredentialsManagerBridge.swift | 12 ++++-------- src/credentials-manager/index.js | 7 ++++--- src/credentials-manager/la-policies.js | 14 ++++++-------- src/hooks/__tests__/use-auth0.spec.js | 6 +++--- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/index.js b/index.js index f7f3be9a..2152b8e5 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ export {TimeoutError} from './src/utils/fetchWithTimeout'; export {default as useAuth0} from './src/hooks/use-auth0'; export {default as Auth0Provider} from './src/hooks/auth0-provider'; -export {default as LAPolicy} from './src/credentials-manager/la-policies'; +export {SecurityLevel} from './src/credentials-manager/la-policies'; import Auth0 from './src/auth0'; export default Auth0; diff --git a/ios/A0Auth0.m b/ios/A0Auth0.m index 93c4cb05..092f4b8f 100644 --- a/ios/A0Auth0.m +++ b/ios/A0Auth0.m @@ -68,7 +68,7 @@ - (dispatch_queue_t)methodQueue [self.credentialsManagerBridge clearCredentialsWithResolve:resolve reject:reject]; } -RCT_EXPORT_METHOD(enableLocalAuthentication:(NSString *)title cancelTitle:(NSString *)cancelTitle fallbackTitle:(NSString *)fallbackTitle evaluationPolicy:(nonnull NSNumber *)evaluationPolicy) { +RCT_EXPORT_METHOD(enableLocalAuthentication:(NSString *)title cancelTitle:(NSString *)cancelTitle fallbackTitle:(NSString *)fallbackTitle evaluationPolicy:(NSNumber *)evaluationPolicy) { [self.credentialsManagerBridge enableLocalAuthenticationWithTitle:title cancelTitle:cancelTitle fallbackTitle:fallbackTitle evaluationPolicy: evaluationPolicy]; } diff --git a/ios/CredentialsManagerBridge.swift b/ios/CredentialsManagerBridge.swift index c1a01269..bbb2df20 100644 --- a/ios/CredentialsManagerBridge.swift +++ b/ios/CredentialsManagerBridge.swift @@ -82,17 +82,13 @@ public class CredentialsManagerBridge: NSObject { resolve(credentialsManager.clear()) } - @objc public func enableLocalAuthentication(title: String?, cancelTitle: String?, fallbackTitle: String?, evaluationPolicy: NSNumber?) { + @objc public func enableLocalAuthentication(title: String?, cancelTitle: String?, fallbackTitle: String?, evaluationPolicy: Int?) { let titleValue = title ?? "Please authenticate to continue" - let policyValue = self.convertPolicyInt(policyInt: evaluationPolicy); - self.credentialsManager.enableBiometrics(withTitle: titleValue, cancelTitle: cancelTitle, fallbackTitle: fallbackTitle, evaluationPolicy: policyValue as LAPolicy) + let policyValue = self.convert(policyInt: evaluationPolicy); + self.credentialsManager.enableBiometrics(withTitle: titleValue, cancelTitle: cancelTitle, fallbackTitle: fallbackTitle, evaluationPolicy: policyValue) } - func convertPolicyInt(policyInt: NSNumber?) -> LAPolicy { - if(policyInt == nil || policyInt == 1) { - return LAPolicy.deviceOwnerAuthenticationWithBiometrics; - } - + func convert(policyInt: NSNumber?) -> LAPolicy { if(policyInt == 2) { return LAPolicy.deviceOwnerAuthentication; } diff --git a/src/credentials-manager/index.js b/src/credentials-manager/index.js index 62ef88e4..4878d5b8 100644 --- a/src/credentials-manager/index.js +++ b/src/credentials-manager/index.js @@ -1,5 +1,6 @@ import {Platform, NativeModules} from 'react-native'; import CredentialsManagerError from './credentialsManagerError'; +import SecurityLevel from './la-policies'; class CredentialsManager { /** @@ -83,7 +84,7 @@ class CredentialsManager { * @param {String} description Android Only - optional - the text to use as description in the authentication screen. On some Android versions it might not be shown. Passing null will result in using the OS's default value. * @param {String} cancelTitle iOS Only - optional - the cancel message to display on the local authentication prompt. * @param {String} fallbackTitle iOS Only - optional - the fallback message to display on the local authentication prompt after a failed match. - * @param {String} evaluationPolicy iOS Only - optional - the evaluation policy to use when accessing the credentials + * @param {String} securityLevel iOS Only - optional - the evaluation policy to use when accessing the credentials * @returns {Promise} */ async requireLocalAuthentication( @@ -91,7 +92,7 @@ class CredentialsManager { description, cancelTitle, fallbackTitle, - evaluationPolicy = 1, + securityLevel = SecurityLevel.deviceOwner, ) { try { await this._ensureCredentialManagerIsInitialized(); @@ -100,7 +101,7 @@ class CredentialsManager { title, cancelTitle, fallbackTitle, - evaluationPolicy + securityLevel ); } else { await this.Auth0Module.enableLocalAuthentication(title, description); diff --git a/src/credentials-manager/la-policies.js b/src/credentials-manager/la-policies.js index 81cf5201..d62d8760 100644 --- a/src/credentials-manager/la-policies.js +++ b/src/credentials-manager/la-policies.js @@ -1,8 +1,6 @@ -export default { - deviceOwnerAuthenticationWithBiometrics: 1, - deviceOwnerAuthentication: 2, - deviceOwnerAuthenticationWithWatch: 3, - deviceOwnerAuthenticationWithBiometricsOrWatch: 4, - deviceOwnerAuthenticationWithWristDetection: 5, - deviceOwnerAuthenticationWithBiometrics: 6 -} \ No newline at end of file +const SecurityLevel = { + deviceOwnerWithBiometrics: 1, + deviceOwner: 2, +} + +export default SecurityLevel; \ No newline at end of file diff --git a/src/hooks/__tests__/use-auth0.spec.js b/src/hooks/__tests__/use-auth0.spec.js index f1a31ddc..88180b54 100644 --- a/src/hooks/__tests__/use-auth0.spec.js +++ b/src/hooks/__tests__/use-auth0.spec.js @@ -5,7 +5,7 @@ import * as React from 'react'; import {renderHook} from '@testing-library/react-hooks'; import Auth0Provider from '../auth0-provider'; import useAuth0 from '../use-auth0'; -import LAPolicy from '../../credentials-manager/la-policies'; +import SecurityLevel from '../../credentials-manager/la-policies'; function makeJwt(claims) { const header = {alg: 'RS256', typ: 'JWT'}; @@ -373,12 +373,12 @@ describe('The useAuth0 hook', () => { 'description', 'cancel', 'fallback', - LAPolicy.deviceOwnerAuthentication + SecurityLevel.deviceOwner ); expect( mockAuth0.credentialsManager.requireLocalAuthentication, - ).toHaveBeenCalledWith('title', 'description', 'cancel', 'fallback', LAPolicy.deviceOwnerAuthentication); + ).toHaveBeenCalledWith('title', 'description', 'cancel', 'fallback', SecurityLevel.deviceOwner); }); it('dispatches an error when requireLocalAuthentication fails', async () => { From c60512f0001941991e49d3740c19a6fc294ce438 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Wed, 25 Jan 2023 13:54:07 +0530 Subject: [PATCH 06/22] Removed unsupported policies from conversion --- ios/CredentialsManagerBridge.swift | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/ios/CredentialsManagerBridge.swift b/ios/CredentialsManagerBridge.swift index bbb2df20..401fcc5b 100644 --- a/ios/CredentialsManagerBridge.swift +++ b/ios/CredentialsManagerBridge.swift @@ -91,28 +91,7 @@ public class CredentialsManagerBridge: NSObject { func convert(policyInt: NSNumber?) -> LAPolicy { if(policyInt == 2) { return LAPolicy.deviceOwnerAuthentication; - } - - #if os(macOS) - if(policyInt == 3) { - if #available(macOS 10.15, macCatalyst 13.0, *) { - return LAPolicy.deviceOwnerAuthenticationWithWatch; - } - } - - if(policyInt == 4) { - return LAPolicy.deviceOwnerAuthenticationWithBiometricsOrWatch; - } - #endif - - #if os(watchOS) - if(policyInt == 5) { - if #available(watchOS 9.0, *) { - return LAPolicy.deviceOwnerAuthenticationWithWristDetection; - } - } - #endif - + } return LAPolicy.deviceOwnerAuthenticationWithBiometrics; } } From aa4e5a2becd33d83c8d91c0cfa01c5efc8f48863 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Wed, 25 Jan 2023 15:21:11 +0530 Subject: [PATCH 07/22] Fixed compilation error --- ios/CredentialsManagerBridge.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ios/CredentialsManagerBridge.swift b/ios/CredentialsManagerBridge.swift index d22a5c87..0f10384f 100644 --- a/ios/CredentialsManagerBridge.swift +++ b/ios/CredentialsManagerBridge.swift @@ -7,6 +7,7 @@ import Auth0 import Foundation +import LocalAuthentication @objc public class CredentialsManagerBridge: NSObject { @@ -82,13 +83,13 @@ public class CredentialsManagerBridge: NSObject { resolve(credentialsManager.clear()) } - @objc public func enableLocalAuthentication(title: String?, cancelTitle: String?, fallbackTitle: String?, evaluationPolicy: Int?) { + @objc public func enableLocalAuthentication(title: String?, cancelTitle: String?, fallbackTitle: String?, evaluationPolicy: Int) { let titleValue = title ?? "Please authenticate to continue" let policyValue = self.convert(policyInt: evaluationPolicy); self.credentialsManager.enableBiometrics(withTitle: titleValue, cancelTitle: cancelTitle, fallbackTitle: fallbackTitle, evaluationPolicy: policyValue) } - func convert(policyInt: NSNumber?) -> LAPolicy { + func convert(policyInt: Int) -> LAPolicy { if(policyInt == 2) { return LAPolicy.deviceOwnerAuthentication; } From ff2d36668dd8e19f1ff7111ba8db982cba51149c Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Wed, 25 Jan 2023 20:46:24 +0530 Subject: [PATCH 08/22] Update ios/CredentialsManagerBridge.swift Co-authored-by: Rita Zerrizuela --- ios/CredentialsManagerBridge.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/CredentialsManagerBridge.swift b/ios/CredentialsManagerBridge.swift index 0f10384f..5463901f 100644 --- a/ios/CredentialsManagerBridge.swift +++ b/ios/CredentialsManagerBridge.swift @@ -90,7 +90,7 @@ public class CredentialsManagerBridge: NSObject { } func convert(policyInt: Int) -> LAPolicy { - if(policyInt == 2) { + if (policyInt == 2) { return LAPolicy.deviceOwnerAuthentication; } return LAPolicy.deviceOwnerAuthenticationWithBiometrics; From 012238560519f9d613fcaf28349ec4ae21ebe2b0 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Thu, 26 Jan 2023 11:34:04 +0530 Subject: [PATCH 09/22] Update ios/CredentialsManagerBridge.swift Co-authored-by: Rita Zerrizuela --- ios/CredentialsManagerBridge.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/CredentialsManagerBridge.swift b/ios/CredentialsManagerBridge.swift index 5463901f..eb36f333 100644 --- a/ios/CredentialsManagerBridge.swift +++ b/ios/CredentialsManagerBridge.swift @@ -85,7 +85,7 @@ public class CredentialsManagerBridge: NSObject { @objc public func enableLocalAuthentication(title: String?, cancelTitle: String?, fallbackTitle: String?, evaluationPolicy: Int) { let titleValue = title ?? "Please authenticate to continue" - let policyValue = self.convert(policyInt: evaluationPolicy); + let policyValue = self.convert(policyInt: evaluationPolicy) self.credentialsManager.enableBiometrics(withTitle: titleValue, cancelTitle: cancelTitle, fallbackTitle: fallbackTitle, evaluationPolicy: policyValue) } From d475bc04aae34ac775c8d0e05531ac20b4c00f96 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Thu, 26 Jan 2023 11:34:42 +0530 Subject: [PATCH 10/22] Update ios/CredentialsManagerBridge.swift Co-authored-by: Rita Zerrizuela --- ios/CredentialsManagerBridge.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/CredentialsManagerBridge.swift b/ios/CredentialsManagerBridge.swift index eb36f333..ecd0e2d2 100644 --- a/ios/CredentialsManagerBridge.swift +++ b/ios/CredentialsManagerBridge.swift @@ -91,7 +91,7 @@ public class CredentialsManagerBridge: NSObject { func convert(policyInt: Int) -> LAPolicy { if (policyInt == 2) { - return LAPolicy.deviceOwnerAuthentication; + return LAPolicy.deviceOwnerAuthentication } return LAPolicy.deviceOwnerAuthenticationWithBiometrics; } From c2c61e5f5a90fa724dd4d5cb18d3b8786dd80578 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Thu, 26 Jan 2023 11:34:50 +0530 Subject: [PATCH 11/22] Update ios/CredentialsManagerBridge.swift Co-authored-by: Rita Zerrizuela --- ios/CredentialsManagerBridge.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/CredentialsManagerBridge.swift b/ios/CredentialsManagerBridge.swift index ecd0e2d2..bf8aa20d 100644 --- a/ios/CredentialsManagerBridge.swift +++ b/ios/CredentialsManagerBridge.swift @@ -93,7 +93,7 @@ public class CredentialsManagerBridge: NSObject { if (policyInt == 2) { return LAPolicy.deviceOwnerAuthentication } - return LAPolicy.deviceOwnerAuthenticationWithBiometrics; + return LAPolicy.deviceOwnerAuthenticationWithBiometrics } } From 06b100bb434de34e97601a3cbf6960f0356fb053 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Thu, 26 Jan 2023 12:34:22 +0530 Subject: [PATCH 12/22] Refactor name to LAPolicy --- src/credentials-manager/index.js | 4 ++-- src/credentials-manager/la-policies.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/credentials-manager/index.js b/src/credentials-manager/index.js index 4878d5b8..900f47f7 100644 --- a/src/credentials-manager/index.js +++ b/src/credentials-manager/index.js @@ -1,6 +1,6 @@ import {Platform, NativeModules} from 'react-native'; import CredentialsManagerError from './credentialsManagerError'; -import SecurityLevel from './la-policies'; +import LAPolicy from './la-policies'; class CredentialsManager { /** @@ -92,7 +92,7 @@ class CredentialsManager { description, cancelTitle, fallbackTitle, - securityLevel = SecurityLevel.deviceOwner, + securityLevel = LAPolicy.deviceOwner, ) { try { await this._ensureCredentialManagerIsInitialized(); diff --git a/src/credentials-manager/la-policies.js b/src/credentials-manager/la-policies.js index d62d8760..3f6f1818 100644 --- a/src/credentials-manager/la-policies.js +++ b/src/credentials-manager/la-policies.js @@ -1,6 +1,6 @@ -const SecurityLevel = { +const LAPolicy = { deviceOwnerWithBiometrics: 1, deviceOwner: 2, } -export default SecurityLevel; \ No newline at end of file +export default LAPolicy; \ No newline at end of file From fb3c6fae0fe1712524f8e35d5fdf8e4f48cb52eb Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Thu, 26 Jan 2023 12:34:30 +0530 Subject: [PATCH 13/22] Use NSInteger --- ios/A0Auth0.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/A0Auth0.m b/ios/A0Auth0.m index e75322ae..135f98d0 100644 --- a/ios/A0Auth0.m +++ b/ios/A0Auth0.m @@ -68,7 +68,7 @@ - (dispatch_queue_t)methodQueue [self.credentialsManagerBridge clearCredentialsWithResolve:resolve reject:reject]; } -RCT_EXPORT_METHOD(enableLocalAuthentication:(NSString *)title cancelTitle:(NSString *)cancelTitle fallbackTitle:(NSString *)fallbackTitle evaluationPolicy:(NSNumber *)evaluationPolicy) { +RCT_EXPORT_METHOD(enableLocalAuthentication:(NSString *)title cancelTitle:(NSString *)cancelTitle fallbackTitle:(NSString *)fallbackTitle evaluationPolicy:(NSInteger)evaluationPolicy) { [self.credentialsManagerBridge enableLocalAuthenticationWithTitle:title cancelTitle:cancelTitle fallbackTitle:fallbackTitle evaluationPolicy: evaluationPolicy]; } From 7d56ab2c43fa2d43b0bc648b1da1aff2d68f299d Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Thu, 26 Jan 2023 13:18:29 +0530 Subject: [PATCH 14/22] Defaults to deviceOwnerWithBiometrics --- src/credentials-manager/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/credentials-manager/index.js b/src/credentials-manager/index.js index 900f47f7..6cf96d37 100644 --- a/src/credentials-manager/index.js +++ b/src/credentials-manager/index.js @@ -84,7 +84,7 @@ class CredentialsManager { * @param {String} description Android Only - optional - the text to use as description in the authentication screen. On some Android versions it might not be shown. Passing null will result in using the OS's default value. * @param {String} cancelTitle iOS Only - optional - the cancel message to display on the local authentication prompt. * @param {String} fallbackTitle iOS Only - optional - the fallback message to display on the local authentication prompt after a failed match. - * @param {String} securityLevel iOS Only - optional - the evaluation policy to use when accessing the credentials + * @param {String} laPolicy iOS Only - optional - the evaluation policy to use when accessing the credentials. Defaults to LAPolicy.deviceOwnerWithBiometrics. * @returns {Promise} */ async requireLocalAuthentication( @@ -92,7 +92,7 @@ class CredentialsManager { description, cancelTitle, fallbackTitle, - securityLevel = LAPolicy.deviceOwner, + laPolicy = LAPolicy.deviceOwnerWithBiometrics, ) { try { await this._ensureCredentialManagerIsInitialized(); @@ -101,7 +101,7 @@ class CredentialsManager { title, cancelTitle, fallbackTitle, - securityLevel + laPolicy ); } else { await this.Auth0Module.enableLocalAuthentication(title, description); From 0364a673b6d7e9bb8f7ec358a0ce496261806f74 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Thu, 26 Jan 2023 13:18:52 +0530 Subject: [PATCH 15/22] Start enum from 0 --- src/credentials-manager/la-policies.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/credentials-manager/la-policies.js b/src/credentials-manager/la-policies.js index 3f6f1818..c8bc6fdb 100644 --- a/src/credentials-manager/la-policies.js +++ b/src/credentials-manager/la-policies.js @@ -1,6 +1,6 @@ const LAPolicy = { - deviceOwnerWithBiometrics: 1, - deviceOwner: 2, + deviceOwnerWithBiometrics: 0, + deviceOwner: 1, } export default LAPolicy; \ No newline at end of file From ffda7ccb72bedf09e73a4a26535beb9e272f9900 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Thu, 26 Jan 2023 13:19:36 +0530 Subject: [PATCH 16/22] Revert "Start enum from 0" This reverts commit 0364a673b6d7e9bb8f7ec358a0ce496261806f74. --- src/credentials-manager/la-policies.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/credentials-manager/la-policies.js b/src/credentials-manager/la-policies.js index c8bc6fdb..3f6f1818 100644 --- a/src/credentials-manager/la-policies.js +++ b/src/credentials-manager/la-policies.js @@ -1,6 +1,6 @@ const LAPolicy = { - deviceOwnerWithBiometrics: 0, - deviceOwner: 1, + deviceOwnerWithBiometrics: 1, + deviceOwner: 2, } export default LAPolicy; \ No newline at end of file From 3693b4ef03f7354e60d4494f97f366752c863e34 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Thu, 26 Jan 2023 17:49:49 +0530 Subject: [PATCH 17/22] Refactor SecurityLevel to LAPolicy --- index.js | 2 +- src/hooks/__tests__/use-auth0.spec.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 2152b8e5..5c910756 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ export {TimeoutError} from './src/utils/fetchWithTimeout'; export {default as useAuth0} from './src/hooks/use-auth0'; export {default as Auth0Provider} from './src/hooks/auth0-provider'; -export {SecurityLevel} from './src/credentials-manager/la-policies'; +export {LAPolicy} from './src/credentials-manager/la-policies'; import Auth0 from './src/auth0'; export default Auth0; diff --git a/src/hooks/__tests__/use-auth0.spec.js b/src/hooks/__tests__/use-auth0.spec.js index 8d012e42..d075c7c4 100644 --- a/src/hooks/__tests__/use-auth0.spec.js +++ b/src/hooks/__tests__/use-auth0.spec.js @@ -5,7 +5,7 @@ import * as React from 'react'; import {renderHook} from '@testing-library/react-hooks'; import Auth0Provider from '../auth0-provider'; import useAuth0 from '../use-auth0'; -import SecurityLevel from '../../credentials-manager/la-policies'; +import LAPolicy from '../../credentials-manager/la-policies'; import {act} from 'react-dom/test-utils'; function makeJwt(claims) { @@ -416,12 +416,12 @@ describe('The useAuth0 hook', () => { 'description', 'cancel', 'fallback', - SecurityLevel.deviceOwner + LAPolicy.deviceOwner ); expect( mockAuth0.credentialsManager.requireLocalAuthentication, - ).toHaveBeenCalledWith('title', 'description', 'cancel', 'fallback', SecurityLevel.deviceOwner); + ).toHaveBeenCalledWith('title', 'description', 'cancel', 'fallback', LAPolicy.deviceOwner); }); it('dispatches an error when requireLocalAuthentication fails', async () => { From a7fb458d20b7d24bc7ca30464b2b0e9ca5094596 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Tue, 31 Jan 2023 14:00:02 +0530 Subject: [PATCH 18/22] Refactor LAPolicy to LocalAuthenticationStrategy --- index.js | 2 +- src/credentials-manager/index.js | 8 ++++---- src/credentials-manager/la-policies.js | 6 ------ src/credentials-manager/localAuthenticationStrategy.js | 6 ++++++ src/hooks/__tests__/use-auth0.spec.js | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) delete mode 100644 src/credentials-manager/la-policies.js create mode 100644 src/credentials-manager/localAuthenticationStrategy.js diff --git a/index.js b/index.js index 5c910756..4194de50 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ export {TimeoutError} from './src/utils/fetchWithTimeout'; export {default as useAuth0} from './src/hooks/use-auth0'; export {default as Auth0Provider} from './src/hooks/auth0-provider'; -export {LAPolicy} from './src/credentials-manager/la-policies'; +export {default as LocalAuthenticationStrategy} from './src/credentials-manager/localAuthenticationStrategy'; import Auth0 from './src/auth0'; export default Auth0; diff --git a/src/credentials-manager/index.js b/src/credentials-manager/index.js index 6cf96d37..149a268b 100644 --- a/src/credentials-manager/index.js +++ b/src/credentials-manager/index.js @@ -1,6 +1,6 @@ import {Platform, NativeModules} from 'react-native'; import CredentialsManagerError from './credentialsManagerError'; -import LAPolicy from './la-policies'; +import LocalAuthenticationStrategy from './localAuthenticationStrategy'; class CredentialsManager { /** @@ -84,7 +84,7 @@ class CredentialsManager { * @param {String} description Android Only - optional - the text to use as description in the authentication screen. On some Android versions it might not be shown. Passing null will result in using the OS's default value. * @param {String} cancelTitle iOS Only - optional - the cancel message to display on the local authentication prompt. * @param {String} fallbackTitle iOS Only - optional - the fallback message to display on the local authentication prompt after a failed match. - * @param {String} laPolicy iOS Only - optional - the evaluation policy to use when accessing the credentials. Defaults to LAPolicy.deviceOwnerWithBiometrics. + * @param {String} localAuthenticationStrategy iOS Only - optional - the evaluation policy to use when accessing the credentials. Defaults to LocalAuthenticationStrategy.deviceOwnerWithBiometrics. * @returns {Promise} */ async requireLocalAuthentication( @@ -92,7 +92,7 @@ class CredentialsManager { description, cancelTitle, fallbackTitle, - laPolicy = LAPolicy.deviceOwnerWithBiometrics, + localAuthenticationStrategy = LocalAuthenticationStrategy.deviceOwnerWithBiometrics, ) { try { await this._ensureCredentialManagerIsInitialized(); @@ -101,7 +101,7 @@ class CredentialsManager { title, cancelTitle, fallbackTitle, - laPolicy + localAuthenticationStrategy ); } else { await this.Auth0Module.enableLocalAuthentication(title, description); diff --git a/src/credentials-manager/la-policies.js b/src/credentials-manager/la-policies.js deleted file mode 100644 index 3f6f1818..00000000 --- a/src/credentials-manager/la-policies.js +++ /dev/null @@ -1,6 +0,0 @@ -const LAPolicy = { - deviceOwnerWithBiometrics: 1, - deviceOwner: 2, -} - -export default LAPolicy; \ No newline at end of file diff --git a/src/credentials-manager/localAuthenticationStrategy.js b/src/credentials-manager/localAuthenticationStrategy.js new file mode 100644 index 00000000..da2e86df --- /dev/null +++ b/src/credentials-manager/localAuthenticationStrategy.js @@ -0,0 +1,6 @@ +const LocalAuthenticationStrategy = { + deviceOwnerWithBiometrics: 1, + deviceOwner: 2, +} + +export default LocalAuthenticationStrategy; \ No newline at end of file diff --git a/src/hooks/__tests__/use-auth0.spec.js b/src/hooks/__tests__/use-auth0.spec.js index d075c7c4..01240015 100644 --- a/src/hooks/__tests__/use-auth0.spec.js +++ b/src/hooks/__tests__/use-auth0.spec.js @@ -5,7 +5,7 @@ import * as React from 'react'; import {renderHook} from '@testing-library/react-hooks'; import Auth0Provider from '../auth0-provider'; import useAuth0 from '../use-auth0'; -import LAPolicy from '../../credentials-manager/la-policies'; +import LocalAuthenticationStrategy from '../../credentials-manager/la-policies'; import {act} from 'react-dom/test-utils'; function makeJwt(claims) { @@ -416,12 +416,12 @@ describe('The useAuth0 hook', () => { 'description', 'cancel', 'fallback', - LAPolicy.deviceOwner + LocalAuthenticationStrategy.deviceOwner ); expect( mockAuth0.credentialsManager.requireLocalAuthentication, - ).toHaveBeenCalledWith('title', 'description', 'cancel', 'fallback', LAPolicy.deviceOwner); + ).toHaveBeenCalledWith('title', 'description', 'cancel', 'fallback', LocalAuthenticationStrategy.deviceOwner); }); it('dispatches an error when requireLocalAuthentication fails', async () => { From 518018eba066ad717464c4ab07fed940e04f8970 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Tue, 31 Jan 2023 20:13:16 +0530 Subject: [PATCH 19/22] Update src/credentials-manager/index.js Co-authored-by: Rita Zerrizuela --- src/credentials-manager/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/credentials-manager/index.js b/src/credentials-manager/index.js index 149a268b..fb6683a2 100644 --- a/src/credentials-manager/index.js +++ b/src/credentials-manager/index.js @@ -84,7 +84,7 @@ class CredentialsManager { * @param {String} description Android Only - optional - the text to use as description in the authentication screen. On some Android versions it might not be shown. Passing null will result in using the OS's default value. * @param {String} cancelTitle iOS Only - optional - the cancel message to display on the local authentication prompt. * @param {String} fallbackTitle iOS Only - optional - the fallback message to display on the local authentication prompt after a failed match. - * @param {String} localAuthenticationStrategy iOS Only - optional - the evaluation policy to use when accessing the credentials. Defaults to LocalAuthenticationStrategy.deviceOwnerWithBiometrics. + * @param {String} strategy iOS Only - optional - the evaluation policy to use when accessing the credentials. Defaults to LocalAuthenticationStrategy.deviceOwnerWithBiometrics. * @returns {Promise} */ async requireLocalAuthentication( @@ -92,7 +92,7 @@ class CredentialsManager { description, cancelTitle, fallbackTitle, - localAuthenticationStrategy = LocalAuthenticationStrategy.deviceOwnerWithBiometrics, + strategy = LocalAuthenticationStrategy.deviceOwnerWithBiometrics, ) { try { await this._ensureCredentialManagerIsInitialized(); From dd18f5775eb6508749bdc6c4996623881b283bf7 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Tue, 31 Jan 2023 20:13:26 +0530 Subject: [PATCH 20/22] Update src/credentials-manager/index.js Co-authored-by: Rita Zerrizuela --- src/credentials-manager/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/credentials-manager/index.js b/src/credentials-manager/index.js index fb6683a2..3a74a430 100644 --- a/src/credentials-manager/index.js +++ b/src/credentials-manager/index.js @@ -101,7 +101,7 @@ class CredentialsManager { title, cancelTitle, fallbackTitle, - localAuthenticationStrategy + strategy ); } else { await this.Auth0Module.enableLocalAuthentication(title, description); From cfd84309776bf89ee7fb19157b209cd66a95a8d8 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Tue, 31 Jan 2023 21:10:38 +0530 Subject: [PATCH 21/22] Trigger Build From 9c4407c582a4e82ac3f34a326239059685df4ed1 Mon Sep 17 00:00:00 2001 From: Poovamraj T T Date: Wed, 1 Feb 2023 00:15:23 +0530 Subject: [PATCH 22/22] Fix broken tests --- src/hooks/__tests__/use-auth0.spec.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hooks/__tests__/use-auth0.spec.js b/src/hooks/__tests__/use-auth0.spec.js index eb0a3031..bef16dab 100644 --- a/src/hooks/__tests__/use-auth0.spec.js +++ b/src/hooks/__tests__/use-auth0.spec.js @@ -5,7 +5,7 @@ import * as React from 'react'; import {renderHook} from '@testing-library/react-hooks'; import Auth0Provider from '../auth0-provider'; import useAuth0 from '../use-auth0'; -import LocalAuthenticationStrategy from '../../credentials-manager/la-policies'; +import LocalAuthenticationStrategy from '../../credentials-manager/localAuthenticationStrategy'; import {act} from 'react-dom/test-utils'; function makeJwt(claims) { @@ -180,8 +180,9 @@ describe('The useAuth0 hook', () => { scope: 'custom-scope openid profile email', audience: 'http://my-api', customParam: '1234', + }, { + ephemeralSession: true }, - {}, ); });