|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
17 | 17 |
|
| 18 | +import { DecodedIdToken } from '../auth/token-verifier'; |
| 19 | + |
18 | 20 | /**
|
19 | 21 | * Interface representing a Data Connect connector configuration.
|
20 | 22 | */
|
@@ -53,4 +55,52 @@ export interface GraphqlOptions<Variables> {
|
53 | 55 | * The name of the GraphQL operation. Required only if `query` contains multiple operations.
|
54 | 56 | */
|
55 | 57 | operationName?: string;
|
| 58 | + |
| 59 | + /** |
| 60 | + * If set, impersonate a request with given Firebase Auth context and evaluate the auth |
| 61 | + * policies on the operation. If omitted, bypass any defined auth policies. |
| 62 | + */ |
| 63 | + impersonate?: ImpersonateAuthenticated | ImpersonateUnauthenticated; |
| 64 | +} |
| 65 | + |
| 66 | +/** |
| 67 | + * Type representing the partial claims of a Firebase Auth token used to evaluate the |
| 68 | + * Data Connect auth policy. |
| 69 | + */ |
| 70 | +export type AuthClaims = Partial<DecodedIdToken>; |
| 71 | + |
| 72 | +/** |
| 73 | + * Interface representing the impersonation of an authenticated user. |
| 74 | + */ |
| 75 | +export interface ImpersonateAuthenticated { |
| 76 | + /** |
| 77 | + * Evaluate the auth policy with a customized JWT auth token. Should follow the Firebase Auth token format. |
| 78 | + * https://firebase.google.com/docs/data-connect/cel-reference#auth-token-contents |
| 79 | + * |
| 80 | + * @example A verified user may have the following `authClaims`: |
| 81 | + * ```json |
| 82 | + * { "sub": "uid", "email_verified": true } |
| 83 | + * ``` |
| 84 | + */ |
| 85 | + authClaims: AuthClaims; |
| 86 | + |
| 87 | + /** |
| 88 | + * Both `authClaims` and `unauthenticated` are mutually exclusive fields and should not be both set. |
| 89 | + */ |
| 90 | + unauthenticated?: never; |
| 91 | +} |
| 92 | + |
| 93 | +/** |
| 94 | + * Interface representing the impersonation of an unauthenticated user. |
| 95 | + */ |
| 96 | +export interface ImpersonateUnauthenticated { |
| 97 | + /** |
| 98 | + * Both `authClaims` and `unauthenticated` are mutually exclusive fields and should not be both set. |
| 99 | + */ |
| 100 | + authClaims?: never; |
| 101 | + |
| 102 | + /** |
| 103 | + * Evaluates the auth policy as an unauthenticated request. Can only be set to true. |
| 104 | + */ |
| 105 | + unauthenticated: true; |
56 | 106 | }
|
0 commit comments