Skip to content

Commit 80268d1

Browse files
committed
chore: remove implicit grant guide and add disclaimer
issue: https://github.com/discordjs/guide/issues/1370/ pr: discordjs/guide#1543
1 parent 09dfaff commit 80268d1

File tree

1 file changed

+4
-50
lines changed

1 file changed

+4
-50
lines changed

apps/guide/content/docs/legacy/oauth2/oauth2.mdx

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -75,56 +75,10 @@ The `identify` scope will allow your application to get basic user information f
7575

7676
### Implicit grant flow
7777

78-
You have your website, and you have a URL. Now you need to use those two things to get an access token. For basic applications like [SPAs](https://en.wikipedia.org/wiki/Single-page_application), getting an access token directly is enough. You can do so by changing the `response_type` in the URL to `token`. However, this means you will not get a refresh token, which means the user will have to explicitly re-authorize when this access token has expired.
79-
80-
After you change the `response_type`, you can test the URL right away. Visiting it in your browser, you will be directed to a page that looks like this:
81-
82-
![Authorization Page](./images/authorize-app-page.png)
83-
84-
You can see that by clicking `Authorize`, you allow the application to access your username and avatar. Once you click through, it will redirect you to your redirect URL with a [fragment identifier](https://en.wikipedia.org/wiki/Fragment_identifier) appended to it. You now have an access token and can make requests to Discord's API to get information on the user.
85-
86-
Modify `index.html` to add your OAuth2 URL and to take advantage of the access token if it exists. Even though [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) is for working with query strings, it can work here because the structure of the fragment follows that of a query string after removing the leading "#".
87-
88-
```html title="index.html" lineNumbers=11
89-
<div id="info">Hoi!</div>
90-
<a id="login" style="display: none;" href="your-oauth2-URL-here">Identify Yourself</a>
91-
<script>
92-
window.onload = () => {
93-
const fragment = new URLSearchParams(window.location.hash.slice(1));
94-
const [accessToken, tokenType] = [fragment.get('access_token'), fragment.get('token_type')];
95-
96-
if (!accessToken) {
97-
return (document.getElementById('login').style.display = 'block');
98-
}
99-
100-
fetch('https://discord.com/api/users/@me', {
101-
headers: {
102-
authorization: `${tokenType} ${accessToken}`,
103-
},
104-
})
105-
.then((result) => result.json())
106-
.then((response) => {
107-
const { username, discriminator } = response;
108-
document.getElementById('info').innerText += ` ${username}#${discriminator}`;
109-
})
110-
.catch(console.error);
111-
};
112-
</script>
113-
```
114-
115-
Here you grab the access token and type from the URL if it's there and use it to get info on the user, which is then used to greet them. The response you get from the [`/api/users/@me` endpoint](https://discord.com/developers/docs/resources/user#get-current-user) is a [user object](https://discord.com/developers/docs/resources/user#user-object) and should look something like this:
116-
117-
```json
118-
{
119-
"id": "123456789012345678",
120-
"username": "User",
121-
"discriminator": "0001",
122-
"avatar": "1cc0a3b14aec3499632225c708451d67",
123-
...
124-
}
125-
```
126-
127-
In the following sections, we'll go over various details of Discord and OAuth2.
78+
<Callout type="error">
79+
Implicit grant flow, as previously covered in this section, is vulnerable to token leakage and replay attacks. Please
80+
use the **authorization grant** flow instead. The [Oauth2 RFC](https://datatracker.ietf.org/doc/html/rfc9700).
81+
</Callout>
12882

12983
## More details
13084

0 commit comments

Comments
 (0)