-
-
Notifications
You must be signed in to change notification settings - Fork 16
Add an OAuth module foundation with error codes and PKCE #2631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,20 @@ | ||
| sourcemeta_library(NAMESPACE sourcemeta PROJECT core NAME oauth | ||
| PRIVATE_HEADERS error.h profile.h pkce.h bearer.h | ||
| SOURCES oauth_error.cc oauth_pkce.cc oauth_bearer.cc oauth_syntax.h) | ||
|
|
||
| target_link_libraries(sourcemeta_core_oauth | ||
| PUBLIC sourcemeta::core::json) | ||
| target_link_libraries(sourcemeta_core_oauth | ||
| PUBLIC sourcemeta::core::crypto) | ||
| target_link_libraries(sourcemeta_core_oauth | ||
| PUBLIC sourcemeta::core::jose) | ||
| target_link_libraries(sourcemeta_core_oauth | ||
| PUBLIC sourcemeta::core::http) | ||
| target_link_libraries(sourcemeta_core_oauth | ||
| PRIVATE sourcemeta::core::uri) | ||
| target_link_libraries(sourcemeta_core_oauth | ||
| PRIVATE sourcemeta::core::text) | ||
|
|
||
| if(SOURCEMETA_CORE_INSTALL) | ||
| sourcemeta_library_install(NAMESPACE sourcemeta PROJECT core NAME oauth) | ||
| endif() |
This file contains hidden or 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,25 @@ | ||
| #ifndef SOURCEMETA_CORE_OAUTH_H_ | ||
| #define SOURCEMETA_CORE_OAUTH_H_ | ||
|
|
||
| #ifndef SOURCEMETA_CORE_OAUTH_EXPORT | ||
| #include <sourcemeta/core/oauth_export.h> | ||
| #endif | ||
|
|
||
| // NOLINTBEGIN(misc-include-cleaner) | ||
| #include <sourcemeta/core/oauth_bearer.h> | ||
| #include <sourcemeta/core/oauth_error.h> | ||
| #include <sourcemeta/core/oauth_pkce.h> | ||
| #include <sourcemeta/core/oauth_profile.h> | ||
| // NOLINTEND(misc-include-cleaner) | ||
|
|
||
| /// @defgroup oauth OAuth | ||
| /// @brief A standards-driven implementation of the OAuth 2.0 and 2.1 message | ||
| /// family. | ||
| /// | ||
| /// This functionality is included as follows: | ||
| /// | ||
| /// ```cpp | ||
| /// #include <sourcemeta/core/oauth.h> | ||
| /// ``` | ||
|
|
||
| #endif |
This file contains hidden or 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,59 @@ | ||
| #ifndef SOURCEMETA_CORE_OAUTH_BEARER_H_ | ||
| #define SOURCEMETA_CORE_OAUTH_BEARER_H_ | ||
|
|
||
| #ifndef SOURCEMETA_CORE_OAUTH_EXPORT | ||
| #include <sourcemeta/core/oauth_export.h> | ||
| #endif | ||
|
|
||
| #include <optional> // std::optional | ||
| #include <string> // std::string | ||
| #include <string_view> // std::string_view | ||
|
|
||
| namespace sourcemeta::core { | ||
|
|
||
| /// @ingroup oauth | ||
| /// Append a `Bearer` credential (RFC 6750 Section 2.1) for an access token to | ||
| /// the sink, returning whether the token is a well-formed `b64token`. Nothing | ||
| /// is appended when it is not. The sink then holds the access token, which is | ||
| /// secret, so a caller that keeps it should use wiping storage. For example: | ||
| /// | ||
| /// ```cpp | ||
| /// #include <sourcemeta/core/oauth.h> | ||
| /// #include <cassert> | ||
| /// #include <string> | ||
| /// | ||
| /// std::string header; | ||
| /// assert(sourcemeta::core::oauth_bearer_header("mF_9.B5f-4.1JqM", header)); | ||
| /// assert(header == "Bearer mF_9.B5f-4.1JqM"); | ||
| /// ``` | ||
| SOURCEMETA_CORE_OAUTH_EXPORT | ||
| auto oauth_bearer_header(const std::string_view token, std::string &sink) | ||
| -> bool; | ||
|
|
||
| /// @ingroup oauth | ||
| /// Find the value of one authentication parameter within the challenge for a | ||
| /// scheme in a `WWW-Authenticate` header value (RFC 7235 Section 4.1), | ||
| /// returning no value when the scheme or parameter is absent, or the header is | ||
| /// malformed before the parameter is reached. The scheme and parameter name are | ||
| /// matched case insensitively, and a quoted-string value is unescaped (RFC 9110 | ||
| /// Section 5.6.4). The full grammar is parsed so that adjacent challenges and | ||
| /// parameters are told apart correctly. For example: | ||
| /// | ||
| /// ```cpp | ||
| /// #include <sourcemeta/core/oauth.h> | ||
| /// #include <cassert> | ||
| /// | ||
| /// const auto realm{sourcemeta::core::oauth_challenge_parameter( | ||
| /// R"(Bearer realm="example", error="invalid_token")", "Bearer", "realm")}; | ||
| /// assert(realm.has_value()); | ||
| /// assert(realm.value() == "example"); | ||
| /// ``` | ||
| SOURCEMETA_CORE_OAUTH_EXPORT | ||
| auto oauth_challenge_parameter(const std::string_view header, | ||
| const std::string_view scheme, | ||
| const std::string_view name) | ||
| -> std::optional<std::string>; | ||
|
|
||
| } // namespace sourcemeta::core | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.