Skip to content

Commit 3c636df

Browse files
committed
Some cleanup and README updates
1 parent 49813cc commit 3c636df

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,24 @@ Note that both private and presence channels require the user to be authenticate
634634
We recommend that you use an authentication endpoint over including your app's secret in your app in the vast majority of use cases. If you are completely certain that there's no risk to you including your app's secret in your app, for example if your app is just for internal use at your company, then it can make things easier than setting up an authentication endpoint.
635635
636636
637+
### Subscribing with self-provided auth values
638+
639+
It is possible to subscribe to channels that require authentication by providing the auth information at the point of calling `subscribe` or `subscribeToPresenceChannel`. This is done as shown below:
640+
641+
#### Swift
642+
643+
```swift
644+
let pusherAuth = PusherAuth(auth: yourAuthString, channelData: yourOptionalChannelDataString)
645+
let chan = self.pusher.subscribe(channelName, auth: pusherAuth)
646+
```
647+
648+
This PusherAuth object can be initialised with just an auth (String) value if the subscription is to a private channel, or both an `auth (String)` and `channelData (String)` pair of values if the subscription is to a presence channel.
649+
650+
These `auth` and `channelData` values are the values that you received if the json object created by a call to pusher.authenticate(...) in one of our various server libraries.
651+
652+
Keep in mind that in order to generate a valid auth value for a subscription the `socketId` (i.e. the unique identifier for a web socket connection to the Pusher servers) must be present when the auth value is generated. As such, the likely flow for using this is something like this would involve checking for when the connection state becomes `connected` before trying to subscribe to any channels requiring authentication.
653+
654+
637655
## Binding to events
638656

639657
Events can be bound to at 2 levels; globally and per channel. When binding to an event you can choose to save the return value, which is a unique identifier for the event handler that gets created. The only reason to save this is if you're going to want to unbind from the event at a later point in time. There is an example of this below.
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
//
2-
// AuthRequestBuilderProtocol.swift
3-
// PusherSwift
4-
//
5-
// Created by Hamilton Chapman on 29/06/2017.
6-
//
7-
//
8-
91
import Foundation
2+
3+
@objc public protocol AuthRequestBuilderProtocol {
4+
@available(*, deprecated: 4.0.2, message: "use requestFor(socketID: String, channelName: String) -> URLRequest? instead")
5+
@objc optional func requestFor(socketID: String, channel: PusherChannel) -> NSMutableURLRequest?
6+
7+
@objc optional func requestFor(socketID: String, channelName: String) -> URLRequest?
8+
}

0 commit comments

Comments
 (0)