UNPKG

@spree/storefront-api-v2-sdk

Version:

Node module to easily integrate your JavaScript or TypeScript application with Spree Storefront API V2. You can create an entirely custom Storefront in JS/TS with this package including one page checkout, Single Page Apps, PWAs and so on.

85 lines (84 loc) 2.96 kB
import { Http } from '@spree/core-api-v2-sdk'; import type { IOAuthTokenResult, EmptyObjectResult } from '@spree/core-api-v2-sdk'; import type { AuthTokenAttr, GetTokenOptions, RefreshTokenAttr, RefreshTokenOptions, RevokeTokenAttr, RevokeTokenOptions } from '../interfaces/Authentication'; export default class Authentication extends Http { /** * Creates a [Bearer token](../pages/tokens.html#bearer-token) required to authorize OAuth API calls. * * **Success response schema:** * ```ts * interface res { * access_token: string * token_type: string = 'Bearer' * expires_in: number * refresh_token: string * created_at: number * } * ``` * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const token = await client.authentication.getToken({ * username: 'spree@example.com', * password: 'spree123' * }) * ``` */ getToken(options: GetTokenOptions): Promise<IOAuthTokenResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ getToken(params: AuthTokenAttr): Promise<IOAuthTokenResult>; /** * Refreshes the [Bearer token](../pages/tokens.html#bearer-token) required to authorize OAuth API calls. * * **Success response schema:** * ```ts * interface res { * access_token: string * token_type: string = 'Bearer' * expires_in: number * refresh_token: string * created_at: number * } * ``` * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const token = await client.authentication.refreshToken({ * refresh_token: 'aebe2886d7dbba6f769e20043e40cfa3447e23ad9d8e82c632f60ed63a2f0df1' * }) * ``` */ refreshToken(options: RefreshTokenOptions): Promise<IOAuthTokenResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ refreshToken(params: RefreshTokenAttr): Promise<IOAuthTokenResult>; /** * Revokes a [Bearer token (access token)](../pages/tokens.html#bearer-token) or a refresh token. * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.authentication.revokeToken({ * token: 'aebe2886d7dbba6f769e20043e40cfa3447e23ad9d8e82c632f60ed63a2f0df1' * }) * ``` */ revokeToken(optons: RevokeTokenOptions): Promise<EmptyObjectResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ revokeToken(params: RevokeTokenAttr): Promise<EmptyObjectResult>; }