Skip to content

Commit c3c8219

Browse files
authored
Added java code snippets for My Account examples (#841)
1 parent fb06876 commit c3c8219

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

EXAMPLES.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,29 @@ client.passkeyEnrollmentChallenge()
712712
```
713713
</details>
714714

715+
<details>
716+
<summary>Using Java</summary>
717+
718+
```java
719+
720+
MyAccountAPIClient client = new MyAccountAPIClient(account, "accessToken");
721+
722+
client.passkeyEnrollmentChallenge()
723+
.start(new Callback<PasskeyEnrollmentChallenge, MyAccountException>() {
724+
@Override
725+
public void onSuccess(PasskeyEnrollmentChallenge result) {
726+
System.out.println(result);
727+
}
728+
729+
@Override
730+
public void onFailure(@NonNull MyAccountException error) {
731+
System.out.println(error);
732+
}
733+
});
734+
735+
```
736+
</details>
737+
715738
#### 2. Create a new passkey credential
716739

717740
Use the enrollment challenge with the Google's [CredentialManager](https://developer.android.com/identity/sign-in/credential-manager) APIs to create a new passkey credential.
@@ -729,6 +752,32 @@ val passkeyCredentials = Gson().fromJson(
729752
PublicKeyCredentials::class.java
730753
)
731754
```
755+
<details>
756+
<summary>Using Java</summary>
757+
758+
```java
759+
760+
CreateCredentialRequest request =
761+
new CreatePublicKeyCredentialRequest(new Gson().toJson(enrollmentChallenge.authParamsPublicKey()));
762+
credentialManager.createCredentialAsync(getContext(),
763+
request,
764+
cancellationSignal,
765+
<executor>,
766+
new CredentialManagerCallback<CreateCredentialResponse, CreateCredentialException>() {
767+
@Override
768+
public void onResult(CreateCredentialResponse createCredentialResponse) {
769+
PublicKeyCredentials credentials = new Gson().fromJson(
770+
((CreatePublicKeyCredentialResponse) createCredentialResponse).getRegistrationResponseJson(),
771+
PublicKeyCredentials.class);
772+
}
773+
@Override
774+
public void onError(@NonNull CreateCredentialException e) {}
775+
});
776+
777+
```
778+
</details>
779+
780+
732781
#### 3. Enroll the passkey
733782

734783
Use the created passkey credential and the enrollment challenge to enroll the passkey with Auth0.
@@ -761,6 +810,27 @@ try {
761810
```
762811
</details>
763812

813+
<details>
814+
<summary>Using Java</summary>
815+
816+
```java
817+
818+
client.enroll(passkeyCredential, challenge)
819+
.start(new Callback<PasskeyAuthenticationMethod, MyAccountException>() {
820+
@Override
821+
public void onSuccess(@NonNull PasskeyAuthenticationMethod result) {
822+
System.out.println("Passkey enrolled successfully: " + result.getId());
823+
}
824+
825+
@Override
826+
public void onFailure(@NonNull MyAccountException error) {
827+
System.out.println("Error enrolling passkey: " + error.getMessage());
828+
}
829+
});
830+
831+
```
832+
</details>
833+
764834
## Credentials Manager
765835

766836
### Secure Credentials Manager
@@ -897,6 +967,31 @@ credentialsManager.getApiCredentials(
897967

898968
</details>
899969

970+
<details>
971+
<summary>Using Java</summary>
972+
973+
```java
974+
975+
credentialsManager.getApiCredentials("audience",
976+
"scope",
977+
0,
978+
new HashMap<>(),
979+
new HashMap<>(),
980+
new Callback<APICredentials, CredentialsManagerException>() {
981+
@Override
982+
public void onSuccess(APICredentials result) {
983+
System.out.println(result);
984+
}
985+
986+
@Override
987+
public void onFailure(@NonNull CredentialsManagerException error) {
988+
System.out.println(error);
989+
}
990+
});
991+
992+
```
993+
</details>
994+
900995
### Handling Credentials Manager exceptions
901996

902997
In the event that something happened while trying to save or retrieve the credentials, a `CredentialsManagerException` will be thrown. These are some of the expected failure scenarios:

auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
134134
* @return A request to obtain a passkey enrollment challenge
135135
*
136136
* */
137+
@JvmOverloads
137138
public fun passkeyEnrollmentChallenge(
138139
userIdentity: String? = null, connection: String? = null
139140
): Request<PasskeyEnrollmentChallenge, MyAccountException> {

0 commit comments

Comments
 (0)