Skip to content

Commit 87a425e

Browse files
committed
Adds auth.rawToken to context to allow access to the underlying token.
1 parent cce55b5 commit 87a425e

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

spec/v1/providers/https.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ describe("#onCall", () => {
199199

200200
let gotData: Record<string, any>;
201201
let gotContext: Record<string, any>;
202+
const rawToken = generateUnsignedIdToken("123456");
202203
const reqData = { hello: "world" };
203204
const authContext = {
204205
uid: "SomeUID",
@@ -207,8 +208,9 @@ describe("#onCall", () => {
207208
sub: "SomeUID",
208209
uid: "SomeUID",
209210
},
211+
rawToken,
210212
};
211-
const originalAuth = "Bearer " + generateUnsignedIdToken("123456");
213+
const originalAuth = "Bearer " + rawToken;
212214
const func = https.onCall((data, context) => {
213215
gotData = data;
214216
gotContext = context;

spec/v1/providers/tasks.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ describe("#onDispatch", () => {
160160
auth: {
161161
uid: "abc",
162162
token: "token" as any,
163+
rawToken: "abc123",
163164
},
164165
queueName: "fn",
165166
id: "task0",

src/common/providers/https.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ export interface AppCheckData {
7878
* The interface for Auth tokens verified in Callable functions
7979
*/
8080
export interface AuthData {
81+
/** The user's uid from the request's ID token. */
8182
uid: string;
83+
/** The decoded claims of the ID token after verification. */
8284
token: DecodedIdToken;
85+
/** The raw ID token as parsed from the header. */
86+
rawToken: string;
8387
}
8488

8589
// This type is the direct v1 callable interface and is also an interface
@@ -646,6 +650,7 @@ export async function checkAuthToken(
646650
ctx.auth = {
647651
uid: authToken.uid,
648652
token: authToken,
653+
rawToken: idToken,
649654
};
650655
return "VALID";
651656
} catch (err) {

src/common/providers/tasks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export interface RateLimits {
8080
export interface AuthData {
8181
uid: string;
8282
token: DecodedIdToken;
83+
rawToken: string;
8384
}
8485

8586
/** Metadata about a call to a Task Queue function. */
@@ -205,6 +206,7 @@ export function onDispatchHandler<Req = any>(
205206
context.auth = {
206207
uid: authToken.uid,
207208
token: authToken,
209+
rawToken: token,
208210
};
209211
}
210212

src/v1/cloud-functions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export interface EventContext<Params = Record<string, string>> {
106106
auth?: {
107107
token: object;
108108
uid: string;
109+
/** If available, the unparsed ID token. */
110+
rawToken?: string;
109111
};
110112

111113
/**

0 commit comments

Comments
 (0)