You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/activities/development-guides/multiplayer-experience.mdx
+96Lines changed: 96 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,6 +138,8 @@ Activities are surfaced through iframes in the Discord app. The activity website
138
138
139
139
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.
140
140
141
+
### Using the Activity Instance API
142
+
141
143
To enable an activity to "lock down" activity access, we encourage utilizing the `get_activity_instance` API, found at `discord.com/api/applications/<application_id>/activity-instances/<instance_id>'`. The route requires a Bot token of the application. It returns a serialized active activity instance for the given application, if found, otherwise it returns a 404. Here are two example responses:
With this API, the activity's backend can verify that a client is in fact in an instance of that activity before allowing the client to participate in any meaningful gameplay. How an activity implements"session verification" is left to the developer's discretion. The solution can be as granular as gating specific features or as binary as not returning the activity HTML except for valid sessions.
152
154
155
+
###### Validating Proxy Request Headers
156
+
157
+
For apps that want additional security validation, Discord provides an optional proxy authentication system. When your embedded app makes requests through Discord's proxy, each request can include cryptographic headers that prove the request's authenticity.
158
+
159
+
Each proxy-authenticated request is sent with the following headers:
160
+
161
+
- `X-Signature-Ed25519` as a cryptographic signature
162
+
- `X-Signature-Timestamp` as a Unix timestamp
163
+
- `X-Discord-Proxy-Payload` as a base64-encoded payload containing user context
164
+
165
+
If you choose to use proxy authentication, you can validate these headers to ensure requests are legitimate. If the signature fails validation, your app should respond with a `401` error code.
166
+
167
+
<Collapsible title="Validating Proxy Headers" description="Code example for validating proxy authentication headers" icon="code">
168
+
Below are some code examples that show how to validate the headers sent in proxy-authenticated requests.
169
+
170
+
**JavaScript**
171
+
172
+
```js
173
+
const nacl = require("tweetnacl");
174
+
175
+
// Your public key can be found on your application in the Developer Portal
0 commit comments