Skip to content

Commit 5cda66b

Browse files
committed
Added example for APICredentials
1 parent b8fe479 commit 5cda66b

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

EXAMPLES.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- [Secure Credentials Manager](#secure-credentials-manager)
2828
- [Usage](#usage)
2929
- [Requiring Authentication](#requiring-authentication)
30+
- [Other Credentials](#other-credentials)
3031
- [Handling Credentials Manager exceptions](#handling-credentials-manager-exceptions)
3132
- [Passkeys](#passkeys)
3233
- [Bot Protection](#bot-protection)
@@ -658,7 +659,7 @@ authentication
658659
659660
Use the Auth0 My Account API to manage the current user's account.
660661

661-
To call the My Account API, you need an access token issued specifically for this API, including any required scopes for the operations you want to perform.
662+
To call the My Account API, you need an access token issued specifically for this API, including any required scopes for the operations you want to perform. See [API credentials [EA]](#api-credentials-ea) to learn how to obtain one.
662663

663664
### Enroll a new passkey
664665

@@ -846,6 +847,56 @@ AuthenticationLevel is an enum that defines the different levels of authenticati
846847
- **WEAK**: Any biometric (e.g., fingerprint, iris, or face) on the device that meets or exceeds the requirements for Class 2 (formerly Weak), as defined by the Android CDD.
847848
- **DEVICE_CREDENTIAL**: The non-biometric credential used to secure the device (i.e., PIN, pattern, or password).
848849

850+
851+
### Other Credentials
852+
853+
#### API credentials [EA]
854+
855+
> [!NOTE]
856+
> This feature is currently available in [Early Access](https://auth0.com/docs/troubleshoot/product-lifecycle/product-release-stages#early-access). Please reach out to Auth0 support to get it enabled for your tenant.
857+
858+
When the user logs in, you can request an access token for a specific API by passing its API identifier as the [audience](#specify-audience) value. The access token in the resulting credentials can then be used to make authenticated requests to that API.
859+
860+
However, if you need an access token for a different API, you can exchange the [refresh token](https://auth0.com/docs/secure/tokens/refresh-tokens) for credentials containing an access token specific to this other API.
861+
862+
> [!IMPORTANT]
863+
> Currently, only the Auth0 My Account API is supported. Support for other APIs will be added in the future.
864+
865+
```kotlin
866+
867+
credentialsManager.getApiCredentials(
868+
audience = "https://example.com/me", scope = " create:me:authentication_methods",
869+
callback = object : Callback<APICredentials, CredentialsManagerException> {
870+
override fun onSuccess(result: APICredentials) {
871+
print("Obtained API credentials: $result")
872+
}
873+
874+
override fun onFailure(error: CredentialsManagerException) {
875+
print("Failed with: $error")
876+
}
877+
})
878+
879+
```
880+
881+
<details>
882+
<summary>Using Coroutines</summary>
883+
884+
```kotlin
885+
886+
try {
887+
val result = credentialsManager.awaitApiCredentials(
888+
audience = "https://example.com/me",
889+
scope = "create:me:authentication_methods"
890+
)
891+
print("Obtained API credentials: $result")
892+
} catch (error: CredentialsManagerException) {
893+
print("Failed with: $error")
894+
}
895+
896+
```
897+
898+
</details>
899+
849900
### Handling Credentials Manager exceptions
850901

851902
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:

0 commit comments

Comments
 (0)