Lesson 35 - Get Compute Auth Token Working
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <smithy/identity/resolver/AwsIdentityResolverBase.h>
|
||||
#include <smithy/identity/signer/AwsSignerBase.h>
|
||||
|
||||
namespace smithy {
|
||||
template<typename IDENTITY_T>
|
||||
class AuthScheme
|
||||
{
|
||||
public:
|
||||
using IdentityT = IDENTITY_T;
|
||||
|
||||
template<std::size_t N>
|
||||
AuthScheme(char const (&iSchemeId)[N])
|
||||
{
|
||||
memcpy(schemeId, iSchemeId, N);
|
||||
}
|
||||
|
||||
char schemeId[32];
|
||||
|
||||
virtual ~AuthScheme() = default;
|
||||
|
||||
virtual std::shared_ptr<IdentityResolverBase<IdentityT>> identityResolver() = 0;
|
||||
|
||||
virtual std::shared_ptr<AwsSignerBase<IdentityT>> signer() = 0;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <aws/crt/Variant.h>
|
||||
|
||||
#include <aws/core/utils/DateTime.h>
|
||||
#include <aws/core/utils/memory/stl/AWSMap.h>
|
||||
#include <aws/core/endpoint/EndpointParameter.h>
|
||||
|
||||
namespace smithy {
|
||||
/* AuthSchemeOption and AuthSchemeOptionResolver */
|
||||
class AuthSchemeOption
|
||||
{
|
||||
using PropertyBag = Aws::UnorderedMap<Aws::String, Aws::Crt::Variant<Aws::String, bool>>;
|
||||
using EndpointParameters = Aws::Vector<Aws::Endpoint::EndpointParameter>;
|
||||
/* note: AuthSchemeOption is not connected with AuthScheme by type system, only by the String of schemeId, this is in accordance with SRA */
|
||||
public:
|
||||
AuthSchemeOption(const char* id = nullptr): schemeId(id) {}
|
||||
virtual ~AuthSchemeOption() = default;
|
||||
|
||||
const char* schemeId = nullptr;
|
||||
|
||||
PropertyBag virtual identityProperties() const { return PropertyBag{}; };
|
||||
PropertyBag virtual signerProperties() const { return PropertyBag{}; };
|
||||
EndpointParameters virtual endpointParameters() const { return EndpointParameters{}; };
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <smithy/identity/auth/AuthSchemeOption.h>
|
||||
#include <smithy/identity/signer/AwsSignerBase.h>
|
||||
|
||||
#include <aws/crt/Variant.h>
|
||||
#include <aws/core/utils/memory/stl/AWSMap.h>
|
||||
|
||||
namespace smithy {
|
||||
/**
|
||||
* A base interface for code-generated interfaces for passing in the data required for determining the
|
||||
* authentication scheme. By default, this only includes the operation name.
|
||||
*/
|
||||
class DefaultAuthSchemeResolverParameters
|
||||
{
|
||||
public:
|
||||
Aws::String serviceName;
|
||||
Aws::String operation;
|
||||
Aws::Crt::Optional<Aws::String> region;
|
||||
|
||||
Aws::UnorderedMap<Aws::String, Aws::Crt::Variant<Aws::String,
|
||||
bool,
|
||||
Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy,
|
||||
Aws::Auth::AWSSigningAlgorithm > > additionalProperties;
|
||||
|
||||
};
|
||||
|
||||
template<typename ServiceAuthSchemeParametersT = DefaultAuthSchemeResolverParameters>
|
||||
class AuthSchemeResolverBase
|
||||
{
|
||||
public:
|
||||
using ServiceAuthSchemeParameters = ServiceAuthSchemeParametersT;
|
||||
|
||||
virtual ~AuthSchemeResolverBase() = default;
|
||||
// AuthScheme Resolver returns a list of AuthSchemeOptions for some reason, according to the SRA...
|
||||
virtual Aws::Vector<AuthSchemeOption> resolveAuthScheme(const ServiceAuthSchemeParameters& identityProperties) = 0;
|
||||
};
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 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/SigV4AuthSchemeOption.h>
|
||||
|
||||
#include <smithy/identity/resolver/built-in/DefaultAwsCredentialIdentityResolver.h>
|
||||
|
||||
#include <smithy/identity/identity/AwsCredentialIdentityBase.h>
|
||||
#include <smithy/identity/signer/built-in/SigV4Signer.h>
|
||||
#include <smithy/identity/auth/built-in/SigV4AuthScheme.h>
|
||||
|
||||
|
||||
namespace smithy {
|
||||
constexpr char SIGV4[] = "aws.auth#sigv4";
|
||||
|
||||
class SigV4AuthScheme : public AuthScheme<AwsCredentialIdentityBase>
|
||||
{
|
||||
public:
|
||||
using AwsCredentialIdentityResolverT = IdentityResolverBase<IdentityT>;
|
||||
using AwsCredentialSignerT = AwsSignerBase<IdentityT>;
|
||||
using SigV4AuthSchemeParameters = DefaultAuthSchemeResolverParameters;
|
||||
|
||||
//This allows to override the identity resolver
|
||||
explicit SigV4AuthScheme(std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver,
|
||||
const Aws::String& serviceName,
|
||||
const Aws::String& region)
|
||||
: AuthScheme(SIGV4),
|
||||
m_identityResolver{identityResolver},
|
||||
m_signer{Aws::MakeShared<AwsSigV4Signer>("SigV4AuthScheme", serviceName, region)}
|
||||
{
|
||||
assert(m_identityResolver);
|
||||
assert(m_signer);
|
||||
}
|
||||
|
||||
//delegate constructor
|
||||
explicit SigV4AuthScheme(const Aws::String& serviceName,
|
||||
const Aws::String& region)
|
||||
: SigV4AuthScheme(Aws::MakeShared<DefaultAwsCredentialIdentityResolver>("SigV4AuthScheme"),
|
||||
serviceName,
|
||||
region)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~SigV4AuthScheme() = 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;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <smithy/Smithy_EXPORTS.h>
|
||||
#include <smithy/identity/auth/AuthSchemeOption.h>
|
||||
|
||||
namespace smithy {
|
||||
struct SigV4AuthSchemeOption
|
||||
{
|
||||
static SMITHY_API AuthSchemeOption sigV4AuthSchemeOption;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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/SigV4AuthSchemeOption.h>
|
||||
|
||||
|
||||
namespace smithy {
|
||||
template<typename ServiceAuthSchemeParametersT = DefaultAuthSchemeResolverParameters>
|
||||
class SigV4AuthSchemeResolver : public AuthSchemeResolverBase<ServiceAuthSchemeParametersT>
|
||||
{
|
||||
public:
|
||||
using ServiceAuthSchemeParameters = ServiceAuthSchemeParametersT;
|
||||
virtual ~SigV4AuthSchemeResolver() = default;
|
||||
|
||||
Aws::Vector<AuthSchemeOption> resolveAuthScheme(const ServiceAuthSchemeParameters& identityProperties) override
|
||||
{
|
||||
AWS_UNREFERENCED_PARAM(identityProperties);
|
||||
return {SigV4AuthSchemeOption::sigV4AuthSchemeOption};
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 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/SigV4aAuthSchemeOption.h>
|
||||
|
||||
#include <smithy/identity/resolver/built-in/DefaultAwsCredentialIdentityResolver.h>
|
||||
|
||||
#include <smithy/identity/identity/AwsCredentialIdentityBase.h>
|
||||
#include <smithy/identity/signer/built-in/SigV4aSigner.h>
|
||||
|
||||
|
||||
namespace smithy {
|
||||
constexpr char SIGV4A[] = "aws.auth#sigv4a";
|
||||
|
||||
|
||||
class SigV4aAuthScheme : public AuthScheme<AwsCredentialIdentityBase>
|
||||
{
|
||||
public:
|
||||
using AwsCredentialIdentityResolverT = IdentityResolverBase<IdentityT>;
|
||||
using AwsCredentialSignerT = AwsSignerBase<IdentityT>;
|
||||
using SigV4aAuthSchemeParameters = DefaultAuthSchemeResolverParameters;
|
||||
|
||||
//This allows to override the identity resolver
|
||||
explicit SigV4aAuthScheme(std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver,
|
||||
const Aws::String& serviceName,
|
||||
const Aws::String& region)
|
||||
: AuthScheme(SIGV4A),
|
||||
m_identityResolver{identityResolver},
|
||||
m_signer{Aws::MakeShared<AwsSigV4aSigner>("SigV4aAuthScheme", serviceName, region)}
|
||||
{
|
||||
assert(m_identityResolver);
|
||||
assert(m_signer);
|
||||
}
|
||||
|
||||
explicit SigV4aAuthScheme(const Aws::String& serviceName,
|
||||
const Aws::String& region)
|
||||
: SigV4aAuthScheme(Aws::MakeShared<DefaultAwsCredentialIdentityResolver>("SigV4aAuthScheme"), serviceName, region)
|
||||
{
|
||||
assert(m_identityResolver);
|
||||
|
||||
assert(m_signer);
|
||||
}
|
||||
|
||||
virtual ~SigV4aAuthScheme() = 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;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <smithy/Smithy_EXPORTS.h>
|
||||
#include <smithy/identity/auth/AuthSchemeOption.h>
|
||||
|
||||
namespace smithy {
|
||||
struct SigV4aAuthSchemeOption
|
||||
{
|
||||
static SMITHY_API AuthSchemeOption sigV4aAuthSchemeOption;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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/SigV4aAuthSchemeOption.h>
|
||||
|
||||
|
||||
namespace smithy {
|
||||
template<typename ServiceAuthSchemeParametersT = DefaultAuthSchemeResolverParameters>
|
||||
class SigV4aAuthSchemeResolver : public AuthSchemeResolverBase<ServiceAuthSchemeParametersT>
|
||||
{
|
||||
public:
|
||||
using ServiceAuthSchemeParameters = ServiceAuthSchemeParametersT;
|
||||
virtual ~SigV4aAuthSchemeResolver() = default;
|
||||
|
||||
Aws::Vector<AuthSchemeOption> resolveAuthScheme(const ServiceAuthSchemeParameters& identityProperties) override
|
||||
{
|
||||
AWS_UNREFERENCED_PARAM(identityProperties);
|
||||
return {SigV4aAuthSchemeOption::sigV4aAuthSchemeOption};
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user