Patreon auth in Ren'Py

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
Andredron
Miko-Class Veteran
Posts: 689
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Patreon auth in Ren'Py

#1 Post by Andredron »



https://dinaki.itch.io/auth-with-patreon-in-renpy-game

First, you need to create a client on Patreon.

Go to the https://www.patreon.com/portal/registra ... er-clients and click on the "Create Client" button.

App Name — enter your game name
Description — enter some text. It will displayed to the user on authentication page.
App Category — Select something
Redirect URIs — enter http://localhost:6167/auth
Client API Version — should be 2
Other fields are not required.
You only need 2 fields "Client ID" and "Client Secret" from the newly created client.

Somewhere in your game (for example, in the "options.rpy") write this code:

define PATREON_CLIENT_ID = "<YOUR_CLIENT_ID>"
define PATREON_CLIENT_SECRET = "<YOUR_CLIENT_SECRET>"
Replace the "<YOUR_CLIENT_ID>" with your Client ID value and
"<YOUR_CLIENT_SECRET>" with your Client Secret value.

From the archive that you downloaded from itch, you'll need 4 files inside the "patreon_auth" folder. Extract this folder inside your game folder (i.e ("MyGame/game/patreon_auth")

Now somewhere in the game you can use this action to start auth process:
PatreonAuth(PATREON_CLIENT_ID, PATREON_CLIENT_SECRET, "/auth")
For example:

textbutton _("Auth with Patreon") action PatreonAuth(PATREON_CLIENT_ID, PATREON_CLIENT_SECRET, "/auth")
By default, user info are saved inside persistent.PATREON_USER_DATA variable.

For example, to get user name:

persistent.PATREON_USER_DATA.get("data").get("attributes").get("full_name")
More info about other fields here: https://docs.patreon.com/#user-v2.

Scopes
Some info are not sent from Patreon by default. To get it, you need to edit scopes inside the "patreon_auth/PatreonAuth.rpy" file.

For example, to get user email, update the scope parameter to this:
scope = "identity identity[email]".

Also, you need to update requested fields inside the on_success_auth function. Add "email" to the "fields[user]" field:

user = client.get_user_data({"fields[user]": "full_name,image_url,email"...
More info about scopes here https://docs.patreon.com/#scopes

How to tell if a player is subscribed
Something like this should work:

included = persistent.PATREON_USER_DATA.get("included")
if len(included) > 0:
attributes = included[0].get("attributes", {})
patron_status = attributes.get("patron_status")
amount = attributes.get("currently_entitled_amount_cents")
patron_status variable could be one of those: active_patron, declined_patron, former_patron or None (if user never pledged).

More info here: https://docs.patreon.com/#member

Post Reply

Who is online

Users browsing this forum: No registered users