Skip to content

OAuth

client.oauth — identity and token exchange.

Official docs: OAuth2.

For a full walkthrough, see the OAuth cookbook.

When to use which

GoalMethodAuth on client
Linked profiles + granted scopesme{ type: "oauth", … }
Code → access tokenexchangeTokenNone (public POST)

me() does not accept API tokens or session cookies — only OAuth access tokens. For token/session identity use player.whoAmI.

me()

GET /oauth/meOAuth access token required

ts
type GetOAuthIdentityResult = {
  application: {
    client_id: string;
    scopes: string[];
  };
  profiles: Record<
    string, // uuid
    {
      username: string;
      primary: boolean;
      rank: string;
      supportRank: string | null;
      shortenedRank: string | null;
      legacyRankColour: { main: string; sub: string };
      rankBadge: string;
      accessRules: Record<string, string>;
    }
  >;
};
ts
const client = new WynnClient({
  auth: { type: "oauth", accessToken: process.env.WYNN_OAUTH_ACCESS_TOKEN! },
});

const { data } = await client.oauth.me();
const primary = Object.values(data.profiles).find((p) => p.primary);
console.log(data.application.scopes, primary?.username);

exchangeToken(options)

POST /oauth/token — no prior auth

Sends application/x-www-form-urlencoded via toOAuthTokenFormBody.

OptionTypeDescription
codestringAuthorization code from the redirect
redirectUristringMust match the registered redirect
clientIdstringApplication client ID
clientSecret?stringConfidential clients
codeVerifier?stringPKCE verifier for public clients

Result

ts
type ExchangeOAuthTokenResult = {
  access_token: string;
  token_type: "bearer";
  scope: string;
};
ts
const { data } = await new WynnClient().oauth.exchangeToken({
  code: "...",
  redirectUri: "https://example.com/callback",
  clientId: process.env.WYNN_OAUTH_CLIENT_ID!,
  codeVerifier: process.env.WYNN_OAUTH_CODE_VERIFIER,
});

const authed = new WynnClient({
  auth: { type: "oauth", accessToken: data.access_token },
});

Unofficial TypeScript tooling for the Wynncraft API