Skip to content

Commit a43dbed

Browse files
committed
Add authorization section; fixes rmosolgo#2044
1 parent 3aaaf5a commit a43dbed

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

guides/subscriptions/ably_implementation.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ Read more here: ["Using CORS"](https://www.html5rocks.com/en/tutorials/cors/).
158158
Your server needs to receive webhooks from Ably when clients disconnect. This keeps your local subscription database in sync with Ably.
159159

160160
### Server
161+
161162
*Note: if you're setting up in a development environment you should follow the [Developing with webhooks](#Developing-with-webhooks) section first*
162163

163164
Mount the Rack app for handling webhooks from Ably. For example, on Rails:
@@ -176,6 +177,7 @@ end
176177
```
177178

178179
### Ably
180+
179181
1. Go to the Ably dashboard
180182
2. Click on your application.
181183
3. Select the "Reactor" tab
@@ -187,6 +189,23 @@ end
187189
9. Under "Sign with key" select the API Key prefix that matches the prefix of the ABLY_API_KEY you provided.
188190
10. Click "Create"
189191

192+
## Authorization
193+
194+
You can use Ably's [token authentication](https://www.ably.io/documentation/realtime/authentication#token-authentication) by implementing an endpoint in your app, for example:
195+
196+
```ruby
197+
class AblyController < ActionController::Base
198+
def auth
199+
render status: 201, json: ably_rest_client.auth.create_token_request(
200+
capability: { '*' => ['presence', 'subscribe'] },
201+
client_id: 'graphql-subscriber',
202+
)
203+
end
204+
end
205+
```
206+
207+
[Ably's tutorial](https://www.ably.io/tutorials/webhook-chuck-norris#tutorial-step-4) also demonstrates some of the setup for this.
208+
190209
## Serializing Context
191210

192211
Since subscription state is stored in the database, then reloaded for pushing updates, you have to serialize and reload your query `context`.

0 commit comments

Comments
 (0)