Skip to content

Commit 7b9db65

Browse files
refactor: Remove biometric policy options and related UI elements
1 parent 2867d4c commit 7b9db65

File tree

2 files changed

+18
-206
lines changed

2 files changed

+18
-206
lines changed

sample/src/main/java/com/auth0/sample/DatabaseLoginFragment.kt

Lines changed: 5 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import com.auth0.android.Auth0
2121
import com.auth0.android.authentication.AuthenticationAPIClient
2222
import com.auth0.android.authentication.AuthenticationException
2323
import com.auth0.android.authentication.storage.AuthenticationLevel
24-
import com.auth0.android.authentication.storage.BiometricPolicy
2524
import com.auth0.android.authentication.storage.CredentialsManager
2625
import com.auth0.android.authentication.storage.CredentialsManagerException
2726
import com.auth0.android.authentication.storage.LocalAuthenticationOptions
@@ -76,16 +75,6 @@ class DatabaseLoginFragment : Fragment() {
7675
AuthenticationAPIClient(account)
7776
}
7877

79-
private val localAuthenticationOptions =
80-
LocalAuthenticationOptions.Builder()
81-
.setTitle("Biometric")
82-
.setDescription("description")
83-
.setAuthenticationLevel(AuthenticationLevel.STRONG)
84-
.setNegativeButtonText("Cancel")
85-
.setDeviceCredentialFallback(true)
86-
.setPolicy(BiometricPolicy.Always) // Default policy - shows prompt every time
87-
.build()
88-
8978
private val secureCredentialsManager: SecureCredentialsManager by lazy {
9079
val storage = SharedPreferencesStorage(requireContext())
9180
val manager = SecureCredentialsManager(
@@ -98,50 +87,20 @@ class DatabaseLoginFragment : Fragment() {
9887
manager
9988
}
10089

101-
// Alternative managers with different biometric policies for demonstration
102-
private val secureCredentialsManagerSession: SecureCredentialsManager by lazy {
90+
private val credentialsManager: CredentialsManager by lazy {
10391
val storage = SharedPreferencesStorage(requireContext())
104-
val localAuthOptionsSession = LocalAuthenticationOptions.Builder()
105-
.setTitle("Biometric")
106-
.setDescription("description")
107-
.setAuthenticationLevel(AuthenticationLevel.STRONG)
108-
.setNegativeButtonText("Cancel")
109-
.setDeviceCredentialFallback(true)
110-
.setPolicy(BiometricPolicy.Session(timeoutInSeconds = 300)) // 5 minute session
111-
.build()
112-
SecureCredentialsManager(
113-
requireContext(),
114-
account,
115-
storage,
116-
requireActivity(),
117-
localAuthOptionsSession
118-
)
92+
val manager = CredentialsManager(authenticationApiClient, storage)
93+
manager
11994
}
12095

121-
private val secureCredentialsManagerAppLifecycle: SecureCredentialsManager by lazy {
122-
val storage = SharedPreferencesStorage(requireContext())
123-
val localAuthOptionsAppLifecycle = LocalAuthenticationOptions.Builder()
96+
private val localAuthenticationOptions =
97+
LocalAuthenticationOptions.Builder()
12498
.setTitle("Biometric")
12599
.setDescription("description")
126100
.setAuthenticationLevel(AuthenticationLevel.STRONG)
127101
.setNegativeButtonText("Cancel")
128102
.setDeviceCredentialFallback(true)
129-
.setPolicy(BiometricPolicy.AppLifecycle()) // Default 1 hour timeout
130103
.build()
131-
SecureCredentialsManager(
132-
requireContext(),
133-
account,
134-
storage,
135-
requireActivity(),
136-
localAuthOptionsAppLifecycle
137-
)
138-
}
139-
140-
private val credentialsManager: CredentialsManager by lazy {
141-
val storage = SharedPreferencesStorage(requireContext())
142-
val manager = CredentialsManager(authenticationApiClient, storage)
143-
manager
144-
}
145104

146105
private val callback = object: Callback<Credentials, AuthenticationException> {
147106
override fun onSuccess(result: Credentials) {
@@ -242,20 +201,6 @@ class DatabaseLoginFragment : Fragment() {
242201
updateMetaAsync()
243202
}
244203
}
245-
246-
// Biometric Policy Demo Buttons
247-
binding.btGetCredsAlways?.setOnClickListener {
248-
getCredsWithPolicy("Always", secureCredentialsManager)
249-
}
250-
binding.btGetCredsSession?.setOnClickListener {
251-
getCredsWithPolicy("Session (5min)", secureCredentialsManagerSession)
252-
}
253-
binding.btGetCredsAppLifecycle?.setOnClickListener {
254-
getCredsWithPolicy("AppLifecycle (1h)", secureCredentialsManagerAppLifecycle)
255-
}
256-
binding.btClearBiometricSession?.setOnClickListener {
257-
clearBiometricSessions()
258-
}
259204
return binding.root
260205
}
261206

@@ -807,50 +752,4 @@ class DatabaseLoginFragment : Fragment() {
807752
).show()
808753
}
809754
}
810-
811-
// =================
812-
// Biometric Policy Demo Methods
813-
// =================
814-
815-
/**
816-
* Demonstrates getting credentials with different biometric policies
817-
*/
818-
private fun getCredsWithPolicy(policyName: String, manager: SecureCredentialsManager) {
819-
manager.getCredentials(object : Callback<Credentials, CredentialsManagerException> {
820-
override fun onSuccess(result: Credentials) {
821-
Snackbar.make(
822-
requireView(),
823-
"$policyName Policy: Got credentials - ${result.accessToken.take(20)}...",
824-
Snackbar.LENGTH_LONG
825-
).show()
826-
}
827-
828-
override fun onFailure(error: CredentialsManagerException) {
829-
val message = when {
830-
error.message?.contains("No Credentials") == true ->
831-
"$policyName Policy: No credentials stored. Please login first."
832-
error.message?.contains("BIOMETRIC") == true ->
833-
"$policyName Policy: Biometric authentication failed - ${error.message}"
834-
else ->
835-
"$policyName Policy: ${error.message}"
836-
}
837-
Snackbar.make(requireView(), message, Snackbar.LENGTH_LONG).show()
838-
}
839-
})
840-
}
841-
842-
/**
843-
* Clears biometric sessions for all managers
844-
*/
845-
private fun clearBiometricSessions() {
846-
secureCredentialsManager.clearBiometricSession()
847-
secureCredentialsManagerSession.clearBiometricSession()
848-
secureCredentialsManagerAppLifecycle.clearBiometricSession()
849-
850-
Snackbar.make(
851-
requireView(),
852-
"🔄 All biometric sessions cleared. Next credential access will show biometric prompt.",
853-
Snackbar.LENGTH_LONG
854-
).show()
855-
}
856755
}

sample/src/main/res/layout/fragment_database_login.xml

Lines changed: 13 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,13 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
6-
android:layout_height="match_parent"
7-
android:fillViewport="true">
6+
android:layout_height="match_parent">
87

98
<androidx.constraintlayout.widget.ConstraintLayout
109
android:layout_width="match_parent"
11-
android:layout_height="wrap_content"
12-
android:paddingStart="8dp"
13-
android:paddingTop="8dp"
14-
android:paddingEnd="8dp"
15-
android:paddingBottom="32dp"
10+
android:layout_height="0dp"
1611
tools:context=".DatabaseLoginFragment">
1712

18-
<TextView
19-
android:id="@+id/textViewUserProfiles"
20-
android:layout_width="wrap_content"
21-
android:layout_height="wrap_content"
22-
android:layout_marginTop="188dp"
23-
android:text="User Profiles"
24-
android:textColor="@android:color/holo_blue_dark"
25-
android:textSize="16sp"
26-
app:layout_constraintEnd_toEndOf="parent"
27-
app:layout_constraintHorizontal_bias="0.439"
28-
app:layout_constraintStart_toStartOf="parent"
29-
app:layout_constraintTop_toBottomOf="@+id/btGetCredsAppLifecycle" />
30-
3113
<EditText
3214
android:id="@+id/textEmail"
3315
android:layout_width="0dp"
@@ -165,12 +147,11 @@
165147
app:layout_constraintTop_toBottomOf="@+id/btWebLogoutAsync" />
166148

167149
<TextView
168-
android:id="@+id/textViewUserManagement"
150+
android:id="@+id/textView5"
169151
android:layout_width="wrap_content"
170152
android:layout_height="wrap_content"
171-
android:layout_marginTop="184dp"
153+
android:layout_marginTop="8dp"
172154
android:text="User Management API"
173-
android:textColor="@android:color/holo_blue_dark"
174155
android:textSize="16sp"
175156
app:layout_constraintEnd_toEndOf="parent"
176157
app:layout_constraintStart_toStartOf="parent"
@@ -257,18 +238,17 @@
257238
android:id="@+id/btGetProfileAsync"
258239
android:layout_width="wrap_content"
259240
android:layout_height="wrap_content"
260-
android:layout_marginTop="16dp"
261-
android:layout_marginEnd="4dp"
241+
android:layout_marginTop="8dp"
262242
android:text="Get User Profile (async)"
263243
android:textSize="12sp"
264244
app:layout_constraintEnd_toEndOf="@+id/btGetCredentialsAsync"
265-
app:layout_constraintTop_toBottomOf="@+id/textViewUserManagement" />
245+
app:layout_constraintTop_toBottomOf="@+id/textView5" />
266246

267247
<Button
268248
android:id="@+id/btUpdateMetaAsync"
269249
android:layout_width="wrap_content"
270250
android:layout_height="wrap_content"
271-
android:layout_marginTop="20dp"
251+
android:layout_marginTop="8dp"
272252
android:text="Update Metadata (async)"
273253
android:textSize="12sp"
274254
app:layout_constraintEnd_toEndOf="@+id/btGetCredentialsAsync"
@@ -278,8 +258,8 @@
278258
android:id="@+id/btUpdateMeta"
279259
android:layout_width="wrap_content"
280260
android:layout_height="wrap_content"
281-
android:layout_marginTop="20dp"
282-
android:layout_marginEnd="40dp"
261+
android:layout_marginTop="8dp"
262+
android:layout_marginEnd="4dp"
283263
android:text="Update Metadata"
284264
android:textSize="12sp"
285265
app:layout_constraintEnd_toStartOf="@+id/btUpdateMetaAsync"
@@ -289,12 +269,12 @@
289269
android:id="@+id/btGetProfile"
290270
android:layout_width="wrap_content"
291271
android:layout_height="wrap_content"
292-
android:layout_marginTop="16dp"
293-
android:layout_marginEnd="48dp"
272+
android:layout_marginTop="8dp"
273+
android:layout_marginEnd="4dp"
294274
android:text="Get User Profile"
295275
android:textSize="12sp"
296276
app:layout_constraintEnd_toStartOf="@+id/btGetProfileAsync"
297-
app:layout_constraintTop_toBottomOf="@+id/textViewUserManagement" />
277+
app:layout_constraintTop_toBottomOf="@+id/textView5" />
298278

299279
<Button
300280
android:id="@+id/btWebLogoutAsync"
@@ -326,77 +306,10 @@
326306
android:layout_marginEnd="100dp"
327307
android:layout_marginBottom="6dp"
328308
android:text="Get Credentials (Secure)"
329-
app:layout_constraintBottom_toTopOf="@+id/textViewBiometricPolicy"
309+
app:layout_constraintBottom_toTopOf="@+id/textView5"
330310
app:layout_constraintEnd_toStartOf="@+id/btDeleteCredentials"
331311
app:layout_constraintStart_toStartOf="parent"
332312
app:layout_constraintTop_toBottomOf="@+id/btGetCredentials" />
333313

334-
<TextView
335-
android:id="@+id/textViewBiometricPolicy"
336-
android:layout_width="wrap_content"
337-
android:layout_height="wrap_content"
338-
android:layout_marginTop="20dp"
339-
android:text="Biometric Policy Examples"
340-
android:textColor="@android:color/holo_blue_dark"
341-
android:textSize="16sp"
342-
android:textStyle="bold"
343-
app:layout_constraintEnd_toEndOf="parent"
344-
app:layout_constraintHorizontal_bias="0.49"
345-
app:layout_constraintStart_toStartOf="parent"
346-
app:layout_constraintTop_toBottomOf="@+id/getCredentialsSecure" />
347-
348-
<Button
349-
android:id="@+id/btGetCredsAlways"
350-
android:layout_width="0dp"
351-
android:layout_height="wrap_content"
352-
android:layout_marginStart="16dp"
353-
android:layout_marginTop="8dp"
354-
android:layout_marginEnd="8dp"
355-
android:text="Get Creds\n(Always Policy)"
356-
android:textSize="11sp"
357-
app:layout_constraintEnd_toStartOf="@+id/btGetCredsSession"
358-
app:layout_constraintStart_toStartOf="parent"
359-
app:layout_constraintTop_toBottomOf="@+id/textViewBiometricPolicy" />
360-
361-
<Button
362-
android:id="@+id/btGetCredsSession"
363-
android:layout_width="0dp"
364-
android:layout_height="wrap_content"
365-
android:layout_marginStart="8dp"
366-
android:layout_marginTop="8dp"
367-
android:layout_marginEnd="16dp"
368-
android:text="Get Creds\n(Session Policy)"
369-
android:textSize="11sp"
370-
app:layout_constraintEnd_toEndOf="parent"
371-
app:layout_constraintStart_toEndOf="@+id/btGetCredsAlways"
372-
app:layout_constraintTop_toBottomOf="@+id/textViewBiometricPolicy" />
373-
374-
<Button
375-
android:id="@+id/btGetCredsAppLifecycle"
376-
android:layout_width="0dp"
377-
android:layout_height="wrap_content"
378-
android:layout_marginStart="16dp"
379-
android:layout_marginTop="8dp"
380-
android:layout_marginEnd="8dp"
381-
android:text="Get Creds\n(AppLifecycle 1h)"
382-
android:textSize="11sp"
383-
app:layout_constraintEnd_toStartOf="@+id/btClearBiometricSession"
384-
app:layout_constraintStart_toStartOf="parent"
385-
app:layout_constraintTop_toBottomOf="@+id/btGetCredsAlways" />
386-
387-
<Button
388-
android:id="@+id/btClearBiometricSession"
389-
android:layout_width="0dp"
390-
android:layout_height="wrap_content"
391-
android:layout_marginStart="8dp"
392-
android:layout_marginTop="8dp"
393-
android:layout_marginEnd="16dp"
394-
android:text="Clear Biometric\nSessions"
395-
android:textSize="11sp"
396-
app:layout_constraintEnd_toEndOf="parent"
397-
app:layout_constraintStart_toEndOf="@+id/btGetCredsAppLifecycle"
398-
app:layout_constraintTop_toBottomOf="@+id/btGetCredsSession" />
399-
400-
401314
</androidx.constraintlayout.widget.ConstraintLayout>
402315
</ScrollView>

0 commit comments

Comments
 (0)