Goal of this patch
Allow Blender Studio to read Blender Cloud session info, so that Blender Studio could serve some of the pages while sharing Blender Cloud's domain, without requiring users to login again.
This is intended to be a temporary solution until Blender Studio handles authentication on its own without having to share its login session with Blender Cloud.
See more https://developer.blender.org/T81349
What this does
This patch introduces a blendercloud app into Blender Studio, which does the following:
- adds a middleware that tries to read a Flask session cookie;
- if Flask session cookie is readable and contains a Blender ID access token:
- looks up a user already associated with this token in the Blender Studio's DB;
- if there's no existing user, uses the access token to fetch user info and stores it the same way blender_id_oath_client does it:
- creates a User, OAuthUserInfo and OAuthToken records;
- copies avatar, username, full name and roles from Blender ID service to a Profile;
- modifies current Django session logging the user in.
Note that existing Blender Cloud OAuth access token is copied over to Blender Studio, and will be used to communicate with Blender ID.
The above appears to work regardless of which OAuth app this access token was originally issued to.
These changes are intended to be easily removed, so most of the logic related to handling of Profile data such as avatar, full name and roles, ties into previously implemented Profile flow.
Configuration
In order for the above to work, the following configuration is required:
- Blender ID should have a new Blender Studio app configured;
- cloud.blender.org (cloud.local for local setup) should be added to ALLOWED_HOSTS of Blender Studio;
- OAuth client secret and webhook secret added to the studio/settings.py;
- Blender Cloud's web server (or LB) should have locations proxying requests to Blender Studio (studiobeta.blender.org).