Skip to content

Commit a99f8b2

Browse files
committed
Add support for Data Connect Impersonation
1 parent 94e4106 commit a99f8b2

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/data-connect/data-connect-api-client-internal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export class DataConnectApiClient {
106106
query,
107107
...(options?.variables && { variables: options?.variables }),
108108
...(options?.operationName && { operationName: options?.operationName }),
109+
...(options?.impersonate && { extensions: { impersonate: options?.impersonate } }),
109110
};
110111
return this.getUrl(host, this.connectorConfig.location, this.connectorConfig.serviceId, endpoint)
111112
.then(async (url) => {

src/data-connect/data-connect-api.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { DecodedIdToken } from '../auth/token-verifier';
19+
1820
/**
1921
* Interface representing a Data Connect connector configuration.
2022
*/
@@ -53,4 +55,49 @@ export interface GraphqlOptions<Variables> {
5355
* The name of the GraphQL operation. Required only if `query` contains multiple operations.
5456
*/
5557
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+
* Interface representing the impersonation of an authenticated user.
68+
*/
69+
export interface ImpersonateAuthenticated {
70+
/**
71+
* Evaluate the auth policy with a customized JWT auth token. Should follow the Firebase Auth token format.
72+
* https://firebase.google.com/docs/rules/rules-and-auth
73+
*
74+
*
75+
* {@link DecodedIdToken}
76+
*
77+
* @example A verified user may have the following `authClaims`:
78+
* ```json
79+
* { "sub": "uid", "email_verified": true }
80+
* ```
81+
*/
82+
authClaims: Partial<DecodedIdToken>;
83+
84+
/**
85+
* Both `authClaims` and `unauthenticated` are mutually exclusive fields and should not be both set.
86+
*/
87+
unauthenticated?: never;
88+
}
89+
90+
/**
91+
* Interface representing the impersonation of an unauthenticated user.
92+
*/
93+
export interface ImpersonateUnauthenticated {
94+
/**
95+
* Both `authClaims` and `unauthenticated` are mutually exclusive fields and should not be both set.
96+
*/
97+
authClaims?: never;
98+
99+
/**
100+
* Evaluates the auth policy as an unauthenticated request. Can only be set to true.
101+
*/
102+
unauthenticated: true;
56103
}

0 commit comments

Comments
 (0)