Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
315 changes: 315 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
- [DPoP [EA]](#dpop-ea-1)
- [My Account API](#my-account-api)
- [Enroll a new passkey](#enroll-a-new-passkey)
- [Get Available Factors](#get-available-factors)
- [Get All Enrolled Authentication Methods](#get-all-enrolled-authentication-methods)
- [Get a Single Authentication Method by ID](#get-a-single-authentication-method-by-id)
- [Enroll a Phone Method](#enroll-a-phone-method)
- [Enroll an Email Method](#enroll-an-email-method)
- [Enroll a TOTP (Authenticator App) Method](#enroll-a-totp-authenticator-app-method)
- [Enroll a Push Notification Method](#enroll-a-push-notification-method)
- [Enroll a Recovery Code](#enroll-a-recovery-code)
- [Verify an Enrollment](#verify-an-enrollment)
- [Update an Authentication Method](#update-an-authentication-method)
- [Delete an Authentication Method](#delete-an-authentication-method)
- [Credentials Manager](#credentials-manager)
- [Secure Credentials Manager](#secure-credentials-manager)
- [Usage](#usage)
Expand Down Expand Up @@ -959,6 +970,310 @@ client.enroll(passkeyCredential, challenge)
```
</details>

### Get Available Factors
**Scopes required:** `read:me:factors`
```kotlin
myAccountClient.getFactors()
.start(object : Callback<List<Factor>, MyAccountException> {
override fun onSuccess(result: Factors) {
// List of available factors in result.factors
}
override fun onFailure(error: MyAccountException) { }
})
```
<details>
<summary>Using Java</summary>

```java
myAccountClient.getFactors()
.start(new Callback<List<Factor>, MyAccountException>() {
@Override
public void onSuccess(Factors result) {
// List of available factors in result.getFactors()
}
@Override
public void onFailure(@NonNull MyAccountException error) { }
});
```</details>

### Get All Enrolled Authentication Methods
**Scopes required:** `read:me:authentication_methods`
```kotlin
myAccountClient.getAuthenticationMethods()
.start(object : Callback<List<AuthenticationMethod>, MyAccountException> {
override fun onSuccess(result: AuthenticationMethods) {
// List of enrolled methods in result.authenticationMethods
}
override fun onFailure(error: MyAccountException) { }
})
```
<details>
<summary>Using Java</summary>

```java
myAccountClient.getAuthenticationMethods()
.start(new Callback<List<AuthenticationMethod>, MyAccountException>() {
@Override
public void onSuccess(AuthenticationMethods result) {
// List of enrolled methods in result.getAuthenticationMethods()
}
@Override
public void onFailure(@NonNull MyAccountException error) { }
});
```
</details>

### Get a Single Authentication Method by ID
**Scopes required:** `read:me:authentication_methods`
```kotlin
myAccountClient.getAuthenticationMethodById("phone|dev_...")
.start(object : Callback<AuthenticationMethod, MyAccountException> {
override fun onSuccess(result: AuthenticationMethod) {
// The requested authentication method
}
override fun onFailure(error: MyAccountException) { }
})
```
<details>
<summary>Using Java</summary>

```java
myAccountClient.getAuthenticationMethodById("phone|dev_...")
.start(new Callback<AuthenticationMethod, MyAccountException>() {
@Override
public void onSuccess(AuthenticationMethod result) {
// The requested authentication method
}
@Override
public void onFailure(@NonNull MyAccountException error) { }
});
```
</details>

### Enroll a Phone Method
**Scopes required:** `create:me:authentication_methods`
```kotlin
myAccountClient.enrollPhone("+11234567890", PhoneAuthenticationMethodType.SMS)
.start(object : Callback<EnrollmentChallenge, MyAccountException> {
override fun onSuccess(result: EnrollmentChallenge) {
// OTP sent. Use result.id and result.authSession to verify.
}
override fun onFailure(error: MyAccountException) { }
})
```
<details>
<summary>Using Java</summary>

```java
myAccountClient.enrollPhone("+11234567890", PhoneAuthenticationMethodType.SMS)
.start(new Callback<EnrollmentChallenge, MyAccountException>() {
@Override
public void onSuccess(EnrollmentChallenge result) {
// OTP sent. Use result.getId() and result.getAuthSession() to verify.
}
@Override
public void onFailure(@NonNull MyAccountException error) { }
});
```
</details>

### Enroll an Email Method
**Scopes required:** `create:me:authentication_methods`
```kotlin
myAccountClient.enrollEmail("user@example.com")
.start(object : Callback<EnrollmentChallenge, MyAccountException> {
override fun onSuccess(result: EnrollmentChallenge) {
// OTP sent. Use result.id and result.authSession to verify.
}
override fun onFailure(error: MyAccountException) { }
})
```
<details>
<summary>Using Java</summary>

```java
myAccountClient.enrollEmail("user@example.com")
.start(new Callback<EnrollmentChallenge, MyAccountException>() {
@Override
public void onSuccess(EnrollmentChallenge result) {
// OTP sent. Use result.getId() and result.getAuthSession() to verify.
}
@Override
public void onFailure(@NonNull MyAccountException error) { }
});
```
</details>

### Enroll a TOTP (Authenticator App) Method
**Scopes required:** `create:me:authentication_methods`
```kotlin
myAccountClient.enrollTotp()
.start(object : Callback<TotpEnrollmentChallenge, MyAccountException> {
override fun onSuccess(result: EnrollmentChallenge) {
val totpChallenge = result as TotpEnrollmentChallenge
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do the users need to explicitly cast them to TotpEnrollmentChallenge ? Why can't we return an instance of TotpEnrollmentChallenge ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to make the necessary changes in line 1112 and 1113

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// Show QR code from totpChallenge.barcodeUri or manual code from totpChallenge.manualInputCode
// Then use result.id and result.authSession to verify.
}
override fun onFailure(error: MyAccountException) { }
})```
<details>
<summary>Using Java</summary>

```java
myAccountClient.enrollTotp()
.start(new Callback<TotpEnrollmentChallenge, MyAccountException>() {
@Override
public void onSuccess(EnrollmentChallenge result) {
TotpEnrollmentChallenge totpChallenge = (TotpEnrollmentChallenge) result;
// Show QR code from totpChallenge.getBarcodeUri() or manual code from totpChallenge.getManualInputCode()
// Then use result.getId() and result.getAuthSession() to verify.
}
@Override
public void onFailure(@NonNull MyAccountException error) { }
});
```
</details>

### Enroll a Push Notification Method
**Scopes required:** `create:me:authentication_methods`
```kotlin
myAccountClient.enrollPushNotification()
.start(object : Callback<TotpEnrollmentChallenge, MyAccountException> {
override fun onSuccess(result: EnrollmentChallenge) {
val pushChallenge = result as TotpEnrollmentChallenge // Uses the same response format as TOTP
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary changes in line 1142 and 1143

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// Show QR code from pushChallenge.barcodeUri to be scanned by Auth0 Guardian/Verify
// Then use result.id and result.authSession to verify.
}
override fun onFailure(error: MyAccountException) { }
})
```
<details>
<summary>Using Java</summary>

```java
myAccountClient.enrollPushNotification()
.start(new Callback<TotpEnrollmentChallenge, MyAccountException>() {
@Override
public void onSuccess(EnrollmentChallenge result) {
TotpEnrollmentChallenge pushChallenge = (TotpEnrollmentChallenge) result;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in line 1157 and 1158

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// Show QR code from pushChallenge.getBarcodeUri() to be scanned by Auth0 Guardian/Verify
// Then use result.getId() and result.getAuthSession() to verify.
}
@Override
public void onFailure(@NonNull MyAccountException error) { }
});
```
</details>

### Enroll a Recovery Code
**Scopes required:** `create:me:authentication_methods`
```kotlin
myAccountClient.enrollRecoveryCode()
.start(object : Callback<RecoveryCodeEnrollmentChallenge, MyAccountException> {
override fun onSuccess(result: EnrollmentChallenge) {
val recoveryChallenge = result as RecoveryCodeEnrollmentChallenge
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we return an instance of RecoveryCodeEnrollmentChallenge ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in line 1173 and 1174

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// Display and require the user to save recoveryChallenge.recoveryCode
// This method is already verified.
}
override fun onFailure(error: MyAccountException) { }
})

```
<details>
<summary>Using Java</summary>

```java
myAccountClient.enrollRecoveryCode()
.start(new Callback<EnrollmentChallenge, MyAccountException>() {
@Override
public void onSuccess(RecoveryCodeEnrollmentChallenge result) {
RecoveryCodeEnrollmentChallenge recoveryChallenge = (RecoveryCodeEnrollmentChallenge) result;
// Display and require the user to save recoveryChallenge.getRecoveryCode()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in line 1190

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// This method is already verified.
}
@Override
public void onFailure(@NonNull MyAccountException error) { }
});
```
</details>

### Verify an Enrollment
**Scopes required:** `create:me:authentication_methods`
```kotlin
// For OTP-based factors (TOTP, Email, Phone)
myAccountClient.verifyOtp("challenge_id_from_enroll", "123456", "auth_session_from_enroll")
.start(object : Callback<AuthenticationMethod, MyAccountException> {
override fun onSuccess(result: AuthenticationMethod) {
// Enrollment successful
}
override fun onFailure(error: MyAccountException) { }
})

// For Push Notification factor
myAccountClient.verify("challenge_id_from_enroll", "auth_session_from_enroll")
.start(object : Callback<AuthenticationMethod, MyAccountException> {
override fun onSuccess(result: AuthenticationMethod) {
// Enrollment successful
}
override fun onFailure(error: MyAccountException) { }
})
```
<details>
<summary>Using Java</summary>

```java
// For OTP-based factors (TOTP, Email, Phone)
myAccountClient.verifyOtp("challenge_id_from_enroll", "123456", "auth_session_from_enroll")
.start(new Callback<AuthenticationMethod, MyAccountException>() {
@Override
public void onSuccess(AuthenticationMethod result) {
// Enrollment successful
}
@Override
public void onFailure(@NonNull MyAccountException error) { }
});

// For Push Notification factor
myAccountClient.verify("challenge_id_from_enroll", "auth_session_from_enroll")
.start(new Callback<AuthenticationMethod, MyAccountException>() {
@Override
public void onSuccess(AuthenticationMethod result) {
// Enrollment successful
}
@Override
public void onFailure(@NonNull MyAccountException error) { }
});
```
</details>

### Delete an Authentication Method
**Scopes required:** `delete:me:authentication_methods`
```kotlin
myAccountClient.deleteAuthenticationMethod("phone|dev_...")
.start(object : Callback<Unit, MyAccountException> {
override fun onSuccess(result: Unit) {
// Deletion successful
}
override fun onFailure(error: MyAccountException) { }
})
```
<details>
<summary>Using Java</summary>

```java
myAccountClient.deleteAuthenticationMethod("phone|dev_...")
.start(new Callback<Void, MyAccountException>() {
@Override
public void onSuccess(Void result) {
// Deletion successful
}
@Override
public void onFailure(@NonNull MyAccountException error) { }
});
```
</details>


## Credentials Manager

### Secure Credentials Manager
Expand Down
Loading