Skip to content

Commit 132c478

Browse files
committed
Add docs for activity instance validation
1 parent e5cd463 commit 132c478

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

docs/activities/Development_Guides.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ These guides include suggested development practices, SDK commands, and user flo
8787
<Card title="Render Avatars and Names" link="#DOCS_ACTIVITIES_DEVELOPMENT_GUIDES/render-avatars-and-names">
8888
Retrieve and render the usernames and avatars of users connected to your application.
8989
</Card>
90+
<Card title="Preventing Unwanted Activity Sessions" link="#DOCS_ACTIVITIES_DEVELOPMENT_GUIDES/preventing-unwanted-activity-sessions">
91+
Validating activity sessions are via a Discord client before adding them to an instance's session.
92+
</Card>
9093
</Container>
9194

9295
## Assets & Metadata
@@ -828,6 +831,29 @@ This example is being done entirely on the client, however, a more common patter
828831
829832
---
830833
834+
### Preventing unwanted activity sessions
835+
836+
Activities are surfaced through iframes in the Discord app. The activity website itself is publicly reachable at `<application_id>.discordsays.com`. Activities will expect to be able to communicate with Discord's web or mobile client via the Discord SDK's RPC protocol. If a user loads the activity's website in a normal browser, the Discord RPC server will not be present, and the activity will likely fail in some way.
837+
838+
It is theoretically possible for a malicious client to mock Discord's RPC protocol or load one activity website when launching another. Because the activity is loaded inside Discord, the RPC protocol is active, and the activity is none the wiser.
839+
840+
To enable an activity to "lock down" activity access, we encourage utilizing the `activity instances` API, found at `discord.com/api/applications/<application_id>/instances/<channel_id>`. The route requires a Bot token of the application. It returns a list of active activity instances for the given application in the given channel (at the moment, the list will always either be of length 0 or length 1, as we do not allow multiple instances of the same activity). Here are two example responses:
841+
842+
```javascript
843+
curl https://discord.com/api/applications/987654321987654321/instances/987654321987654321 -H 'Authorization: Bot <bot token>'
844+
{"instances": []}
845+
846+
curl https://discord.com/api/applications/987654321987654321/instances/987654321987654321 -H 'Authorization: Bot <bot token>'
847+
{"instances": [{"application_id": "987654321987654321", "channel_id": "987654321987654321", "users": ["987654321987654321"], "instance_id": "abcdabcd-1234-5678-9012-123456781234"}]}
848+
```
849+
850+
With this API, the activity's backend can verify that a client is in fact in an instance of that activity, in a specific channel, before allowing the client to participate in any meaningful gameplay. How an activity implement's "session verification" is up to them. The solution can be as granular as gating specific features or as binary as not returning the activity HTML except for valid sessions.
851+
852+
In the below flow diagram, we show how server can deliver the activity website, only for valid users in a valid activity session
853+
![application-test-mode-prod](activities/activity-instance-validation.jpg)
854+
855+
---
856+
831857
### Setting Up Activity Metadata
832858
833859
The Activity Shelf is where users can see what Activities can be played. It has various metadata and art assets that can be configured.
Loading

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy