| 1 |
#include "_helper.h" |
| 2 |
#include "account/account.h" |
| 3 |
#include "promptAndSet.h" |
| 4 |
#include "utils/listUtils.h" |
| 5 |
#include "utils/prompt.h" |
| 6 |
#include "utils/uriUtils.h" |
| 7 |
|
| 8 |
void askOrNeedRedirectUris(struct oidc_account* account, |
| 9 |
const struct arguments* arguments, int optional) { |
| 10 |
if (readRedirectUris(account, arguments)) { |
| 11 |
return; |
| 12 |
} |
| 13 |
ERROR_IF_NO_PROMPT(optional, |
| 14 |
ERROR_MESSAGE("redirect uri", OPT_LONG_REDIRECT)); |
| 15 |
while (1) { |
| 16 |
list_t* redirect_uris = promptMultiple( |
| 17 |
"Please enter Redirect URIs", "Redirect_uris", |
| 18 |
account_getRedirectUris(account), CLI_PROMPT_NOT_VERBOSE); |
| 19 |
oidc_error_t err = checkRedirectUrisForErrors(redirect_uris); |
| 20 |
if (err == OIDC_SUCCESS) { |
| 21 |
account_setRedirectUris(account, redirect_uris); |
| 22 |
return; |
| 23 |
} |
| 24 |
secFreeList(redirect_uris); |
| 25 |
if (err != |
| 26 |
OIDC_EERROR) { // If err == OIDC_EERROR a not valid redirect_uri |
| 27 |
// was entered, so the user want to provide input. |
| 28 |
// If err != OIDC_EERROR no input was provided |
| 29 |
if (optional) { |
| 30 |
return; |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
int readRedirectUris(struct oidc_account* account, |
| 37 |
const struct arguments* arguments) { |
| 38 |
if (arguments->redirect_uris) { |
| 39 |
account_setRedirectUris(account, arguments->redirect_uris); |
| 40 |
return 1; |
| 41 |
} |
| 42 |
if (prompt_mode() == 0 && account_getRedirectUris(account)) { |
| 43 |
return 1; |
| 44 |
} |
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
void askRedirectUris(struct oidc_account* account, |
| 49 |
const struct arguments* arguments) { |
| 50 |
return askOrNeedRedirectUris(account, arguments, 1); |
| 51 |
} |
| 52 |
|
| 53 |
void needRedirectUris(struct oidc_account* account, |
| 54 |
const struct arguments* arguments) { |
| 55 |
return askOrNeedRedirectUris(account, arguments, 0); |
| 56 |
} |