Discord Login
Learn how to interact with Discord Login
To enable Discord Auth for your project, you need to set up a Discord OAuth application and add the application credentials in the Openfort Dashboard.
Overview#
Setting up Discord logins for your application consists of 3 parts:
- Create and configure a Discord Project and App on the Discord Developer Dashboard.
- Add your Discord API Key and API Secret Key to your Openfort Project.
- Add the login code to your Openfort JS Client App.
Configuration#
Access your Discord account
-
Go to discord.com.
-
Click on
Login
at the top right to log in. -
Once logged in, go to discord.com/developers.
-
callback URL:
https://api.openfort.xyz/iam/v1/oauth/callback/facebook
Create a Discord application
- Click on
New Application
at the top right. - Enter the name of your application and click
Create
. - Click on
OAuth2
underSettings
in the left side panel. - Click
Add Redirect
underRedirects
. - Type or paste your
callback URL
into theRedirects
box. - Click
Save Changes
at the bottom. - Copy your
Client ID
andClient Secret
underClient information
.
Add your Discord credentials into your Supabase project
Signing users in#
To initiate sign in, you can use the initOAuth()
method from the Openfort JavaScript library and provide a redirectTo
URL which points to a callback route.
- Implicit flow: that's all you need to do. The user will be taken to Google's consent screen, and finally redirected to your app with an access and refresh token pair representing their session.
- Pooling flow: for example in Server-Side Auth, you need to redirect the user back to your website.
Behind the scenes, Openfort Auth uses the Google OAuth 2.0 APIs, which are OpenID Connect certified, to perform the authentication.
To initiate sign in, you can use the initOAuth()
method from the Openfort JavaScript library.
- Implicit flow: that's all you need to do. The user will be taken to Google's consent screen, and finally redirected to your app with an access and refresh token pair representing their session.
- Pooling flow: for example in Server-Side Auth, you need to redirect the user back to your website.
_10const response = await openfort.initOAuth(_10 {_10 provider: OAuthProvider.DISCORD,_10 redirectTo: 'https://your-website.com',_10 }_10);
Now you can redirect the user to the initOAuth.url and when the process is done, you will be redirected to the redirectTo url with tokens https://your-website.com?access_token=...&refresh_token=... You can then use those parameters to authenticate the user:
_10openfort.storeCredentials({_10 player: 'undefined',_10 accessToken: access_token,_10 refreshToken: refresh_token,_10 });
Uppon successful authentication, the SDK will return a token that can be used to authenticate the user in your application.