Skip to content

Commit 5a71404

Browse files
committed
Changed authentication method according to review comments and params updated Example.md file
1 parent 93c507b commit 5a71404

File tree

4 files changed

+382
-47
lines changed

4 files changed

+382
-47
lines changed

EXAMPLES.md

Lines changed: 353 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,359 @@ client.enroll(passkeyCredential, challenge)
970970
```
971971
</details>
972972

973+
### Get Available Factors
974+
**Scopes required:** `read:me:factors`
975+
```kotlin
976+
myAccountClient.getFactors()
977+
.start(object : Callback<Factors, MyAccountException> {
978+
override fun onSuccess(result: Factors) {
979+
// List of available factors in result.factors
980+
}
981+
override fun onFailure(error: MyAccountException) { }
982+
})
983+
```
984+
<details>
985+
<summary>Using Java</summary>
986+
987+
```java
988+
myAccountClient.getFactors()
989+
.start(new Callback<Factors, MyAccountException>() {
990+
@Override
991+
public void onSuccess(Factors result) {
992+
// List of available factors in result.getFactors()
993+
}
994+
@Override
995+
public void onFailure(@NonNull MyAccountException error) { }
996+
});
997+
```</details>
998+
999+
### Get All Enrolled Authentication Methods
1000+
**Scopes required:** `read:me:authentication_methods`
1001+
```kotlin
1002+
myAccountClient.getAuthenticationMethods()
1003+
.start(object : Callback<List<AuthenticationMethod>, MyAccountException> {
1004+
override fun onSuccess(result: AuthenticationMethods) {
1005+
// List of enrolled methods in result.authenticationMethods
1006+
}
1007+
override fun onFailure(error: MyAccountException) { }
1008+
})
1009+
```
1010+
<details>
1011+
<summary>Using Java</summary>
1012+
1013+
```java
1014+
myAccountClient.getAuthenticationMethods()
1015+
.start(new Callback<List<AuthenticationMethod>, MyAccountException>() {
1016+
@Override
1017+
public void onSuccess(AuthenticationMethods result) {
1018+
// List of enrolled methods in result.getAuthenticationMethods()
1019+
}
1020+
@Override
1021+
public void onFailure(@NonNull MyAccountException error) { }
1022+
});
1023+
```
1024+
</details>
1025+
1026+
### Get a Single Authentication Method by ID
1027+
**Scopes required:** `read:me:authentication_methods`
1028+
```kotlin
1029+
myAccountClient.getAuthenticationMethodById("phone|dev_...")
1030+
.start(object : Callback<AuthenticationMethod, MyAccountException> {
1031+
override fun onSuccess(result: AuthenticationMethod) {
1032+
// The requested authentication method
1033+
}
1034+
override fun onFailure(error: MyAccountException) { }
1035+
})
1036+
```
1037+
<details>
1038+
<summary>Using Java</summary>
1039+
1040+
```java
1041+
myAccountClient.getAuthenticationMethodById("phone|dev_...")
1042+
.start(new Callback<AuthenticationMethod, MyAccountException>() {
1043+
@Override
1044+
public void onSuccess(AuthenticationMethod result) {
1045+
// The requested authentication method
1046+
}
1047+
@Override
1048+
public void onFailure(@NonNull MyAccountException error) { }
1049+
});
1050+
```
1051+
</details>
1052+
1053+
### Enroll a Phone Method
1054+
**Scopes required:** `create:me:authentication_methods`
1055+
```kotlin
1056+
myAccountClient.enrollPhone("+11234567890", PhoneAuthenticationMethodType.SMS)
1057+
.start(object : Callback<EnrollmentChallenge, MyAccountException> {
1058+
override fun onSuccess(result: EnrollmentChallenge) {
1059+
// OTP sent. Use result.id and result.authSession to verify.
1060+
}
1061+
override fun onFailure(error: MyAccountException) { }
1062+
})
1063+
```
1064+
<details>
1065+
<summary>Using Java</summary>
1066+
1067+
```java
1068+
myAccountClient.enrollPhone("+11234567890", PhoneAuthenticationMethodType.SMS)
1069+
.start(new Callback<EnrollmentChallenge, MyAccountException>() {
1070+
@Override
1071+
public void onSuccess(EnrollmentChallenge result) {
1072+
// OTP sent. Use result.getId() and result.getAuthSession() to verify.
1073+
}
1074+
@Override
1075+
public void onFailure(@NonNull MyAccountException error) { }
1076+
});
1077+
```
1078+
</details>
1079+
1080+
### Enroll an Email Method
1081+
**Scopes required:** `create:me:authentication_methods`
1082+
```kotlin
1083+
myAccountClient.enrollEmail("[email protected]")
1084+
.start(object : Callback<EnrollmentChallenge, MyAccountException> {
1085+
override fun onSuccess(result: EnrollmentChallenge) {
1086+
// OTP sent. Use result.id and result.authSession to verify.
1087+
}
1088+
override fun onFailure(error: MyAccountException) { }
1089+
})
1090+
```
1091+
<details>
1092+
<summary>Using Java</summary>
1093+
1094+
```java
1095+
myAccountClient.enrollEmail("[email protected]")
1096+
.start(new Callback<EnrollmentChallenge, MyAccountException>() {
1097+
@Override
1098+
public void onSuccess(EnrollmentChallenge result) {
1099+
// OTP sent. Use result.getId() and result.getAuthSession() to verify.
1100+
}
1101+
@Override
1102+
public void onFailure(@NonNull MyAccountException error) { }
1103+
});
1104+
```
1105+
</details>
1106+
1107+
### Enroll a TOTP (Authenticator App) Method
1108+
**Scopes required:** `create:me:authentication_methods`
1109+
```kotlin
1110+
myAccountClient.enrollTotp()
1111+
.start(object : Callback<EnrollmentChallenge, MyAccountException> {
1112+
override fun onSuccess(result: EnrollmentChallenge) {
1113+
val totpChallenge = result as TotpEnrollmentChallenge
1114+
// Show QR code from totpChallenge.barcodeUri or manual code from totpChallenge.manualInputCode
1115+
// Then use result.id and result.authSession to verify.
1116+
}
1117+
override fun onFailure(error: MyAccountException) { }
1118+
})```
1119+
<details>
1120+
<summary>Using Java</summary>
1121+
1122+
```java
1123+
myAccountClient.enrollTotp()
1124+
.start(new Callback<EnrollmentChallenge, MyAccountException>() {
1125+
@Override
1126+
public void onSuccess(EnrollmentChallenge result) {
1127+
TotpEnrollmentChallenge totpChallenge = (TotpEnrollmentChallenge) result;
1128+
// Show QR code from totpChallenge.getBarcodeUri() or manual code from totpChallenge.getManualInputCode()
1129+
// Then use result.getId() and result.getAuthSession() to verify.
1130+
}
1131+
@Override
1132+
public void onFailure(@NonNull MyAccountException error) { }
1133+
});
1134+
```
1135+
</details>
1136+
1137+
### Enroll a Push Notification Method
1138+
**Scopes required:** `create:me:authentication_methods`
1139+
```kotlin
1140+
myAccountClient.enrollPushNotification()
1141+
.start(object : Callback<EnrollmentChallenge, MyAccountException> {
1142+
override fun onSuccess(result: EnrollmentChallenge) {
1143+
val pushChallenge = result as TotpEnrollmentChallenge // Uses the same response format as TOTP
1144+
// Show QR code from pushChallenge.barcodeUri to be scanned by Auth0 Guardian/Verify
1145+
// Then use result.id and result.authSession to verify.
1146+
}
1147+
override fun onFailure(error: MyAccountException) { }
1148+
})
1149+
```
1150+
<details>
1151+
<summary>Using Java</summary>
1152+
1153+
```java
1154+
myAccountClient.enrollPushNotification()
1155+
.start(new Callback<EnrollmentChallenge, MyAccountException>() {
1156+
@Override
1157+
public void onSuccess(EnrollmentChallenge result) {
1158+
TotpEnrollmentChallenge pushChallenge = (TotpEnrollmentChallenge) result;
1159+
// Show QR code from pushChallenge.getBarcodeUri() to be scanned by Auth0 Guardian/Verify
1160+
// Then use result.getId() and result.getAuthSession() to verify.
1161+
}
1162+
@Override
1163+
public void onFailure(@NonNull MyAccountException error) { }
1164+
});
1165+
```
1166+
</details>
1167+
1168+
### Enroll a Recovery Code
1169+
**Scopes required:** `create:me:authentication_methods`
1170+
```kotlin
1171+
myAccountClient.enrollRecoveryCode()
1172+
.start(object : Callback<EnrollmentChallenge, MyAccountException> {
1173+
override fun onSuccess(result: EnrollmentChallenge) {
1174+
val recoveryChallenge = result as RecoveryCodeEnrollmentChallenge
1175+
// Display and require the user to save recoveryChallenge.recoveryCode
1176+
// This method is already verified.
1177+
}
1178+
override fun onFailure(error: MyAccountException) { }
1179+
})
1180+
1181+
```
1182+
<details>
1183+
<summary>Using Java</summary>
1184+
1185+
```java
1186+
myAccountClient.enrollRecoveryCode()
1187+
.start(new Callback<EnrollmentChallenge, MyAccountException>() {
1188+
@Override
1189+
public void onSuccess(EnrollmentChallenge result) {
1190+
RecoveryCodeEnrollmentChallenge recoveryChallenge = (RecoveryCodeEnrollmentChallenge) result;
1191+
// Display and require the user to save recoveryChallenge.getRecoveryCode()
1192+
// This method is already verified.
1193+
}
1194+
@Override
1195+
public void onFailure(@NonNull MyAccountException error) { }
1196+
});
1197+
```
1198+
</details>
1199+
1200+
### Verify an Enrollment
1201+
**Scopes required:** `create:me:authentication_methods`
1202+
```kotlin
1203+
// For OTP-based factors (TOTP, Email, Phone)
1204+
myAccountClient.verifyOtp("challenge_id_from_enroll", "123456", "auth_session_from_enroll")
1205+
.start(object : Callback<AuthenticationMethod, MyAccountException> {
1206+
override fun onSuccess(result: AuthenticationMethod) {
1207+
// Enrollment successful
1208+
}
1209+
override fun onFailure(error: MyAccountException) { }
1210+
})
1211+
1212+
// For Push Notification factor
1213+
myAccountClient.verify("challenge_id_from_enroll", "auth_session_from_enroll")
1214+
.start(object : Callback<AuthenticationMethod, MyAccountException> {
1215+
override fun onSuccess(result: AuthenticationMethod) {
1216+
// Enrollment successful
1217+
}
1218+
override fun onFailure(error: MyAccountException) { }
1219+
})
1220+
```
1221+
<details>
1222+
<summary>Using Java</summary>
1223+
1224+
```java
1225+
// For OTP-based factors (TOTP, Email, Phone)
1226+
myAccountClient.verifyOtp("challenge_id_from_enroll", "123456", "auth_session_from_enroll")
1227+
.start(new Callback<AuthenticationMethod, MyAccountException>() {
1228+
@Override
1229+
public void onSuccess(AuthenticationMethod result) {
1230+
// Enrollment successful
1231+
}
1232+
@Override
1233+
public void onFailure(@NonNull MyAccountException error) { }
1234+
});
1235+
1236+
// For Push Notification factor
1237+
myAccountClient.verify("challenge_id_from_enroll", "auth_session_from_enroll")
1238+
.start(new Callback<AuthenticationMethod, MyAccountException>() {
1239+
@Override
1240+
public void onSuccess(AuthenticationMethod result) {
1241+
// Enrollment successful
1242+
}
1243+
@Override
1244+
public void onFailure(@NonNull MyAccountException error) { }
1245+
});
1246+
```
1247+
</details>
1248+
1249+
### Update an Authentication Method
1250+
**Scopes required:** `update:me:authentication_methods`
1251+
```kotlin
1252+
// Example: Update the name of a TOTP or Push method
1253+
myAccountClient.updateAuthenticationMethodById("totp|dev_...", name = "My Authenticator App")
1254+
.start(object : Callback<AuthenticationMethod, MyAccountException> {
1255+
override fun onSuccess(result: AuthenticationMethod) {
1256+
// Update successful
1257+
}
1258+
override fun onFailure(error: MyAccountException) { }
1259+
})
1260+
1261+
// Example: Update the preferred method of a Phone method
1262+
myAccountClient.updateAuthenticationMethodById("phone|dev_...", preferredAuthenticationMethod = PhoneAuthenticationMethodType.VOICE)
1263+
.start(object : Callback<AuthenticationMethod, MyAccountException> {
1264+
override fun onSuccess(result: AuthenticationMethod) {
1265+
// Update successful
1266+
}
1267+
override fun onFailure(error: MyAccountException) { }
1268+
})
1269+
```
1270+
<details>
1271+
<summary>Using Java</summary>
1272+
1273+
```java
1274+
// Example: Update the name of a TOTP or Push method
1275+
myAccountClient.updateAuthenticationMethodById("totp|dev_...", "My Authenticator App", null)
1276+
.start(new Callback<AuthenticationMethod, MyAccountException>() {
1277+
@Override
1278+
public void onSuccess(AuthenticationMethod result) {
1279+
// Update successful
1280+
}
1281+
@Override
1282+
public void onFailure(@NonNull MyAccountException error) { }
1283+
});
1284+
1285+
// Example: Update the preferred method of a Phone method
1286+
myAccountClient.updateAuthenticationMethodById("phone|dev_...", null, PhoneAuthenticationMethodType.VOICE)
1287+
.start(new Callback<AuthenticationMethod, MyAccountException>() {
1288+
@Override
1289+
public void onSuccess(AuthenticationMethod result) {
1290+
// Update successful
1291+
}
1292+
@Override
1293+
public void onFailure(@NonNull MyAccountException error) { }
1294+
});
1295+
```
1296+
</details>
1297+
1298+
### Delete an Authentication Method
1299+
**Scopes required:** `delete:me:authentication_methods`
1300+
```kotlin
1301+
myAccountClient.deleteAuthenticationMethod("phone|dev_...")
1302+
.start(object : Callback<Unit, MyAccountException> {
1303+
override fun onSuccess(result: Unit) {
1304+
// Deletion successful
1305+
}
1306+
override fun onFailure(error: MyAccountException) { }
1307+
})
1308+
```
1309+
<details>
1310+
<summary>Using Java</summary>
1311+
1312+
```java
1313+
myAccountClient.deleteAuthenticationMethod("phone|dev_...")
1314+
.start(new Callback<Void, MyAccountException>() {
1315+
@Override
1316+
public void onSuccess(Void result) {
1317+
// Deletion successful
1318+
}
1319+
@Override
1320+
public void onFailure(@NonNull MyAccountException error) { }
1321+
});
1322+
```
1323+
</details>
1324+
1325+
9731326
## Credentials Manager
9741327

9751328
### Secure Credentials Manager

0 commit comments

Comments
 (0)