You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by rx...@apache.org on 2020/07/29 10:41:34 UTC
[pulsar] 25/25: [doc] add cpp client document for oauth2
authentication
This is an automated email from the ASF dual-hosted git repository.
rxl pushed a commit to branch branch-2.6
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit a1f56e38849d79e167807b8f205a1cb649d30f79
Author: Jia Zhai <zh...@apache.org>
AuthorDate: Fri Jul 24 08:37:03 2020 +0800
[doc] add cpp client document for oauth2 authentication
Signed-off-by: xiaolong.ran <rx...@apache.org>
---
site2/docs/client-libraries-java.md | 4 +--
.../docs/{security-oauth.md => security-oauth2.md} | 30 +++++++++++++++++++---
site2/website/sidebars.json | 2 +-
3 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/site2/docs/client-libraries-java.md b/site2/docs/client-libraries-java.md
index bbcf8f2..da6fbc0 100644
--- a/site2/docs/client-libraries-java.md
+++ b/site2/docs/client-libraries-java.md
@@ -781,7 +781,7 @@ The following schema formats are currently available for Java:
## Authentication
-Pulsar currently supports three authentication schemes: [TLS](security-tls-authentication.md), [Athenz](security-athenz.md), and [Oauth2](security-oauth.md). You can use the Pulsar Java client with all of them.
+Pulsar currently supports three authentication schemes: [TLS](security-tls-authentication.md), [Athenz](security-athenz.md), and [Oauth2](security-oauth2.md). You can use the Pulsar Java client with all of them.
### TLS Authentication
@@ -843,7 +843,7 @@ PulsarClient client = PulsarClient.builder()
### Oauth2
-The following example shows how to use [Oauth2](security-oauth.md) as an authentication provider for the Pulsar Java client.
+The following example shows how to use [Oauth2](security-oauth2.md) as an authentication provider for the Pulsar Java client.
You can use the factory method to configure authentication for Pulsar Java client.
diff --git a/site2/docs/security-oauth.md b/site2/docs/security-oauth2.md
similarity index 81%
rename from site2/docs/security-oauth.md
rename to site2/docs/security-oauth2.md
index b399dea..c847112 100644
--- a/site2/docs/security-oauth.md
+++ b/site2/docs/security-oauth2.md
@@ -1,5 +1,5 @@
---
-id: security-oauth
+id: security-oauth2
title: Client authentication using OAuth 2.0 access tokens
sidebar_label: Authentication using OAuth 2.0 access tokens
---
@@ -74,10 +74,14 @@ You can use the Oauth2 authentication provider with the following Pulsar clients
You can use the factory method to configure authentication for Pulsar Java client.
```java
+String issuerUrl = "https://dev-kt-aa9ne.us.auth0.com/oauth/token";
+String credentialsUrl = "file:///path/to/KeyFile.json";
+String audience = "https://dev-kt-aa9ne.us.auth0.com/api/v2/";
+
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar://broker.example.com:6650/")
.authentication(
- AuthenticationFactoryOAuth2.clientCredentials(this.issuerUrl, this.credentialsUrl, this.audience))
+ AuthenticationFactoryOAuth2.clientCredentials(issuerUrl, credentialsUrl, audience))
.build();
```
@@ -85,9 +89,27 @@ In addition, you can also use the encoded parameters to configure authentication
```java
Authentication auth = AuthenticationFactory
- .create(AuthenticationOAuth2.class.getName(), "{"type":"client_credentials","privateKey":"...","issuerUrl":"...","audience":"..."}");
+ .create(AuthenticationOAuth2.class.getName(), "{"type":"client_credentials","privateKey":"./key/path/..","issuerUrl":"...","audience":"..."}");
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar://broker.example.com:6650/")
.authentication(auth)
.build();
-```
\ No newline at end of file
+```
+
+### C++ client
+
+The C++ client is similar to the Java client. You need to provide parameters of `issuerUrl`, `private_key` (the credentials file path), and the audience.
+
+```c++
+#include <pulsar/Client.h>
+
+pulsar::ClientConfiguration config;
+std::string params = R"({
+ "issuer_url": "https://dev-kt-aa9ne.us.auth0.com/oauth/token",
+ "private_key": "../../pulsar-broker/src/test/resources/authentication/token/cpp_credentials_file.json",
+ "audience": "https://dev-kt-aa9ne.us.auth0.com/api/v2/"})";
+
+config.setAuth(pulsar::AuthOauth2::create(params));
+
+pulsar::Client client("pulsar://broker.example.com:6650/", config);
+```
diff --git a/site2/website/sidebars.json b/site2/website/sidebars.json
index 42356fd..3c10720 100644
--- a/site2/website/sidebars.json
+++ b/site2/website/sidebars.json
@@ -82,7 +82,7 @@
"security-jwt",
"security-athenz",
"security-kerberos",
- "security-oauth"
+ "security-oauth2",
"security-authorization",
"security-encryption",
"security-extending",