From bdc9cff85767395d7ea0df05bc28345233ab7e91 Mon Sep 17 00:00:00 2001 From: Jia Zhai Date: Wed, 22 Jul 2020 19:09:34 +0800 Subject: [PATCH 1/3] add cpp example, rename file oauth to oauth2 --- site2/docs/client-libraries-java.md | 4 +-- .../{security-oauth.md => security-oauth2.md} | 30 ++++++++++++++++--- site2/website/sidebars.json | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) rename site2/docs/{security-oauth.md => security-oauth2.md} (81%) diff --git a/site2/docs/client-libraries-java.md b/site2/docs/client-libraries-java.md index bea1df9228ae0..2c58691b030ee 100644 --- a/site2/docs/client-libraries-java.md +++ b/site2/docs/client-libraries-java.md @@ -795,7 +795,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 @@ -857,7 +857,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 b399deae5ac46..e0e20569e0b50 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 +``` + +### CPP + +Cpp client is similar to java client. user need to provide parameters of issuerUrl, private_key(which is the credentials file path), and audience. + +```c++ +#include + +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 1f4de0cb643ae..841ee4e1d8526 100644 --- a/site2/website/sidebars.json +++ b/site2/website/sidebars.json @@ -88,7 +88,7 @@ "security-jwt", "security-athenz", "security-kerberos", - "security-oauth", + "security-oauth2", "security-authorization", "security-encryption", "security-extending", From 5dd92ddf0d4111e1b68f1992e503f1b19d6de33e Mon Sep 17 00:00:00 2001 From: Jia Zhai Date: Thu, 23 Jul 2020 08:17:40 +0800 Subject: [PATCH 2/3] Update site2/docs/security-oauth2.md Co-authored-by: HuanliMeng <48120384+Huanli-Meng@users.noreply.github.com> --- site2/docs/security-oauth2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site2/docs/security-oauth2.md b/site2/docs/security-oauth2.md index e0e20569e0b50..7a66685868602 100644 --- a/site2/docs/security-oauth2.md +++ b/site2/docs/security-oauth2.md @@ -96,7 +96,7 @@ PulsarClient client = PulsarClient.builder() .build(); ``` -### CPP +### C++ client Cpp client is similar to java client. user need to provide parameters of issuerUrl, private_key(which is the credentials file path), and audience. From 27ac572801bfedd2d0bee2841e8b8002d9a58c2f Mon Sep 17 00:00:00 2001 From: Jia Zhai Date: Thu, 23 Jul 2020 08:17:50 +0800 Subject: [PATCH 3/3] Update site2/docs/security-oauth2.md Co-authored-by: HuanliMeng <48120384+Huanli-Meng@users.noreply.github.com> --- site2/docs/security-oauth2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site2/docs/security-oauth2.md b/site2/docs/security-oauth2.md index 7a66685868602..c847112b57a3d 100644 --- a/site2/docs/security-oauth2.md +++ b/site2/docs/security-oauth2.md @@ -98,7 +98,7 @@ PulsarClient client = PulsarClient.builder() ### C++ client -Cpp client is similar to java client. user need to provide parameters of issuerUrl, private_key(which is the credentials file path), and audience. +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