| 1 |
#include "_helper.h" |
| 2 |
#include "account/account.h" |
| 3 |
#include "promptAndSet.h" |
| 4 |
#include "utils/string/stringUtils.h" |
| 5 |
|
| 6 |
void askOrNeedDeviceAuthEndpoint(struct oidc_account* account, |
| 7 |
const struct arguments* arguments, |
| 8 |
int optional) { |
| 9 |
if (readDeviceAuthEndpoint(account, arguments)) { |
| 10 |
return; |
| 11 |
} |
| 12 |
ERROR_IF_NO_PROMPT(optional, ERROR_MESSAGE("device authorization endpoint", |
| 13 |
OPT_LONG_DEVICE)); |
| 14 |
char* res = |
| 15 |
_gen_prompt("Device Authorization Endpoint", |
| 16 |
account_getDeviceAuthorizationEndpoint(account), 0, optional); |
| 17 |
if (res) { |
| 18 |
issuer_setDeviceAuthorizationEndpoint(account_getIssuer(account), res, 1); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
int readDeviceAuthEndpoint(struct oidc_account* account, |
| 23 |
const struct arguments* arguments) { |
| 24 |
if (arguments->device_authorization_endpoint) { |
| 25 |
issuer_setDeviceAuthorizationEndpoint( |
| 26 |
account_getIssuer(account), |
| 27 |
oidc_strcopy(arguments->device_authorization_endpoint), 1); |
| 28 |
return 1; |
| 29 |
} |
| 30 |
if (prompt_mode() == 0 && |
| 31 |
strValid(account_getDeviceAuthorizationEndpoint(account))) { |
| 32 |
return 1; |
| 33 |
} |
| 34 |
return 0; |
| 35 |
} |
| 36 |
|
| 37 |
void askDeviceAuthEndpoint(struct oidc_account* account, |
| 38 |
const struct arguments* arguments) { |
| 39 |
return askOrNeedDeviceAuthEndpoint(account, arguments, 1); |
| 40 |
} |
| 41 |
|
| 42 |
void needDeviceAuthEndpoint(struct oidc_account* account, |
| 43 |
const struct arguments* arguments) { |
| 44 |
return askOrNeedDeviceAuthEndpoint(account, arguments, 0); |
| 45 |
} |