-
Notifications
You must be signed in to change notification settings - Fork 157
Add ClientCertificateCredential #3578
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
Show all changes
18 commits
Select commit
Hold shift + click to select a range
26c8e90
Add ClientCertificateCredential
antkmsft 053b19e
Update unit test
antkmsft 6db1902
cspell
antkmsft 3912b2d
Update Readme
antkmsft cb78f22
Cosmetic fixes
antkmsft 70d83a2
Changelog to mention env cred update
antkmsft 4be7076
Fix warning
antkmsft 5aa8a67
cspell
antkmsft cfdc6be
Tell CI to install openssl
antkmsft 15bd7a4
openssl for all Windows
antkmsft f5261b4
update dependency manifest
antkmsft 9c8c26e
Re-phrase changelog
antkmsft 322dabf
Clang warnings
antkmsft fbd1ed2
Clang warning
antkmsft 4357d40
Clang warning - 2
antkmsft 8148bbb
Ubuntu18 warning
antkmsft 08511eb
Update sdk/identity/azure-identity/CHANGELOG.md
antkmsft 0a2ace2
PR feedback
antkmsft 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
96 changes: 96 additions & 0 deletions
96
sdk/identity/azure-identity/inc/azure/identity/client_certificate_credential.hpp
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,96 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| /** | ||
| * @file | ||
| * @brief Client Certificate Credential and options. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "azure/identity/dll_import_export.hpp" | ||
|
|
||
| #include <azure/core/credentials/credentials.hpp> | ||
| #include <azure/core/credentials/token_credential_options.hpp> | ||
| #include <azure/core/url.hpp> | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| namespace Azure { namespace Identity { | ||
| namespace _detail { | ||
| class TokenCredentialImpl; | ||
| } // namespace _detail | ||
|
|
||
| /** | ||
| * @brief Options for client certificate authentication. | ||
| * | ||
| */ | ||
| struct ClientCertificateCredentialOptions final : public Core::Credentials::TokenCredentialOptions | ||
| { | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Client Certificate Credential authenticates with the Azure services using a Tenant ID, | ||
| * Client ID and a client certificate. | ||
| * | ||
| */ | ||
| class ClientCertificateCredential final : public Core::Credentials::TokenCredential { | ||
| private: | ||
| std::unique_ptr<_detail::TokenCredentialImpl> m_tokenCredentialImpl; | ||
| Core::Url m_requestUrl; | ||
| std::string m_requestBody; | ||
| std::string m_tokenHeaderEncoded; | ||
| std::string m_tokenPayloadStaticPart; | ||
| void* m_pkey; | ||
|
|
||
| public: | ||
| /** | ||
| * @brief Constructs a Client Secret Credential. | ||
| * | ||
| * @param tenantId Tenant ID. | ||
| * @param clientId Client ID. | ||
| * @param clientCertificatePath Client certificate path. | ||
| * @param options Options for token retrieval. | ||
| */ | ||
| explicit ClientCertificateCredential( | ||
| std::string const& tenantId, | ||
| std::string const& clientId, | ||
| std::string const& clientCertificatePath, | ||
| Core::Credentials::TokenCredentialOptions const& options | ||
| = Core::Credentials::TokenCredentialOptions()); | ||
|
|
||
| /** | ||
| * @brief Constructs a Client Secret Credential. | ||
| * | ||
| * @param tenantId Tenant ID. | ||
| * @param clientId Client ID. | ||
| * @param clientCertificatePath Client certificate path. | ||
| * @param options Options for token retrieval. | ||
| */ | ||
| explicit ClientCertificateCredential( | ||
| std::string const& tenantId, | ||
| std::string const& clientId, | ||
| std::string const& clientCertificatePath, | ||
| ClientCertificateCredentialOptions const& options); | ||
|
antkmsft marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * @brief Destructs `%ClientCertificateCredential`. | ||
| * | ||
| */ | ||
| ~ClientCertificateCredential() override; | ||
|
|
||
| /** | ||
| * @brief Gets an authentication token. | ||
| * | ||
| * @param tokenRequestContext A context to get the token in. | ||
| * @param context A context to control the request lifetime. | ||
| * | ||
| * @throw Azure::Core::Credentials::AuthenticationException Authentication error occurred. | ||
| */ | ||
| Core::Credentials::AccessToken GetToken( | ||
| Core::Credentials::TokenRequestContext const& tokenRequestContext, | ||
| Core::Context const& context) const override; | ||
| }; | ||
|
|
||
| }} // namespace Azure::Identity | ||
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
42 changes: 42 additions & 0 deletions
42
sdk/identity/azure-identity/samples/client_certificate_credential.cpp
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,42 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include <iostream> | ||
|
|
||
| #include <azure/identity/client_certificate_credential.hpp> | ||
|
|
||
| #include <azure/service/client.hpp> | ||
|
|
||
| // These functions should be getting the real Tenant ID, Client ID, and the Client Certificate to | ||
| // authenticate. | ||
| std::string GetTenantId() { return std::string(); } | ||
| std::string GetClientId() { return std::string(); } | ||
| std::string GetClientCertificatePath() { return std::string(); } | ||
|
|
||
| int main() | ||
| { | ||
| try | ||
| { | ||
| // Step 1: Initialize Client Certificate Credential. | ||
| auto clientCertificateCredential | ||
| = std::make_shared<Azure::Identity::ClientCertificateCredential>( | ||
| GetTenantId(), GetClientId(), GetClientCertificatePath()); | ||
|
|
||
| // Step 2: Pass the credential to an Azure Service Client. | ||
| Azure::Service::Client azureServiceClient("serviceUrl", clientCertificateCredential); | ||
|
|
||
| // Step 3: Start using the Azure Service Client. | ||
| azureServiceClient.DoSomething(Azure::Core::Context::ApplicationContext); | ||
|
|
||
| std::cout << "Success!" << std::endl; | ||
| } | ||
| catch (const Azure::Core::Credentials::AuthenticationException& exception) | ||
| { | ||
| // Step 4: Handle authentication errors, if needed | ||
| // (invalid credential parameters, insufficient permissions). | ||
| std::cout << "Authentication error: " << exception.what() << std::endl; | ||
| return 1; | ||
| } | ||
|
|
||
| return 0; | ||
| } |
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.