Skip to content

Adds auth.rawToken to context to allow access to the underlying token. #1678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion spec/v1/providers/https.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ describe("#onCall", () => {

let gotData: Record<string, any>;
let gotContext: Record<string, any>;
const rawToken = generateUnsignedIdToken("123456");
const reqData = { hello: "world" };
const authContext = {
uid: "SomeUID",
Expand All @@ -207,8 +208,9 @@ describe("#onCall", () => {
sub: "SomeUID",
uid: "SomeUID",
},
rawToken,
};
const originalAuth = "Bearer " + generateUnsignedIdToken("123456");
const originalAuth = "Bearer " + rawToken;
const func = https.onCall((data, context) => {
gotData = data;
gotContext = context;
Expand Down
1 change: 1 addition & 0 deletions spec/v1/providers/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ describe("#onDispatch", () => {
auth: {
uid: "abc",
token: "token" as any,
rawToken: "abc123",
},
queueName: "fn",
id: "task0",
Expand Down
5 changes: 5 additions & 0 deletions src/common/providers/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ export interface AppCheckData {
* The interface for Auth tokens verified in Callable functions
*/
export interface AuthData {
/** The user's uid from the request's ID token. */
uid: string;
/** The decoded claims of the ID token after verification. */
token: DecodedIdToken;
/** The raw ID token as parsed from the header. */
rawToken: string;
}

// This type is the direct v1 callable interface and is also an interface
Expand Down Expand Up @@ -646,6 +650,7 @@ export async function checkAuthToken(
ctx.auth = {
uid: authToken.uid,
token: authToken,
rawToken: idToken,
};
return "VALID";
} catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions src/common/providers/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export interface RateLimits {
export interface AuthData {
uid: string;
token: DecodedIdToken;
rawToken: string;
}

/** Metadata about a call to a Task Queue function. */
Expand Down Expand Up @@ -205,6 +206,7 @@ export function onDispatchHandler<Req = any>(
context.auth = {
uid: authToken.uid,
token: authToken,
rawToken: token,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/v1/cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export interface EventContext<Params = Record<string, string>> {
auth?: {
token: object;
uid: string;
/** If available, the unparsed ID token. */
rawToken?: string;
};

/**
Expand Down
Loading