Skip to main content
REST client

OAuth

The 4 operations under oauth, as typed calls on the generated REST client.

1 min read
View MarkdownEdit on GitHub

OAuth

Available from @codespar/sdk 0.12.0, which is not on npm yet. The published version today is 0.11.0, and it has no cs.api; 0.12.0 is on the main branch of codespar-core. The examples below are not compiled against the installed package for that reason.

Every call below is cs.api reaching one operation of the OpenAPI document this page was generated from; the REST client overview explains request, response, the option bag and the errors. The values are placeholders shaped by the document.

import { CodeSpar } from "@codespar/sdk";

const cs = new CodeSpar({ apiKey: process.env.CODESPAR_API_KEY });

GET /oauth/authorize

GET/oauth/authorize

Consent page (RFC 6749 §4.1.1 authorization request)

const result = await cs.api.get("/oauth/authorize", {
  query: {
    response_type: "code",
    client_id: "client_0000000000000000",
    redirect_uri: "https://example.com/hook",
    code_challenge: "string",
    code_challenge_method: "S256"
  }
});

Parameters, body and every documented response: GET /oauth/authorize in the HTTP reference.

POST /oauth/authorize

POST/oauth/authorize

Consent submit — exchanges a pasted API key for an authorization code

const result = await cs.api.post("/oauth/authorize", {
  body: {
    response_type: "code",
    client_id: "client_0000000000000000",
    redirect_uri: "https://example.com/hook",
    code_challenge: "string",
    code_challenge_method: "S256",
    state: "string",
    scope: "string",
    api_key: "string"
  }
});

Parameters, body and every documented response: POST /oauth/authorize in the HTTP reference.

POST /oauth/register

POST/oauth/register

Register a client (RFC 7591 dynamic client registration)

const result = await cs.api.post("/oauth/register", {
  body: {
    redirect_uris: [
      "https://example.com/hook"
    ],
    client_name: "Example",
    token_endpoint_auth_method: "https://example.com/hook",
    grant_types: [
      "string"
    ],
    response_types: [
      "string"
    ]
  }
});

Parameters, body and every documented response: POST /oauth/register in the HTTP reference.

POST /oauth/token

POST/oauth/token

Token endpoint — authorization_code and refresh_token grants

const result = await cs.api.post("/oauth/token", {
  body: {
    grant_type: "authorization_code",
    code: "string",
    code_verifier: "string",
    redirect_uri: "https://example.com/hook",
    client_id: "client_0000000000000000",
    refresh_token: "string"
  }
});

Parameters, body and every documented response: POST /oauth/token in the HTTP reference.

OAuth | CodeSpar