Yroun Guide

OAuth & Widget Viewer Identity

Expose your own server's API inside a hub page (API widgets) and know WHO is looking, without asking viewers to paste headers, and without receiving personal data you did not ask for. Two layers, both standard:

  • Layer 1 · Widget token (default, no consent): every signed-in viewer's widget request carries a short-lived token. Verifying it gives you a per-hub pseudonymous viewerId, stable for the same viewer on the same hub, impossible to correlate across hubs or trace back to a Yroun account.
  • Layer 2 · Sign in with Yroun (one-time consent): when you need a real identity (e.g. your own admins), the account connects once through a standard OAuth 2.0 consent and you read their email and name. Store the viewerId ↔ email link in your database; every later request is identified by Layer 1 alone.
  • Identity is authentication, not authorization. A verified token proves exactly two things: the request came from a signed-in Yroun account, and this is that account's stable pseudonym for this hub. It does NOT imply hub membership, hub visibility, a plan, or any entitlement. Any signed-in Yroun account can obtain a token for any hub uid, including one they are not a member of. So AUTHORIZATION is always yours: decide access from the viewerId you have on file (your own allowlist, role table, or the Layer 2 email link), and always compare the hubUid the verify response returns against your own hub before trusting the viewerId.

    Choosing your integration path: token verify vs proxy headers

    Layer 1 identity reaches your server by one of two paths, and BOTH deliver the SAME per-hub pairwise viewerId. Start with either and switch later without losing continuity. They differ in trust model and integration cost:

  • Widget token verify (direct): the widget calls your API straight from the viewer's browser; you verify the token against Yroun (below). This is PROOF: a verified token cannot be forged. Costs 1 credit per verification (cacheable for the token's 5-minute lifetime), needs one verify call on your side, and your API must be browser-reachable (CORS).
  • Connection proxy headers: the widget calls through Yroun's server-side Connection proxy instead; signed-in viewers arrive with X-Yroun-Viewer (the same viewerId) and X-Yroun-Hub already attached. This is an ASSERTION: you trust that the request really came from Yroun's proxy. Check the credential you configured on the Connection before trusting the headers. Zero integration work, no verification cost, and your API key stays server-side (never in a browser). Setup: Hub Page Widgets → CONNECTIONS.
  • On either path, no token / absent headers = anonymous viewer. Machine callers (API keys) never carry a viewer identity.
  • Rule of thumb: if identity gates anything security-sensitive (paid content, per-viewer permissions, rate limits), verify the token. Proof beats assertion. For personalization or analytics, or when your API key must stay server-side, the Connection proxy headers are the zero-work answer.

    Layer 1: Verify the widget token

    In the widget's auth tab pick Yroun ID. Every signed-in viewer's request to your server then carries this header automatically (5-minute tokens, refreshed by the widget, nothing to configure per user):

    Authorization: YrounWidget <token>

    Your server verifies the token with your own API key (each verification is metered against your credits, and the viewer never pays for your identification):

    curl -X POST https://api.yroun.com/oapi/widget-tokens/verify \
      -H "X-API-Key: yroun_key_xxxxxxxxxxxx" \
      -H "Content-Type: application/json" \
      -d '{ "token": "<value after the YrounWidget prefix>" }'
    { "valid": true, "viewerId": "3f9c…32-hex, stable per (viewer, hub)", "hubUid": "…" }
  • valid=false (HTTP 200): expired or forged token. Treat the request as anonymous.
  • A transport error is NOT an invalid user. Retry or fail the request, never silently anonymize.
  • You may cache a verification for the token's 5-minute lifetime, no need to re-verify per request.
  • Membership disclosure: one-line authorization for your own hub

    By default a valid token proves authentication only. When the dashboard you are protecting belongs to YOUR OWN hub, ask verify to also disclose membership. Add includeMembership: true and your admin policy becomes one line: a JOINED ADMIN passes.

    curl -X POST https://api.yroun.com/oapi/widget-tokens/verify \
      -H "X-API-Key: yroun_key_xxxxxxxxxxxx" \
      -H "Content-Type: application/json" \
      -d '{ "token": "<token>", "includeMembership": true }'
    { "valid": true, "viewerId": "…", "hubUid": "…", "membership": { "isMember": true, "authority": "ADMIN" } }
  • Only JOINED members disclose an authority. A pending invite reads as isMember:false.
  • Non-members stay fully pseudonymous: nothing beyond isMember:false is ever disclosed, and no reverse lookup exists.
  • The default response is unchanged. Membership appears only when you ask for it.
  • Pre-provisioning: read your members' viewerIds

    To whitelist specific members BEFORE they ever open your dashboard, or to see which member a stored viewerId belongs to, the members list can include each member's own-hub viewerId. Owner/admin surface, members only:

    curl "https://api.yroun.com/oapi/hubs/{hubUid}/members?includeViewerId=true" \
      -H "X-API-Key: yroun_key_xxxxxxxxxxxx"

    Pattern: an application & approval dashboard

    The shape that runs real multi-admin operations on a single hub page, end to end:

  • Applicants interact through your openid-mode widget. Every submission your API receives already carries their verified viewerId. Store it on the row.
  • Staff review the rows on the same hub page (an API table widget over your own API) and approve or reject. No manual identity matching: the row was born with its viewerId.
  • Gate admin actions with includeMembership. 'JOINED ADMIN of this hub' replaces a hand-maintained admin allowlist, so adding an admin to the hub IS the entire onboarding.
  • When a flow needs access before first contact, pre-approve known members from the member viewerId list above.
  • Layer 2: Sign in with Yroun (email confirmation)

    Standard OAuth 2.0 Authorization Code + PKCE (S256, required, no client secret in the current version; keep the code_verifier in your server-side session). The consent screen shows exactly one permission: "Confirm your email and name" (scope: identity). An identity-scope token can call userinfo and nothing else.

  • Redirect the browser to https://oauth.yroun.com/oauth/authorize with response_type=code, your client_id, a registered redirect_uri, scope=identity, a state you keep in session, and the PKCE code_challenge (+ method=S256). A signed-out visitor is routed through Yroun sign-in automatically.
  • On return, check state, then exchange the code: POST https://oauth.yroun.com/oauth/token (form-encoded) with grant_type=authorization_code, code, redirect_uri, client_id, code_verifier → access_token (1 hour), refresh_token (30 days).
  • Read the identity: GET https://oauth.yroun.com/oauth/userinfo with Authorization: Bearer <access_token> → { sub, email, name, locale }.
  • Store { viewerId ↔ sub/email } in your database. Done. Later widget requests need only Layer 1.
  • # 2) token exchange
    curl -X POST https://oauth.yroun.com/oauth/token \
      -H "Content-Type: application/x-www-form-urlencoded" \
      -d "grant_type=authorization_code&code=CODE&redirect_uri=URI&client_id=ID&code_verifier=VERIFIER"
    
    # 3) identity
    curl https://oauth.yroun.com/oauth/userinfo \
      -H "Authorization: Bearer ACCESS_TOKEN"

    Server samples: Spring / Node

    No Yroun SDK is required. Both layers are one standard HTTP call each. Copy-paste starting points:

    // Spring: verify a widget token (Layer 1)
    record VerifyResponse(boolean valid, String viewerId, String hubUid) {}
    
    public Optional<VerifyResponse> verify(String authorization) {
        if (authorization == null || !authorization.startsWith("YrounWidget "))
            return Optional.empty();
        VerifyResponse res = restClient.post()
            .uri("https://api.yroun.com/oapi/widget-tokens/verify")
            .header("X-API-Key", apiKey)
            .body(Map.of("token", authorization.substring(12)))
            .retrieve().body(VerifyResponse.class);
        return (res != null && res.valid()) ? Optional.of(res) : Optional.empty();
    }
    // Node / Next.js: start the OAuth link (Layer 2)
    const verifier = crypto.randomBytes(48).toString('base64url')
    const challenge = crypto.createHash('sha256').update(verifier).digest('base64url')
    // keep verifier + state in the server session, then redirect to:
    // https://oauth.yroun.com/oauth/authorize?response_type=code&client_id=...
    //   &redirect_uri=...&scope=identity&state=...&code_challenge=<challenge>
    //   &code_challenge_method=S256
    
    // callback: state check -> token exchange -> userinfo
    const tokens = await (await fetch('https://oauth.yroun.com/oauth/token', {
      method: 'POST',
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
      body: new URLSearchParams({ grant_type: 'authorization_code', code,
        redirect_uri: REDIRECT_URI, client_id: CLIENT_ID, code_verifier: verifier }),
    })).json()
    const userinfo = await (await fetch('https://oauth.yroun.com/oauth/userinfo', {
      headers: { Authorization: `Bearer ${tokens.access_token}` },
    })).json()  // { sub, email, name, locale }

    Spring Security users can register Yroun as a standard OAuth2 client provider (authorization-uri / token-uri / user-info-uri from the well-known metadata) instead of hand-rolling the callback.

    Token rules you must honor

  • refresh_token is SINGLE-USE and rotating: POST /oauth/token with grant_type=refresh_token returns a new refresh_token. Replace the stored one. Re-using an old refresh_token invalidates the whole chain (replay protection).
  • If you only confirm the email once and store the link, you may discard the tokens right after. Re-consent is always available.
  • Keep tokens and API keys server-side only. Never in browser storage.
  • Users can disconnect any time at console.yroun.com/connections. A failed refresh means re-consent, plan for it. Your side can revoke via POST /oauth/revoke.
  • Protocol metadata (all endpoints, machine-readable): https://oauth.yroun.com/.well-known/oauth-authorization-server
  • Register your app (get a client_id)

    Self-serve, no review, no waiting on us: console.yroun.com → Your Apps. Two fields are required and the client_id is issued immediately.

  • App name: shown on the consent screen. Pick one of your hubs in the form and its name and image fill in for you; that hub identity is usually the right answer.
  • One redirect URI: https, matched exactly against the one you send. An unlisted URI is refused, which is what stops anyone else pointing your sign-in at their own server. Add more later.
  • Then choose where the app runs, because that decides whether a secret exists at all. A browser, mobile or extension client is PUBLIC: no secret is issued and it authenticates with PKCE. A server-side app is CONFIDENTIAL and receives a client secret shown exactly once. We keep only its hash, so a lost secret is rotated, never looked up.

    Everything else is optional and editable later: description, logo URL, privacy policy and terms links. A privacy policy is NOT required to register; when you provide one it is linked on the consent screen, and after the grant the user's email and name are governed by your policy. Scopes default to identity. Request only what you need, since every one you tick becomes a line the user reads before approving.

    The widget-verify API key is separate and also self-service: your hub → Settings → API Keys.

    Or register with your API key, no browser

    Everything the console page does is also an Open API capability your own key holds, so registration and rotation can be automated and never require a logged-in session. Same rules, same caps, same owner: the app belongs to the key owner, and you cannot register on behalf of anyone else.

    curl -X POST "https://oapi.yroun.com/oauth-apps" \
      -H "X-API-Key: $YROUN_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"name":"My App","redirectUris":["https://example.com/callback"],"scopes":["identity"],"confidential":true}'
    
    # -> { clientId, clientSecret, clientType, redirectUris, scopes, ... }
    #    clientSecret appears in THIS response only.
  • GET /oauth-apps: your apps. clientSecret is never in a list response.
  • POST /oauth-apps/{clientId}/actions/rotate-secret: new secret, shown once; the old one stops working immediately.
  • DELETE /oauth-apps/{clientId}: soft delete; existing tokens stop working at once.
  • Checklist

  • Widget auth tab = Yroun ID (no manual header instructions for viewers).
  • Server parses Authorization: YrounWidget → POST /oapi/widget-tokens/verify with your X-API-Key.
  • valid=false → anonymous; transport error → error. Never confuse the two.
  • OAuth: verify state, keep the PKCE verifier server-side, rotate the refresh_token on every refresh.
  • Link viewerId ↔ email once; identify by viewerId afterwards.
  • Stuck, or something here is wrong? Send us a message