Skip to main content

RNet OAuth Python Library

A Python backend library for integrating RNet OAuth and AI Provider services. This library allows users to authenticate via RNet and pay for AI model token costs directly using their RNet account.

Features

  • OAuth2 PKCE Support: Secure authorization code flow with automatic code verifier and challenge generation.
  • Token Management: Exchange authorization codes for tokens and refresh expired tokens.
  • UserInfo Endpoint: Fetch the authenticated user's RNet profile with an access token.
  • AI Integration: Easy methods to chat with AI models using standard or streaming responses.

Installation

pip install rnet-oauth

Quick Start

1. Initialize the Clients

from rnet_oauth import RNetOAuthClient, ModelClient

auth = RNetOAuthClient(
    client_id='client-id',
    client_secret='client-secret',
    redirect_uri='redirect-uri'
)
ai = ModelClient("gemini-2.5-flash-lite")

2. Generate Authorization URL (OAuth2 PKCE)

# 1. Generate PKCE
pkce = auth.generate_pkce()
verifier = pkce['verifier']
challenge = pkce['challenge']

# 2. Get Authorization URL
# challenge: PKCE code challenge (optional)
# state: An optional string to maintain state between the request and callback (recommended for security)
auth_url = auth.get_authorization_url(challenge, state='optional-state')

3. Exchange Code for Tokens

# 3. Exchange code for tokens
tokens = auth.exchange_code_for_token(code, verifier)
access_token = tokens['access_token']

4. Get User Info

user_info = auth.get_user_info(access_token)
print(user_info['email'])
print(user_info['name'])

The UserInfo response comes from RNet's /userinfo endpoint and may include: sub, email, email_verified, name, preferred_username, user_id, role, and status.

5. Chat with AI

response = ai.chat({
    "contents": [
        {
            "role": "user",
            "parts": [{"text": "Hello!"}]
        }
    ]
}, access_token)

6. Streaming AI Response

for chunk in ai.chat_stream({
    "contents": [
        {
            "role": "user",
            "parts": [{"text": "Hello!"}]
        }
    ]
}, access_token):
    print(chunk)

License

MIT

Metadata

Release files for rnet-oauth 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rnet-oauth 1.0.3
File Size Uploaded
rnet_oauth-1.0.3.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rnet-oauth 1.0.3
File Interpreter ABI Platform
rnet_oauth-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 12.9 kB

Release files / rnet_oauth-1.0.3.tar.gz

Download URL rnet_oauth-1.0.3.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
73a593e43e5aa2a901e97877164638e5d410bba304a5a28fb4ad95a6845ba2ee
BLAKE2b-256 checksum
How to use checksums
929e0745d6db65413b55a6bdd4abb3029766a1cbf9847ed38f1d7e51b85b8adf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / rnet_oauth-1.0.3-py3-none-any.whl

Download URL rnet_oauth-1.0.3-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a1fb863de38a171b523584ca38526c257d429f96b351816da417f5119d8b9f3
BLAKE2b-256 checksum
How to use checksums
9a04d10835baf0b9651ccd1c2706ede3666c28c68faf97c256886591803b199f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page