Patreon auth in Ren'Py
A downloadable asset pack
Patreon Integration Setup
This guide helps you integrate Patreon authentication into your Ren'Py game.
1. Create a Patreon Client
Go to Patreon Developer Portal and click Create Client. Fill in the fields as follows:
- App Name: Your game’s name
- Description: Short message shown during login
- App Category: Choose any
- Redirect URIs:
http://127.0.0.1:6167/auth
- Client API Version:
2
- Other fields can be left empty
After creation, copy your Client ID.
2. Add to Your Game
Add this line to your options.rpy
:
define PATREON_CLIENT_ID = "<YOUR_CLIENT_ID>"
Replace <YOUR_CLIENT_ID>
with your actual Client ID.
Patreon Files
From the downloaded archive, copy the patreon_auth
folder into your game directory:
MyGame/game/patreon_auth
Add a Login Button
You can trigger the login with:
PatreonAuth(PATREON_CLIENT_ID)
Example:
textbutton _("Auth with Patreon") action PatreonAuth(PATREON_CLIENT_ID)
3. Accessing User Info
After login, user data is saved in:
persistent.PATREON_USER_DATA
Example - get user’s full name:
persistent.PATREON_USER_DATA.get("data").get("attributes").get("full_name")
More fields: User API Reference
4. Add Extra Scopes (e.g., Email) (optional)
Edit patreon_auth/PatreonAuth.rpy
and update the scope:
scope = "identity identity[email]"
Also update the fields requested in on_success_auth
:
user = client.get_user_data({
"fields[user]": "full_name,image_url,email"
})
More info: Scopes Reference
5. Check Patreon Tier
To check if the user is a patron of your game:
- Open the tier edit page on Patreon
- Get the Tier ID from the URL:
Example:
URL:https://www.patreon.com/membership/1234567
ID:1234567
Define your tier list:
define PATREON_TIERS = ["1234567", "2345678", "3456789"]
Then check membership like this:
included = persistent.PATREON_USER_DATA.get("included", [])
my_tiers = list(filter(lambda data: data.get("id") in PATREON_TIERS, included))
If subscribed, my_tiers
will be a non-empty list of tier info.
[{ 'id': '1234567', 'type': 'tier', 'attributes': { 'amount_cents': 300, 'title': 'My Tier for $3' }}]
More info: Member API Reference
6. Refreshing Data
To manually update user data (example code, may need testing):
client = PatreonClient(persistent.PATREON_TOKENS.get("access_token"))
user = client.get_user_data({
"fields[user]": "full_name,image_url",
"fields[tier]": "title,amount_cents",
"include": "memberships.currently_entitled_tiers"
})
persistent.PATREON_USER_DATA = user
renpy.restart_interaction()
7. Token Expiration
Patreon tokens expire after about 1 month.
- You can refresh them manually — see Token Refresh Guide
- Or ask the user to log in again
Updated | 10 hours ago |
Status | Released |
Category | Assets |
Release date | Nov 17, 2023 |
Rating | Rated 5.0 out of 5 stars (4 total ratings) |
Author | Dinaki |
Made with | Ren'Py |
Tags | authentication, patreon, Ren'Py, script |
Code license | MIT License |
Links | GitHub |
Download
Click download now to get access to the following files:
Development log
- No More Client Secret Required10 hours ago
Comments
Log in with itch.io to leave a comment.
This just screams security/privacy issue. If you put your client ID and secret in Ren'Py code, which anyone can go in and read, they'd have access to your client and would potentially be able to retrieve all your Patreon data, including names and email addresses.
Yeah, you right. I didn't think someone could use that in the final public build. I added a warning at the beginning.
Hi, your code is awesome, but whenever I log in to patreon and then try to save the game I get an error:
```
I'm sorry, but an uncaught exception occurred.
While running game code:
File "renpy/common/00gamemenu.rpy", line 174, in script
$ ui.interact()
File "renpy/common/00gamemenu.rpy", line 174, in <module>
$ ui.interact()
File "renpy/common/00action_file.rpy", line 397, in __call__
renpy.save(fn, extra_info=save_name)
TypeError: cannot pickle '_thread.lock' object (perhaps store.webserver.server._BaseServer__is_shut_down._cond._lock = <unlocked _thread.lock object at 0x00000000066a4600>)
I managed to put a band aid on this by making renpy restart after each authentication, I saw you had them in your code, but for some reason it did not do it on my laptop so in the end that's fine.
Also it does not work on mobile, the patreon link shows up and then the page loads for a while and then crashes.
Also it crashes directly in the browser:
I've uploaded a new version that fixes the first problem with saving.
I'll look into the second problem when I have more time.
Hello, I have a problem. Observe the following error when clicking the "Auth With Patreon" button This page is not working No data was sent by localhost ERR_EMPTY_RESPONSE
"http://localhost:6167/auth?code=08DDd0e75udOHwbpHrJorzUF8Hdtme&state=None"
Hello. Have you replaced `PATREON_CLIENT_ID` and `PATREON_CLIENT_SECRET` in the "options.rpy" file?
There is no `APP_NAME would like to...` window?
Yes, I changed it to
Patreon authentication
set PATREON_CLIENT_ID = "93VC-W99QouZubcHXV9F76GchkNzIjyHwaYppU3hQX9CN2ZrQTPhuUTsm7UIsGiY"
set PATREON_CLIENT_SECRET = "MC2CJKrpErv96aVhOHJTH54bmSMta5YonMqFJoRGG4aqiSTnSNqR5p_vpfltql2v"
In Options.py
Everything works normally until the
View your public profile (Allow) (Deny)
When clicking Allow, the error message appears on the web page.
[This page is not workinglocalhost did not send any data.
ERR_EMPTY_RESPONSE]
The problem appears after the `APP_NAME would like to...` window
Did you change anything else?
I just replaced ID and SECRET in options.rpy in the default project and got a successful result.
Possible solution:
In the patreon_auth/OAuth2Strategy.rpy replace this line:
With this:
And in the patreon client replace Redirect URIs with http://127.0.0.1:6167/auth
{"error":"invalid_request","error_description":"Mismatching redirect URI."}
Now this error appears when clicking (Allow)
I didn't modify anything, I used the file you released here. And I put the pateron credentials. Is there a problem with the files you imported and for some reason I don't have them?
(import http.server
from urllib.parse import urlparse, parse_qs, urlencode
from urllib.request import urlopen, Request
import threading
import json)
I managed to resolve this error mentioned above, but now the screen has the same error of not loading again.
Thanks for sharing the code!
Do you plan to publish this code on github?
What is the usage license of your tool?
Hello. No plans to publish on github for now.
MIT License.