For developers

Connect with rNet

Connect with rNet signs users in and lets your app spend their credits. It uses OAuth 2.0 with the authorization code flow and PKCE. The SDKs handle the protocol details for you.

The flow

1

User clicks Connect with rNet

Your server creates a PKCE verifier and challenge plus a random state, stores the verifier and state in the user's session, and redirects to rNet.

2

User signs in and allows your app

rNet shows your app name and what it can do: see the user's name and email address, and use their rNet credits for AI requests they make in your app.

3

rNet redirects back with a code

The user returns to your redirect URI with code and state. Check that state matches what you stored.

4

Your server exchanges the code

Your server sends the code and verifier to rNet and receives an access token and a refresh token for this user.

Start sign-in

javascript
// Create a PKCE pair and keep the verifier in the user's server-side session
const { verifier, challenge } = auth.generatePKCE();
const state = crypto.randomUUID();
req.session.rnet = { verifier, state };

// Send the user to rNet to sign in and approve your app
res.redirect(auth.getAuthorizationUrl(challenge, state));

Handle the callback

javascript
// GET /callback?code=...&state=...
const { verifier, state } = req.session.rnet;
if (req.query.state !== state) return res.status(400).send('Invalid state');

const tokens = await auth.exchangeCodeForToken(req.query.code, verifier);
req.session.rnet = {
  accessToken: tokens.access_token,
  refreshToken: tokens.refresh_token,
};
Keep tokens on the server
Do the code exchange and store tokens on your server only. Never expose the Client secret, access token or refresh token to browser JavaScript. See Sessions and tokens.

Get the user's profile

javascript
const user = await auth.getUserInfo(accessToken);
console.log(user.email, user.name);
FieldDescription
subStable user identifier.
emailThe user's email address.
email_verifiedWhether the email is verified.
nameThe user's name.
preferred_usernameUsername.
user_idrNet user ID.
roleUSER or DEVELOPER.
statusAccount status.

Scopes are openid profile email; the SDKs request them for you. The fields above may vary by account.

Button guidelines

  • Label the button Connect with rNet. Write rNet with a lowercase r and capital N.
  • Show the rNet icon on the left. You can use https://www.rnetai.org/favicon.svg.
  • Use a neutral style that fits your app, or rNet green (#059345) with white text.
  • Keep it at least 40px tall and as easy to find as your other sign-in options.
html
<a href="/auth/rnet" class="rnet-button">
  <img src="https://www.rnetai.org/favicon.svg" alt="" width="20" height="20" />
  Connect with rNet
</a>

<style>
  .rnet-button {
    display: inline-flex; align-items: center; gap: 8px;
    height: 40px; padding: 0 16px; border-radius: 8px;
    border: 1px solid #e5e5e5; background: #fff; color: #171717;
    font: 500 14px/1 system-ui, sans-serif; text-decoration: none;
  }
  .rnet-button:hover { background: #f4f4f4; }
</style>

Raw endpoints

Not using an SDK? See the Authentication API for the authorize, token and userinfo endpoints.