Skip to content

Commit da1cab5

Browse files
agatavpusher-ci
andauthored
fix README and code examples for the user authentication (#85)
* fix README and code examples for the user authentication * Bump to version 5.1.1 Co-authored-by: Pusher CI <pusher-ci@pusher.com>
1 parent 8c86c48 commit da1cab5

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 5.1.1
4+
5+
- [CHANGED] readme example for user authentication
6+
37
## 5.1.0
48

59
* [ADDED] SendToUser method

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,13 @@ For more information see our [docs](http://pusher.com/docs/authenticating_users)
400400
| Argument | Description |
401401
| :-: | :-: |
402402
| params `[]byte` | The request body sent by the client |
403+
| userData `map[string]interface{}` | The map containing arbitrary user data. It must contain at least an `id` field with the user's id as a string. See below. |
404+
405+
###### Arbitrary User Data
406+
407+
```go
408+
userData := map[string]interface{} { "id": "1234", "twitter": "jamiepatel" }
409+
```
403410

404411
| Return Value | Description |
405412
| :-: | :-: |
@@ -411,7 +418,8 @@ For more information see our [docs](http://pusher.com/docs/authenticating_users)
411418
```go
412419
func pusherUserAuth(res http.ResponseWriter, req *http.Request) {
413420
params, _ := ioutil.ReadAll(req.Body)
414-
response, err := pusherClient.AuthenticateUser(params)
421+
userData := map[string]interface{} { "id": "1234", "twitter": "jamiepatel" }
422+
response, err := pusherClient.AuthenticateUser(params, userData)
415423
if err != nil {
416424
panic(err)
417425
}

client.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var pusherPathRegex = regexp.MustCompile("^/apps/([0-9]+)$")
1717
var maxTriggerableChannels = 100
1818

1919
const (
20-
libraryVersion = "5.1.0"
20+
libraryVersion = "5.1.1"
2121
libraryName = "pusher-http-go"
2222
)
2323

@@ -65,7 +65,6 @@ type Client struct {
6565
ClientFromURL allows client instantiation from a specially-crafted Pusher URL.
6666
6767
c := pusher.ClientFromURL("http://key:secret@api.pusherapp.com/apps/app_id")
68-
6968
*/
7069
func ClientFromURL(serverURL string) (*Client, error) {
7170
url2, err := url.Parse(serverURL)
@@ -104,8 +103,8 @@ func ClientFromURL(serverURL string) (*Client, error) {
104103
ClientFromEnv allows instantiation of a client from an environment variable.
105104
This is particularly relevant if you are using Pusher as a Heroku add-on,
106105
which stores credentials in a `"PUSHER_URL"` environment variable. For example:
107-
client := pusher.ClientFromEnv("PUSHER_URL")
108106
107+
client := pusher.ClientFromEnv("PUSHER_URL")
109108
*/
110109
func ClientFromEnv(key string) (*Client, error) {
111110
url := os.Getenv(key)
@@ -139,7 +138,6 @@ be marshallable into JSON.
139138
140139
data := map[string]string{"hello": "world"}
141140
client.Trigger("greeting_channel", "say_hello", data)
142-
143141
*/
144142
func (c *Client) Trigger(channel string, eventName string, data interface{}) error {
145143
_, err := c.validateChannelsAndTrigger([]string{channel}, eventName, data, TriggerParams{})
@@ -201,6 +199,7 @@ func (c *Client) TriggerWithParams(
201199
/*
202200
TriggerMulti is the same as `client.Trigger`, except one passes in a slice of
203201
`channels` as the first parameter. The maximum length of channels is 100.
202+
204203
client.TriggerMulti([]string{"a_channel", "another_channel"}, "event", data)
205204
*/
206205
func (c *Client) TriggerMulti(channels []string, eventName string, data interface{}) error {
@@ -226,6 +225,7 @@ func (c *Client) TriggerMultiWithParams(
226225
TriggerExclusive triggers an event excluding a recipient whose connection has
227226
the `socket_id` you specify here from receiving the event.
228227
You can read more here: http://pusher.com/docs/duplicates.
228+
229229
client.TriggerExclusive("a_channel", "event", data, "123.12")
230230
231231
Deprecated: use TriggerWithParams instead.
@@ -240,6 +240,7 @@ func (c *Client) TriggerExclusive(channel string, eventName string, data interfa
240240
TriggerMultiExclusive triggers an event to multiple channels excluding a
241241
recipient whose connection has the `socket_id` you specify here from receiving
242242
the event on any of the channels.
243+
243244
client.TriggerMultiExclusive([]string{"a_channel", "another_channel"}, "event", data, "123.12")
244245
245246
Deprecated: use TriggerMultiWithParams instead.
@@ -466,7 +467,6 @@ method the channel name.
466467
users, err := client.GetChannelUsers("presence-chatroom")
467468
468469
//users=> &{List:[{ID:13} {ID:90}]}
469-
470470
*/
471471
func (c *Client) GetChannelUsers(name string) (*Users, error) {
472472
path := fmt.Sprintf("/apps/%s/channels/%s/users", c.AppID, name)
@@ -482,10 +482,10 @@ func (c *Client) GetChannelUsers(name string) (*Users, error) {
482482
}
483483

484484
/*
485-
AuthenticateUser allows you to authenticate a user s subscription to a
486-
private channel. It returns an authentication signature to send back to the client
485+
AuthenticateUser allows you to authenticate a user's connection.
486+
It returns an authentication signature to send back to the client
487487
and authenticate them. In order to identify a user, this method acceps a map containing
488-
arbitrary user data. It must contain at least and id field with the user's id as a string.
488+
arbitrary user data. It must contain at least an id field with the user's id as a string.
489489
490490
For more information see our docs: http://pusher.com/docs/authenticating_users.
491491
@@ -499,7 +499,8 @@ to send back to the client.
499499
func pusherUserAuth(res http.ResponseWriter, req *http.Request) {
500500
501501
params, _ := ioutil.ReadAll(req.Body)
502-
response, err := client.AuthenticateUser(params)
502+
userData := map[string]interface{} { "id": "1234", "twitter": "jamiepatel" }
503+
response, err := client.AuthenticateUser(params, userData)
503504
if err != nil {
504505
panic(err)
505506
}
@@ -680,8 +681,6 @@ occupied or vacated, members being added or removed in presence-channels, or
680681
after client-originated events. For more information see
681682
https://pusher.com/docs/webhooks.
682683
683-
684-
685684
If the webhook is valid, a `*pusher.Webhook* will be returned, and the `err`
686685
value will be nil. If it is invalid, the first return value will be nil, and an
687686
error will be passed.

0 commit comments

Comments
 (0)