Debian Codegraph @

src/oidc-gen/promptAndSet/clientsecret.c

raw
1 #include "_helper.h"
2 #include "account/account.h"
3 #include "promptAndSet.h"
4 #include "utils/string/stringUtils.h"
5
6 void askOrNeedClientSecret(struct oidc_account* account,
7 const struct arguments* arguments, int optional) {
8 if (readClientSecret(account, arguments)) {
9 return;
10 }
11 ERROR_IF_NO_PROMPT(optional,
12 ERROR_MESSAGE("client secret", OPT_LONG_CLIENTSECRET));
13 char* res = _gen_prompt("Client_secret", account_getClientSecret(account), 1,
14 optional);
15 if (res) {
16 account_setClientSecret(account, res);
17 }
18 }
19
20 int readClientSecret(struct oidc_account* account,
21 const struct arguments* arguments) {
22 if (arguments->client_secret) {
23 account_setClientSecret(account, oidc_strcopy(arguments->client_secret));
24 return 1;
25 }
26 if (prompt_mode() == 0 && strValid(account_getClientSecret(account))) {
27 return 1;
28 }
29 return 0;
30 }
31
32 void askClientSecret(struct oidc_account* account,
33 const struct arguments* arguments) {
34 return askOrNeedClientSecret(account, arguments, 1);
35 }
36
37 void needClientSecret(struct oidc_account* account,
38 const struct arguments* arguments) {
39 return askOrNeedClientSecret(account, arguments, 0);
40 }