-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oauth2): new library to create oauth2 tokens (#12064)
- Loading branch information
Showing
15 changed files
with
420 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
package(default_visibility = ["//visibility:private"]) | ||
|
||
licenses(["notice"]) # Apache 2.0 | ||
|
||
load(":google_cloud_cpp_oauth2_unit_tests.bzl", "google_cloud_cpp_oauth2_unit_tests") | ||
load(":google_cloud_cpp_oauth2.bzl", "google_cloud_cpp_oauth2_hdrs", "google_cloud_cpp_oauth2_srcs") | ||
|
||
cc_library( | ||
name = "google_cloud_cpp_oauth2", | ||
srcs = google_cloud_cpp_oauth2_srcs, | ||
hdrs = google_cloud_cpp_oauth2_hdrs, | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"//:common", | ||
"//google/cloud:google_cloud_cpp_rest_internal", | ||
], | ||
) | ||
|
||
[cc_test( | ||
name = test.replace("/", "_").replace(".cc", ""), | ||
srcs = [test], | ||
deps = [ | ||
":google_cloud_cpp_oauth2", | ||
"//google/cloud/testing_util:google_cloud_cpp_testing_private", | ||
"//google/cloud/testing_util:google_cloud_cpp_testing_rest_private", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) for test in google_cloud_cpp_oauth2_unit_tests] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# ~~~ | ||
# Copyright 2022 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ~~~ | ||
|
||
include(GoogleCloudCppCommon) | ||
set(DOXYGEN_PROJECT_NAME "OAuth2 Access Token Generation Library") | ||
set(DOXYGEN_PROJECT_BRIEF | ||
"Create OAuth2 Access Tokens for any GCP authentication mechanism") | ||
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION}") | ||
set(DOXYGEN_EXCLUDE_SYMBOLS "internal") | ||
|
||
add_library(google_cloud_cpp_oauth2 # cmake-format: sort | ||
access_token_generator.cc access_token_generator.h) | ||
target_link_libraries( | ||
google_cloud_cpp_oauth2 PUBLIC google-cloud-cpp::rest_internal | ||
google-cloud-cpp::common) | ||
google_cloud_cpp_add_common_options(google_cloud_cpp_oauth2) | ||
target_include_directories( | ||
google_cloud_cpp_oauth2 PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}> | ||
$<INSTALL_INTERFACE:include>) | ||
target_compile_options(google_cloud_cpp_oauth2 | ||
PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG}) | ||
set_target_properties( | ||
google_cloud_cpp_oauth2 | ||
PROPERTIES EXPORT_NAME "google-cloud-cpp::oauth2" | ||
VERSION ${PROJECT_VERSION} | ||
SOVERSION ${PROJECT_VERSION_MAJOR}) | ||
add_library(google-cloud-cpp::oauth2 ALIAS google_cloud_cpp_oauth2) | ||
|
||
# Export the CMake targets to make it easy to create configuration files. | ||
install( | ||
EXPORT google_cloud_cpp_oauth2-targets | ||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_oauth2" | ||
COMPONENT google_cloud_cpp_development) | ||
|
||
# Install the libraries and headers in the locations determined by | ||
# GNUInstallDirs | ||
install( | ||
TARGETS google_cloud_cpp_oauth2 | ||
EXPORT google_cloud_cpp_oauth2-targets | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
COMPONENT google_cloud_cpp_runtime | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
COMPONENT google_cloud_cpp_runtime | ||
NAMELINK_COMPONENT google_cloud_cpp_development | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
COMPONENT google_cloud_cpp_development) | ||
|
||
google_cloud_cpp_install_headers(google_cloud_cpp_oauth2 include/google/cloud) | ||
|
||
google_cloud_cpp_add_pkgconfig( | ||
oauth2 "${DOXYGEN_PROJECT_NAME}" "${DOXYGEN_PROJECT_BRIEF}" | ||
"google_cloud_cpp_rest_internal" "google_cloud_cpp_common") | ||
|
||
# Create and install the CMake configuration files. | ||
include(CMakePackageConfigHelpers) | ||
configure_file("config.cmake.in" "google_cloud_cpp_oauth2-config.cmake" @ONLY) | ||
write_basic_package_version_file( | ||
"google_cloud_cpp_oauth2-config-version.cmake" | ||
VERSION ${PROJECT_VERSION} | ||
COMPATIBILITY ExactVersion) | ||
|
||
install( | ||
FILES | ||
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_oauth2-config.cmake" | ||
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_oauth2-config-version.cmake" | ||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_oauth2" | ||
COMPONENT google_cloud_cpp_development) | ||
|
||
create_bazel_config(google_cloud_cpp_oauth2 YEAR 2023) | ||
|
||
set(google_cloud_cpp_oauth2_unit_tests # cmake-format: sort | ||
access_token_generator_test.cc) | ||
|
||
export_list_to_bazel("google_cloud_cpp_oauth2_unit_tests.bzl" | ||
"google_cloud_cpp_oauth2_unit_tests" YEAR 2023) | ||
|
||
if (NOT BUILD_TESTING) | ||
return() | ||
endif () | ||
|
||
foreach (fname IN LISTS google_cloud_cpp_oauth2_unit_tests) | ||
google_cloud_cpp_add_executable(target "oauth2" "${fname}") | ||
target_link_libraries( | ||
${target} | ||
PRIVATE google-cloud-cpp::oauth2 | ||
google_cloud_cpp_testing | ||
google_cloud_cpp_testing_rest | ||
google-cloud-cpp::common | ||
GTest::gmock_main | ||
GTest::gmock | ||
GTest::gtest) | ||
google_cloud_cpp_add_common_options(${target}) | ||
if (MSVC) | ||
target_compile_options(${target} PRIVATE "/bigobj") | ||
endif () | ||
add_test(NAME ${target} COMMAND ${target}) | ||
endforeach () |
Oops, something went wrong.