|
41 | 41 | import static org.privacyidea.PIConstants.GENKEY;
|
42 | 42 | import static org.privacyidea.PIConstants.GET;
|
43 | 43 | import static org.privacyidea.PIConstants.HEADER_ORIGIN;
|
| 44 | +import static org.privacyidea.PIConstants.OTPKEY; |
44 | 45 | import static org.privacyidea.PIConstants.PASS;
|
45 | 46 | import static org.privacyidea.PIConstants.PASSWORD;
|
46 | 47 | import static org.privacyidea.PIConstants.POST;
|
@@ -379,6 +380,33 @@ public RolloutInfo tokenRollout(String username, String typeToEnroll)
|
379 | 380 | return parser.parseRolloutInfo(response);
|
380 | 381 | }
|
381 | 382 |
|
| 383 | + /** |
| 384 | + * Init a new token of the specified type for the specified user. |
| 385 | + * This requires a service account to be set. Currently, only HOTP and TOTP type token are supported. |
| 386 | + * |
| 387 | + * @param username username |
| 388 | + * @param typeToEnroll token type to enroll |
| 389 | + * @param otpKey secret to import |
| 390 | + * @return RolloutInfo which contains all info for the token or null if error |
| 391 | + */ |
| 392 | + public RolloutInfo tokenInit(String username, String typeToEnroll, String otpKey) |
| 393 | + { |
| 394 | + if (!serviceAccountAvailable()) |
| 395 | + { |
| 396 | + error("Cannot do rollout without service account!"); |
| 397 | + return null; |
| 398 | + } |
| 399 | + |
| 400 | + Map<String, String> params = new LinkedHashMap<>(); |
| 401 | + params.put(USER, username); |
| 402 | + params.put(TYPE, typeToEnroll); |
| 403 | + params.put(OTPKEY, otpKey); // Import the secret |
| 404 | + |
| 405 | + String response = runRequestAsync(ENDPOINT_TOKEN_INIT, params, new LinkedHashMap<>(), true, POST); |
| 406 | + |
| 407 | + return parser.parseRolloutInfo(response); |
| 408 | + } |
| 409 | + |
382 | 410 | private void appendRealm(Map<String, String> params)
|
383 | 411 | {
|
384 | 412 | if (configuration.realm != null && !configuration.realm.isEmpty())
|
|
0 commit comments