-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathpipeline_auth_helper.hpp
More file actions
36 lines (32 loc) · 1.22 KB
/
pipeline_auth_helper.hpp
File metadata and controls
36 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include <azure/core/context.hpp>
#include <azure/core/credentials/credentials.hpp>
#include <azure/core/internal/environment.hpp>
#include <azure/identity.hpp>
#include <memory>
#include <string>
#include <utility>
class PipelineAuthHelper final {
public:
static const std::shared_ptr<Azure::Core::Credentials::TokenCredential> GetSampleCredentials()
{
try
{
// the ENVs are defined only by the pipeline and not by the user thus this will throw when
// trying to get ENVs outside of the pipeline thus will fall back on the default azure
// credential
return std::make_shared<Azure::Identity::AzurePipelinesCredential>(
Azure::Core::_internal::Environment::GetVariable("AZURESUBSCRIPTION_TENANT_ID"),
Azure::Core::_internal::Environment::GetVariable("AZURESUBSCRIPTION_CLIENT_ID"),
Azure::Core::_internal::Environment::GetVariable(
"AZURESUBSCRIPTION_SERVICE_CONNECTION_ID"),
Azure::Core::_internal::Environment::GetVariable("SYSTEM_ACCESSTOKEN"));
}
catch (...)
{
return std::make_shared<Azure::Identity::DefaultAzureCredential>();
};
}
};