|
| 1 | +// Copyright 2022 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_SUBJECT_TOKEN_H |
| 16 | +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_SUBJECT_TOKEN_H |
| 17 | + |
| 18 | +#include "google/cloud/version.h" |
| 19 | +#include <chrono> |
| 20 | +#include <iosfwd> |
| 21 | +#include <string> |
| 22 | + |
| 23 | +namespace google { |
| 24 | +namespace cloud { |
| 25 | +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN |
| 26 | +namespace internal { |
| 27 | + |
| 28 | +/** |
| 29 | + * A slightly more type-safe representation for subject tokens. |
| 30 | + * |
| 31 | + * External accounts credentials use [OAuth 2.0 Token Exchange][RFC 8693] to |
| 32 | + * convert a "subject token" into an "access token". The latter is used (as one |
| 33 | + * would expect) to access GCP services. Tokens are just strings. It is too easy |
| 34 | + * to confuse their roles. A struct to wrap them provides enough type |
| 35 | + * annotations to avoid most mistakes. |
| 36 | + * |
| 37 | + * [RFC 8693]: https://www.rfc-editor.org/rfc/rfc8693.html |
| 38 | + */ |
| 39 | +struct SubjectToken { |
| 40 | + std::string token; |
| 41 | +}; |
| 42 | + |
| 43 | +std::ostream& operator<<(std::ostream& os, SubjectToken const& rhs); |
| 44 | + |
| 45 | +bool operator==(SubjectToken const& lhs, SubjectToken const& rhs); |
| 46 | + |
| 47 | +inline bool operator!=(SubjectToken const& lhs, SubjectToken const& rhs) { |
| 48 | + return !(lhs == rhs); |
| 49 | +} |
| 50 | + |
| 51 | +} // namespace internal |
| 52 | +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END |
| 53 | +} // namespace cloud |
| 54 | +} // namespace google |
| 55 | + |
| 56 | +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_SUBJECT_TOKEN_H |
0 commit comments