Repository: gradio-app/gradio
File: gradio/helpers.py (Python)

Code before:
        elif type_hint in (
            oauth.OAuthProfile | None,
            oauth.OAuthToken | None,
            oauth.OAuthProfile,
            oauth.OAuthToken,
        ):
            if inputs is not None:
                # Retrieve session from gr.Request, if it exists (i.e. if user is logged in)
                try:
                    session = (
                        # request.session (if fastapi.Request obj i.e. direct call)
                        getattr(request, "session", {})
                        or
                        # or request.request.session (if gr.Request obj i.e. websocket call)
                        getattr(getattr(request, "request", None), "session", {})
                    )
                except AssertionError as e:
                    if (
                        "SessionMiddleware must be installed to access request.session"
                        in str(e)
                    ):
                        session = {}
                    else:
                        raise e

                # Inject user profile
                if type_hint in (Optional[oauth.OAuthProfile], oauth.OAuthProfile):
                    oauth_profile = (
                        session["oauth_info"]["userinfo"]
                        if "oauth_info" in session
                        else None
                    )
                    if oauth_profile is not None:
                        oauth_profile = oauth.OAuthProfile(oauth_profile)
                    elif type_hint == oauth.OAuthProfile:
                        raise Error(
                            "This action requires a logged in user. Please sign in and retry."
                        )
                    inputs.insert(i, oauth_profile)

                # Inject user token
                elif type_hint in (Optional[oauth.OAuthToken], oauth.OAuthToken):
                    oauth_info = session.get("oauth_info")
                    oauth_token = (
                        oauth.OAuthToken(
                            token=oauth_info["access_token"],
                            scope=oauth_info["scope"],
                            expires_at=oauth_info["expires_at"],
                        )
                        if oauth_info is not None
                        else None

Review comment (security):
perhaps let's raise a warning here to remind the developer that an empty session is being created and they they need to e.g. install `gradio[oauth]` and add a `gr.LoginButton` to actually get the session

Code after:
        elif type_hint in (
            oauth.OAuthProfile | None,
            oauth.OAuthToken | None,
            oauth.OAuthProfile,
            oauth.OAuthToken,
        ):
            if inputs is not None:
                # Retrieve session from gr.Request, if it exists (i.e. if user is logged in)
                try:
                    session = (
                        # request.session (if fastapi.Request obj i.e. direct call)
                        getattr(request, "session", {})
                        or
                        # or request.request.session (if gr.Request obj i.e. websocket call)
                        getattr(getattr(request, "request", None), "session", {})
                    )
                except AssertionError as e:
                    if (
                        "SessionMiddleware must be installed to access request.session"
                        in str(e)
                    ):
                        warnings.warn(
                            "Empty session being created. Install gradio[oauth] and add a gr.LoginButton to your app to enable OAuth login.",
                            UserWarning,
                        )
                        session = {}
                    else:
                        raise e

                # Inject user profile
                if type_hint in (Optional[oauth.OAuthProfile], oauth.OAuthProfile):
                    oauth_profile = (
                        session["oauth_info"]["userinfo"]
                        if "oauth_info" in session
                        else None
                    )
                    if oauth_profile is not None:
                        oauth_profile = oauth.OAuthProfile(oauth_profile)
                    elif type_hint == oauth.OAuthProfile:
                        raise Error(
                            "This action requires a logged in user. Please sign in and retry."
                        )
                    inputs.insert(i, oauth_profile)

                # Inject user token
                elif type_hint in (Optional[oauth.OAuthToken], oauth.OAuthToken):
                    oauth_info = session.get("oauth_info")
                    oauth_token = (
                        oauth.OAuthToken(
                            token=oauth_info["access_token"],
                            scope=oauth_info["scope"],