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:48:32 UTC

[pulsar] 01/03: [doc] Add pulsar-client-go oauth2 authentication document (#7648)

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 4c3c9cc09598b58c9351d98d844f093c6be6a2a5
Author: Yong Zhang <zh...@gmail.com>
AuthorDate: Tue Jul 28 19:40:52 2020 +0800

    [doc] Add pulsar-client-go oauth2 authentication document (#7648)
    
    * [doc] Add pulsar-client-go oauth2 authentication document
    ---
    
    *Motivation*
    
    Add pulsar-client-go oauth2 authentication usage document.
    
    * Address comments
    
    (cherry picked from commit 24fa8cfcbe77faec66db66a478182709dad74bd8)
---
 site2/docs/client-libraries-go.md | 19 +++++++++++++++++++
 site2/docs/security-oauth2.md     | 19 +++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/site2/docs/client-libraries-go.md b/site2/docs/client-libraries-go.md
index 90cd346..83f8930 100644
--- a/site2/docs/client-libraries-go.md
+++ b/site2/docs/client-libraries-go.md
@@ -658,3 +658,22 @@ opts := pulsar.ClientOptions{
     Authentication: NewAuthenticationTLS("my-cert.pem", "my-key.pem"),
 }
 ```
+
+## OAuth2 authentication
+
+To use [OAuth2 authentication](security-oauth2.md), you'll need to configure your client to perform the following operations.
+This example shows how to configure OAuth2 authentication.
+
+```go
+oauth := pulsar.NewAuthenticationOAuth2(map[string]string{
+		"type":       "client_credentials",
+		"issuerUrl":  "https://dev-kt-aa9ne.us.auth0.com/oauth/token",
+		"audience":   "https://dev-kt-aa9ne.us.auth0.com/api/v2/",
+		"privateKey": "/path/to/privateKey",
+		"clientId":   "0Xx...Yyxeny",
+	})
+client, err := pulsar.NewClient(pulsar.ClientOptions{
+		URL:              "puslar://my-cluster:6650",
+		Authentication:   oauth,
+})
+```
diff --git a/site2/docs/security-oauth2.md b/site2/docs/security-oauth2.md
index c847112..41b660f 100644
--- a/site2/docs/security-oauth2.md
+++ b/site2/docs/security-oauth2.md
@@ -113,3 +113,22 @@ config.setAuth(pulsar::AuthOauth2::create(params));
 
 pulsar::Client client("pulsar://broker.example.com:6650/", config);
 ```
+
+### Go client
+
+To enable OAuth2 authentication in Go client, you need to configure OAuth2 authentication.
+This example shows how to configure OAuth2 authentication in Go client. 
+
+```go
+oauth := pulsar.NewAuthenticationOAuth2(map[string]string{
+		"type":       "client_credentials",
+		"issuerUrl":  "https://dev-kt-aa9ne.us.auth0.com/oauth/token",
+		"audience":   "https://dev-kt-aa9ne.us.auth0.com/api/v2/",
+		"privateKey": "/path/to/privateKey",
+		"clientId":   "0Xx...Yyxeny",
+	})
+client, err := pulsar.NewClient(pulsar.ClientOptions{
+		URL:              "puslar://my-cluster:6650",
+		Authentication:   oauth,
+})
+```