UNPKG

3.73 kBTypeScriptView Raw
1import { GaxiosOptions } from 'gaxios';
2/**
3 * OAuth error codes.
4 * https://tools.ietf.org/html/rfc6749#section-5.2
5 */
6type OAuthErrorCode = 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'unauthorized_client' | 'unsupported_grant_type' | 'invalid_scope' | string;
7/**
8 * The standard OAuth error response.
9 * https://tools.ietf.org/html/rfc6749#section-5.2
10 */
11export interface OAuthErrorResponse {
12 error: OAuthErrorCode;
13 error_description?: string;
14 error_uri?: string;
15}
16/**
17 * OAuth client authentication types.
18 * https://tools.ietf.org/html/rfc6749#section-2.3
19 */
20export type ConfidentialClientType = 'basic' | 'request-body';
21/**
22 * Defines the client authentication credentials for basic and request-body
23 * credentials.
24 * https://tools.ietf.org/html/rfc6749#section-2.3.1
25 */
26export interface ClientAuthentication {
27 confidentialClientType: ConfidentialClientType;
28 clientId: string;
29 clientSecret?: string;
30}
31/**
32 * Abstract class for handling client authentication in OAuth-based
33 * operations.
34 * When request-body client authentication is used, only application/json and
35 * application/x-www-form-urlencoded content types for HTTP methods that support
36 * request bodies are supported.
37 */
38export declare abstract class OAuthClientAuthHandler {
39 private readonly clientAuthentication?;
40 private crypto;
41 /**
42 * Instantiates an OAuth client authentication handler.
43 * @param clientAuthentication The client auth credentials.
44 */
45 constructor(clientAuthentication?: ClientAuthentication | undefined);
46 /**
47 * Applies client authentication on the OAuth request's headers or POST
48 * body but does not process the request.
49 * @param opts The GaxiosOptions whose headers or data are to be modified
50 * depending on the client authentication mechanism to be used.
51 * @param bearerToken The optional bearer token to use for authentication.
52 * When this is used, no client authentication credentials are needed.
53 */
54 protected applyClientAuthenticationOptions(opts: GaxiosOptions, bearerToken?: string): void;
55 /**
56 * Applies client authentication on the request's header if either
57 * basic authentication or bearer token authentication is selected.
58 *
59 * @param opts The GaxiosOptions whose headers or data are to be modified
60 * depending on the client authentication mechanism to be used.
61 * @param bearerToken The optional bearer token to use for authentication.
62 * When this is used, no client authentication credentials are needed.
63 */
64 private injectAuthenticatedHeaders;
65 /**
66 * Applies client authentication on the request's body if request-body
67 * client authentication is selected.
68 *
69 * @param opts The GaxiosOptions whose headers or data are to be modified
70 * depending on the client authentication mechanism to be used.
71 */
72 private injectAuthenticatedRequestBody;
73 /**
74 * Retry config for Auth-related requests.
75 *
76 * @remarks
77 *
78 * This is not a part of the default {@link AuthClient.transporter transporter/gaxios}
79 * config as some downstream APIs would prefer if customers explicitly enable retries,
80 * such as GCS.
81 */
82 protected static get RETRY_CONFIG(): GaxiosOptions;
83}
84/**
85 * Converts an OAuth error response to a native JavaScript Error.
86 * @param resp The OAuth error response to convert to a native Error object.
87 * @param err The optional original error. If provided, the error properties
88 * will be copied to the new error.
89 * @return The converted native Error object.
90 */
91export declare function getErrorFromOAuthErrorResponse(resp: OAuthErrorResponse, err?: Error): Error;
92export {};