Error with Discord OAuth

Hello. Trying to setup Discor login and get this error:

API Connector error: the Oauth2 API Discord-login is not configured properly - Received error from api The service this service just returned an error (HTTP 401). Please consult their documentation to ensure your call is setup properly. Raw error: {“error”: “invalid_client”} API Connector error: the Oauth2 API Discord-login is not configured properly - Received error from api The service this service just returned an error (HTTP 401). Please consult their documentation to ensure your call is setup properly. Raw error: {“error”: “invalid_client”}

hey @imaguru

I’m not familiar with Discord’s API but just a thought - have you tried removing all parameters from that URL in the Login dialog redirect field?

Based on the documentation it also looks like you shouldn’t have that /api in there

Try it again with https:// discord.com/oauth2/authorize

Ambroise

1 Like

Will add to @ambroisedlg but you shouldn’t have anything else than https://discord.com/oauth2/authorize in authorize endpoint (nothing after for the client id and other stuff… Bubble will add it for you)

2 Likes

In this way I have another error
image

Where or when do you have this error?

Here, when I tried login with discord
image

@imaguru not sure why’re you’re having this error - any reason why you’re not using the Discord Auth plugin though, instead of API Connector?

Can you show the url you have when you click on the signup button?

@imaguru this config worked for me

Note that the URLs are not the same https://discordapp.com/ instead of https://discord.com

1 Like

I tried few plugins and I have errors with all of them

Change to https://discordapp.com/ but still have this error. Mayby problem in discord app?

this url work for me but there’s an error in the space between your scopes
this is the url you should get;
https://discord.com/oauth2/authorize?client_id=1062335892833964032&redirect_uri=https:%2F%2Fimaguru.host%2Fapi%2F1.1%2Foauth_redirect&response_type=code&state=%257B%2522debug_mode%2522%253A%2522true%2522%252C%2522oauth_provider%2522%253A%2522apiconnector2-cmjqm%2522%252C%2522resume_key%2522%253A%25221674147665613x465100227164646300%2522%252C%2522used_redirect_url%2522%253A%2522https%253A%252F%252Fimaguru.host%252Fversion-test%252Flogin-s10%252Fsignup%252F%253Fdebug_mode%253Dtrue%2522%252C%2522redirect_unique_id%2522%253A%25221674147665989x613458061407708000%2522%257D&scope=email%20identify

Are there should be any link ?

@imaguru

I didn’t put any links there, just the redirect_uri in the OAuth2 screen

Also maybe a dumb question but worth checking - you got your App Secret from there, right?

1 Like

Nope. I am idiot… used public key instead of secret key. Thank you so much

1 Like

No problem!

@ambroisedlg sorry for the tag on a post that’s 2+ years old but I’ve searched forever and this post is as close as I can get to getting my issue figured out.

I’m also assuming my issue is just my ignorance we how bubble handles the code/token during the OAuth2 process.

I’m trying to allow uses to Join a private discord with role assignment after they sign up for my app.

I’m able to complete the OAuth2 process as you can see in the screen shot below.

My issue comes with setting up additional calls after that authorization. I’m trying to join the user to my sever with the designated role.

According to the Discord Docs all parameters are optional expect for the access_token.

To get to the point, its my understanding that bubble during the users authorization is running “https://discordapp.com/api/v9/oauth2/token” and is getting their access_token. Is that true?

If that is true how do I locate it so I can initialize my “join server” call? I’ve tried doing it without it and I get an “unauthorized” response.

I’ve also tried to save the token upon the redirect but the only data options are the users ID and Email.

@draked123 sorry for bringing you in as well but I saw a post from you where it looks like you do the “https://discordapp.com/api/v9/oauth2/token” as separate call. So is Bubble not swapping out the code for the user_token then?

Any help from anyone is appreciated.

Hey!

It has been a long while since I’ve messed with Discord’s OAuth and tokens, but if I recall correctly, myself and @johnny were unable to get the tokens to properly refresh or store in the Bubble database when using the API Connectors OAuth2 User-Agent Flow, so we managed the tokens directly ourselves when building this out, and used None / Self-handled.

Each user had a table entry for storing both their refresh token and their auth token. If you go this route, especially if you’re granting the Join servers permission, ensure you have strict privacy rules. We also stored the token expiration, and created a scheduled API call to refresh the auth token daily so we didn’t lose it.

It’s been years since I’ve touched the API, this is just all what I can recall directly from memory. I know once we solved this initial problem, hooking up the rest of the calls was really a breeze.

1 Like

Thanks @draked123 I managed to get it to work by using the None / Self-handled and handling the tokens in the DB.

Thanks for the tip.

1 Like