Debian Codegraph @

crt/aws-c-auth/include/aws/auth/private/login_token_utils.h

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5 #ifndef AWS_AUTH_TOKEN_PRIVATE_H
6 #define AWS_AUTH_TOKEN_PRIVATE_H
7
8 #include <aws/auth/auth.h>
9 #include <aws/common/date_time.h>
10
11 /*
12 * A login token provided by the the aws login command in the aws cli that is stored to disk. This token has valid sigv4
13 * credentials alongside additional fields that can be used to refresh the credentials when the expire. owns a pointer
14 * to serialized_token that all byte cursors point to. an owned token needs to be destroyed with aws_login_token_destroy
15 * when leaving scope.
16 */
17 struct aws_login_token;
18
19 /*
20 * A refresh response retuned by the aws sign in service when the operation CreateOAuth2Token is called successfully.
21 * This response will contain valid AWS sigv4 credentials alongside a refresh token that can be used in further calls
22 * to the service to refresh the credentials again. Owns a pointer to serialized_token that all byte cursors point to.
23 * an owned token needs to be destroyed with aws_login_token_destroy when leaving scope.
24 */
25 struct aws_login_refresh_response;
26
27 AWS_EXTERN_C_BEGIN
28
29 /*
30 * Creates a login token file from a cached file.
31 */
32 AWS_AUTH_API
33 struct aws_login_token *aws_login_token_new_from_file(struct aws_allocator *allocator, struct aws_byte_buf *file_path);
34
35 /*
36 * Getter for account Id.
37 */
38 AWS_AUTH_API
39 struct aws_byte_cursor aws_login_token_get_account_id(struct aws_login_token *token);
40
41 /*
42 * Setter for access key id.
43 */
44 AWS_AUTH_API
45 void aws_login_token_set_access_key_id(struct aws_login_token *token, struct aws_byte_cursor value);
46
47 /*
48 * Setter for secret access key.
49 */
50 AWS_AUTH_API
51 void aws_login_token_set_secret_access_key(struct aws_login_token *token, struct aws_byte_cursor value);
52
53 /*
54 * Setter for session token.
55 */
56 AWS_AUTH_API
57 void aws_login_token_set_session_token(struct aws_login_token *token, struct aws_byte_cursor value);
58
59 /*
60 * Setter for expires at.
61 */
62 AWS_AUTH_API
63 void aws_login_token_set_expires_at(struct aws_login_token *token, struct aws_date_time value);
64
65 /*
66 * Setter for refresh token
67 */
68 AWS_AUTH_API
69 void aws_login_token_set_refresh_token(struct aws_login_token *token, struct aws_byte_cursor value);
70
71 /*
72 * Creates a login token from a byte cursor to json document.
73 */
74 AWS_AUTH_API
75 struct aws_login_token *aws_login_token_new_from_json_document(
76 struct aws_allocator *allocator,
77 struct aws_byte_cursor payload_cursor);
78
79 /*
80 * Writes a login token to a filepath.
81 */
82 AWS_AUTH_API
83 int aws_login_token_write_token_file(
84 const struct aws_login_token *token,
85 struct aws_allocator *allocator,
86 const struct aws_byte_buf *file_path);
87
88 /*
89 * Constructs a DPoP (Demonstrating Proof of Possession) header. This is sent as a header to the sign in service to
90 * authenticate the refresh token that we send.
91 */
92 AWS_AUTH_API
93 int aws_login_token_get_dpop_header(
94 struct aws_allocator *allocator,
95 const struct aws_login_token *token,
96 struct aws_byte_cursor host,
97 struct aws_byte_buf *header_value);
98
99 /*
100 * Constructs a path to a login cached credential i.e.
101 *
102 * ~/.aws/login/cache/${SHA_256_OF_LOGIN_SESSION}.json
103 */
104 AWS_AUTH_API
105 int aws_login_token_construct_token_path(
106 struct aws_allocator *allocator,
107 const struct aws_string *input,
108 const struct aws_string *directory_override,
109 struct aws_byte_buf *login_token_path_buf);
110
111 /*
112 * Constructs the payload body that we are sending to the sign in service.
113 */
114 AWS_AUTH_API
115 int aws_login_token_get_body(
116 struct aws_allocator *allocator,
117 const struct aws_login_token *token,
118 struct aws_byte_buf *body_buf);
119
120 /*
121 * Destroys a login token.
122 */
123 AWS_AUTH_API
124 struct aws_login_token *aws_login_token_destroy(struct aws_login_token *token);
125
126 /*
127 * Creates a refresh token from a byte cursor to json document.
128 */
129 AWS_AUTH_API
130 struct aws_login_refresh_response *aws_login_refresh_new_from_json_document(
131 struct aws_allocator *allocator,
132 struct aws_byte_cursor payload_cursor);
133
134 /*
135 * Getter for access key id.
136 */
137 AWS_AUTH_API
138 struct aws_byte_cursor aws_login_refresh_get_access_key_id(struct aws_login_refresh_response *token);
139
140 /*
141 * Getter for secret access key id.
142 */
143 AWS_AUTH_API
144 struct aws_byte_cursor aws_login_refresh_get_secret_access_key(struct aws_login_refresh_response *token);
145
146 /*
147 * Getter for session token.
148 */
149 AWS_AUTH_API
150 struct aws_byte_cursor aws_login_refresh_get_session_token(struct aws_login_refresh_response *token);
151
152 /*
153 * Getter for expires at.
154 */
155 AWS_AUTH_API
156 struct aws_date_time aws_login_refresh_get_expires_at(struct aws_login_refresh_response *token);
157
158 /*
159 * Getter for refresh token.
160 */
161 AWS_AUTH_API
162 struct aws_byte_cursor aws_login_refresh_get_refresh_token(struct aws_login_refresh_response *token);
163
164 /*
165 * Destroys a refresh response.
166 */
167 AWS_AUTH_API
168 struct aws_login_refresh_response *aws_login_refresh_destroy(struct aws_login_refresh_response *token);
169
170 AWS_EXTERN_C_END
171
172 #endif // AWS_AUTH_TOKEN_PRIVATE_H