Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ namespace Azure { namespace Core { namespace Credentials {
*
*/
DateTime ExpiresOn;

/**
* @brief Token type used in the Authorization header. Empty means "Bearer".
*
*/
std::string TokenType;
};
Comment on lines +40 to 45

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ void ApplyBearerToken(
Azure::Core::Http::Request& request,
Azure::Core::Credentials::AccessToken const& token)
{
request.SetHeader("authorization", "Bearer " + token.Token);
request.SetHeader(
"authorization", (token.TokenType.empty() ? "Bearer" : token.TokenType) + " " + token.Token);
}
Comment on lines +83 to 85
} // namespace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,39 @@ TEST(BearerTokenAuthenticationPolicy, InitialGet)
}
}

TEST(BearerTokenAuthenticationPolicy, InitialGetUsesTokenType)
{
using namespace std::chrono_literals;
auto accessToken = std::make_shared<AccessToken>();

std::vector<std::unique_ptr<HttpPolicy>> policies;

TokenRequestContext tokenRequestContext;
tokenRequestContext.Scopes = {"https://microsoft.com/.default"};

policies.emplace_back(std::make_unique<BearerTokenAuthenticationPolicy>(
std::make_shared<TestTokenCredential>(accessToken), tokenRequestContext));

policies.emplace_back(std::make_unique<TestTransportPolicy>());

HttpPipeline pipeline(policies);

{
Request request(HttpMethod::Get, Url("https://www.azure.com"));

*accessToken = {"ACCESSTOKEN1", std::chrono::system_clock::now() + 1h, "PoP"};

pipeline.Send(request, Context());

{
auto const headers = request.GetHeaders();
auto const authHeader = headers.find("authorization");
EXPECT_NE(authHeader, headers.end());
EXPECT_EQ(authHeader->second, "PoP ACCESSTOKEN1");
}
}
}

TEST(BearerTokenAuthenticationPolicy, ReuseWhileValid)
{
using namespace std::chrono_literals;
Expand Down
Loading