Debian Codegraph @

src/oidc-gen/promptAndSet/refreshtoken.c

raw
1 #include "_helper.h"
2 #include "account/account.h"
3 #include "promptAndSet.h"
4 #include "utils/string/stringUtils.h"
5
6 void askOrNeedRefreshToken(struct oidc_account* account,
7 const struct arguments* arguments, int optional) {
8 if (readRefreshToken(account, arguments)) {
9 return;
10 }
11 ERROR_IF_NO_PROMPT(optional,
12 ERROR_MESSAGE("refresh token", OPT_LONG_REFRESHTOKEN));
13 char* res = _gen_prompt("Refresh token", account_getRefreshToken(account), 0,
14 optional);
15 if (res) {
16 account_setRefreshToken(account, res);
17 }
18 }
19
20 int readRefreshToken(struct oidc_account* account,
21 const struct arguments* arguments) {
22 if (arguments->refresh_token) {
23 account_setRefreshToken(account, oidc_strcopy(arguments->refresh_token));
24 return 1;
25 }
26 if (prompt_mode() == 0 && strValid(account_getRefreshToken(account))) {
27 return 1;
28 }
29 return 0;
30 }
31
32 void askRefreshToken(struct oidc_account* account,
33 const struct arguments* arguments) {
34 return askOrNeedRefreshToken(account, arguments, 1);
35 }
36
37 void needRefreshToken(struct oidc_account* account,
38 const struct arguments* arguments) {
39 return askOrNeedRefreshToken(account, arguments, 0);
40 }