-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bearer token placeholder * test placeholder * more placeholder changes * fixes * fixes wip * fixes * make tests functional * make test provider the first in chain for test * cleanup * run clang formatter llvm * remove redundant headers * fix scheme id name * fixes * address comments
- Loading branch information
Showing
9 changed files
with
371 additions
and
23 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/aws-cpp-sdk-core/include/smithy/identity/auth/built-in/BearerTokenAuthScheme.h
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,59 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
#pragma once | ||
|
||
#include <smithy/identity/auth/AuthScheme.h> | ||
#include <smithy/identity/auth/built-in/BearerTokenAuthSchemeOption.h> | ||
#include <smithy/identity/identity/AwsBearerTokenIdentityBase.h> | ||
#include <smithy/identity/resolver/AwsBearerTokenIdentityResolver.h> | ||
#include <smithy/identity/signer/built-in/BearerTokenSigner.h> | ||
namespace smithy | ||
{ | ||
class BearerTokenAuthScheme : public AuthScheme<AwsBearerTokenIdentityBase> | ||
{ | ||
public: | ||
using AwsCredentialIdentityResolverT = IdentityResolverBase<IdentityT>; | ||
using AwsCredentialSignerT = AwsSignerBase<IdentityT>; | ||
using BearerTokenAuthSchemeParameters = DefaultAuthSchemeResolverParameters; | ||
|
||
// This allows to override the identity resolver | ||
explicit BearerTokenAuthScheme( | ||
std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver, | ||
const Aws::String &serviceName, const Aws::String ®ion) | ||
: AuthScheme("smithy.api#HTTPBearerAuth"), | ||
m_identityResolver{identityResolver}, | ||
m_signer{Aws::MakeShared<smithy::BearerTokenSigner>( | ||
"BearerTokenAuthScheme", serviceName, region)} | ||
{ | ||
assert(m_identityResolver); | ||
assert(m_signer); | ||
} | ||
|
||
explicit BearerTokenAuthScheme(const Aws::String &serviceName, | ||
const Aws::String ®ion) | ||
: BearerTokenAuthScheme( | ||
Aws::MakeShared<DefaultAwsBearerTokenIdentityResolver>( | ||
"BearerTokenAuthScheme"), | ||
serviceName, region) | ||
{ | ||
assert(m_identityResolver); | ||
|
||
assert(m_signer); | ||
} | ||
|
||
virtual ~BearerTokenAuthScheme() = default; | ||
|
||
std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver() override | ||
{ | ||
return m_identityResolver; | ||
} | ||
|
||
std::shared_ptr<AwsCredentialSignerT> signer() override { return m_signer; } | ||
|
||
protected: | ||
std::shared_ptr<AwsCredentialIdentityResolverT> m_identityResolver; | ||
std::shared_ptr<AwsCredentialSignerT> m_signer; | ||
}; | ||
} // namespace smithy |
17 changes: 17 additions & 0 deletions
17
src/aws-cpp-sdk-core/include/smithy/identity/auth/built-in/BearerTokenAuthSchemeOption.h
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,17 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
#pragma once | ||
|
||
#include <smithy/identity/auth/AuthSchemeOption.h> | ||
namespace smithy | ||
{ | ||
struct BearerTokenAuthSchemeOption | ||
{ | ||
static AuthSchemeOption bearerTokenAuthSchemeOption; | ||
}; | ||
|
||
AuthSchemeOption BearerTokenAuthSchemeOption::bearerTokenAuthSchemeOption = | ||
AuthSchemeOption("smithy.api#HTTPBearerAuth"); | ||
} // namespace smithy |
28 changes: 28 additions & 0 deletions
28
src/aws-cpp-sdk-core/include/smithy/identity/auth/built-in/BearerTokenAuthSchemeResolver.h
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,28 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
#pragma once | ||
|
||
#include <smithy/identity/auth/AuthSchemeResolverBase.h> | ||
#include <smithy/identity/auth/built-in/BearerTokenAuthSchemeOption.h> | ||
|
||
namespace smithy | ||
{ | ||
template <typename ServiceAuthSchemeParametersT = | ||
DefaultAuthSchemeResolverParameters> | ||
class BearerTokenAuthSchemeResolver | ||
: public AuthSchemeResolverBase<ServiceAuthSchemeParametersT> | ||
{ | ||
public: | ||
using ServiceAuthSchemeParameters = ServiceAuthSchemeParametersT; | ||
virtual ~BearerTokenAuthSchemeResolver() = default; | ||
|
||
Aws::Vector<AuthSchemeOption> resolveAuthScheme( | ||
const ServiceAuthSchemeParameters &identityProperties) override | ||
{ | ||
AWS_UNREFERENCED_PARAM(identityProperties); | ||
return {BearerTokenAuthSchemeOption::bearerTokenAuthSchemeOption}; | ||
} | ||
}; | ||
} // namespace smithy |
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
68 changes: 68 additions & 0 deletions
68
src/aws-cpp-sdk-core/include/smithy/identity/signer/built-in/BearerTokenSigner.h
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,68 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <smithy/identity/identity/AwsBearerTokenIdentityBase.h> | ||
#include <smithy/identity/signer/AwsSignerBase.h> | ||
|
||
#include <aws/core/auth/signer/AWSAuthSignerHelper.h> | ||
#include <aws/core/http/HttpRequest.h> | ||
#include <aws/crt/http/HttpConnection.h> | ||
#include <aws/crt/http/HttpRequestResponse.h> | ||
|
||
namespace smithy | ||
{ | ||
static const char AUTHORIZATION_HEADER[] = "authorization"; | ||
|
||
class BearerTokenSigner : public AwsSignerBase<AwsBearerTokenIdentityBase> | ||
{ | ||
|
||
public: | ||
static const char LOGGING_TAG[]; | ||
|
||
using BearerTokenAuthSchemeParameters = | ||
smithy::DefaultAuthSchemeResolverParameters; | ||
explicit BearerTokenSigner(const Aws::String &serviceName, | ||
const Aws::String ®ion) | ||
: m_serviceName(serviceName), m_region(region) | ||
{ | ||
} | ||
|
||
SigningFutureOutcome | ||
sign(std::shared_ptr<HttpRequest> httpRequest, | ||
const smithy::AwsBearerTokenIdentityBase &identity, | ||
SigningProperties properties) override | ||
{ | ||
AWS_UNREFERENCED_PARAM(properties); | ||
|
||
if (Aws::Http::Scheme::HTTPS != httpRequest->GetUri().GetScheme()) | ||
{ | ||
// Clients MUST always use TLS (https) or equivalent transport | ||
// security when making requests with bearer tokens. | ||
// https://datatracker.ietf.org/doc/html/rfc6750 | ||
AWS_LOGSTREAM_ERROR( | ||
LOGGING_TAG, | ||
"HTTPS scheme must be used with a bearer token authorization"); | ||
return SigningError( | ||
Aws::Client::CoreErrors::INVALID_PARAMETER_VALUE, "", | ||
"Failed to sign the request with bearer", false); | ||
} | ||
|
||
httpRequest->SetHeaderValue(AUTHORIZATION_HEADER, | ||
"Bearer " + identity.token()); | ||
|
||
return SigningFutureOutcome(std::move(httpRequest)); | ||
} | ||
|
||
virtual ~BearerTokenSigner(){}; | ||
|
||
protected: | ||
Aws::String m_serviceName; | ||
Aws::String m_region; | ||
}; | ||
|
||
const char BearerTokenSigner::LOGGING_TAG[] = "BearerTokenSigner"; | ||
} // namespace smithy |
Oops, something went wrong.