(auth)
REST APIs for managing Authentication
- getAccess - Get access allowances for a particular workspace
- getAccessToken - Get or refresh an access token for the current workspace.
- getUser - Get information about the current user.
- validateApiKey - Validate the current api key.
Checks if generation is permitted for a particular run of the CLI
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
const speakeasy = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const result = await speakeasy.auth.getAccess({});
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { SpeakeasyCore } from "@speakeasy-api/speakeasy-client-sdk-typescript/core.js";
import { authGetAccess } from "@speakeasy-api/speakeasy-client-sdk-typescript/funcs/authGetAccess.js";
// Use `SpeakeasyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const speakeasy = new SpeakeasyCore({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const res = await authGetAccess(speakeasy, {});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Query hooks for fetching data.
useAuthGetAccess,
useAuthGetAccessSuspense,
// Utility for prefetching data during server-side rendering and in React
// Server Components that will be immediately available to client components
// using the hooks.
prefetchAuthGetAccess,
// Utilities to invalidate the query cache for this query in response to
// mutations and other user actions.
invalidateAuthGetAccess,
invalidateAllAuthGetAccess,
} from "@speakeasy-api/speakeasy-client-sdk-typescript/react-query/authGetAccess.js";
Parameter | Type | Required | Description |
---|---|---|---|
request |
operations.GetWorkspaceAccessRequest | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<shared.AccessDetails>
Error Type | Status Code | Content Type |
---|---|---|
errors.SDKError | 4XX, 5XX | */* |
Get or refresh an access token for the current workspace.
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
const speakeasy = new Speakeasy();
async function run() {
const result = await speakeasy.auth.getAccessToken({
workspaceId: "<id>",
});
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { SpeakeasyCore } from "@speakeasy-api/speakeasy-client-sdk-typescript/core.js";
import { authGetAccessToken } from "@speakeasy-api/speakeasy-client-sdk-typescript/funcs/authGetAccessToken.js";
// Use `SpeakeasyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const speakeasy = new SpeakeasyCore();
async function run() {
const res = await authGetAccessToken(speakeasy, {
workspaceId: "<id>",
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Query hooks for fetching data.
useAuthGetAccessToken,
useAuthGetAccessTokenSuspense,
// Utility for prefetching data during server-side rendering and in React
// Server Components that will be immediately available to client components
// using the hooks.
prefetchAuthGetAccessToken,
// Utilities to invalidate the query cache for this query in response to
// mutations and other user actions.
invalidateAuthGetAccessToken,
invalidateAllAuthGetAccessToken,
} from "@speakeasy-api/speakeasy-client-sdk-typescript/react-query/authGetAccessToken.js";
Parameter | Type | Required | Description |
---|---|---|---|
request |
operations.GetAccessTokenRequest | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<shared.AccessToken>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorT | 4XX | application/json |
errors.SDKError | 5XX | */* |
Get information about the current user.
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
const speakeasy = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const result = await speakeasy.auth.getUser();
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { SpeakeasyCore } from "@speakeasy-api/speakeasy-client-sdk-typescript/core.js";
import { authGetUser } from "@speakeasy-api/speakeasy-client-sdk-typescript/funcs/authGetUser.js";
// Use `SpeakeasyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const speakeasy = new SpeakeasyCore({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const res = await authGetUser(speakeasy);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Query hooks for fetching data.
useAuthGetUser,
useAuthGetUserSuspense,
// Utility for prefetching data during server-side rendering and in React
// Server Components that will be immediately available to client components
// using the hooks.
prefetchAuthGetUser,
// Utility to invalidate the query cache for this query in response to
// mutations and other user actions.
invalidateAllAuthGetUser,
} from "@speakeasy-api/speakeasy-client-sdk-typescript/react-query/authGetUser.js";
Parameter | Type | Required | Description |
---|---|---|---|
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<shared.User>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorT | 4XX | application/json |
errors.SDKError | 5XX | */* |
Validate the current api key.
import { Speakeasy } from "@speakeasy-api/speakeasy-client-sdk-typescript";
const speakeasy = new Speakeasy({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const result = await speakeasy.auth.validateApiKey();
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { SpeakeasyCore } from "@speakeasy-api/speakeasy-client-sdk-typescript/core.js";
import { authValidateApiKey } from "@speakeasy-api/speakeasy-client-sdk-typescript/funcs/authValidateApiKey.js";
// Use `SpeakeasyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const speakeasy = new SpeakeasyCore({
security: {
apiKey: "<YOUR_API_KEY_HERE>",
},
});
async function run() {
const res = await authValidateApiKey(speakeasy);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Query hooks for fetching data.
useAuthValidateApiKey,
useAuthValidateApiKeySuspense,
// Utility for prefetching data during server-side rendering and in React
// Server Components that will be immediately available to client components
// using the hooks.
prefetchAuthValidateApiKey,
// Utility to invalidate the query cache for this query in response to
// mutations and other user actions.
invalidateAllAuthValidateApiKey,
} from "@speakeasy-api/speakeasy-client-sdk-typescript/react-query/authValidateApiKey.js";
Parameter | Type | Required | Description |
---|---|---|---|
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<shared.ApiKeyDetails>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorT | 4XX | application/json |
errors.SDKError | 5XX | */* |