Skip to content

Commit 0de4e7e

Browse files
committed
updated with API proposal guidence
1 parent ecdc6e1 commit 0de4e7e

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

spec/common/providers/identity.spec.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import * as identity from "../../../src/common/providers/identity";
2727
const EVENT = "EVENT_TYPE";
2828
const now = new Date();
2929
const TEST_NAME = "John Doe";
30+
const ALLOW = "ALLOW";
31+
const BLOCK = "BLOCK";
3032

3133
describe("identity", () => {
3234
describe("userRecordConstructor", () => {
@@ -771,24 +773,24 @@ describe("identity", () => {
771773
});
772774
});
773775

774-
describe("generateRequestPayload", () => {
776+
describe("generateResponsePayload", () => {
775777
const DISPLAY_NAME_FIELD = "displayName";
776778
const TEST_RESPONSE = {
777779
displayName: TEST_NAME,
778-
recaptchaPassed: false,
780+
recaptchaActionOverride: BLOCK,
779781
} as identity.BeforeCreateResponse;
780782

781783
const EXPECT_PAYLOAD = {
782784
userRecord: { displayName: TEST_NAME, updateMask: DISPLAY_NAME_FIELD },
783-
recaptchaPassed: false,
785+
recaptchaActionOverride: BLOCK,
784786
};
785787

786-
const TEST_RESPONSE_RECAPTCHA_TRUE = {
787-
recaptchaPassed: true,
788+
const TEST_RESPONSE_RECAPTCHA_ALLOW = {
789+
recaptchaActionOverride: ALLOW,
788790
} as identity.BeforeCreateResponse;
789791

790-
const EXPECT_PAYLOAD_RECAPTCHA_TRUE = {
791-
recaptchaPassed: true,
792+
const EXPECT_PAYLOAD_RECAPTCHA_ALLOW = {
793+
recaptchaActionOverride: ALLOW,
792794
};
793795

794796
const TEST_RESPONSE_RECAPTCHA_UNDEFINED = {
@@ -802,19 +804,19 @@ describe("identity", () => {
802804
expect(identity.generateResponsePayload()).to.eql({});
803805
});
804806

805-
it("should exclude recaptchaPass field from updateMask", () => {
807+
it("should exclude recaptchaActionOverride field from updateMask", () => {
806808
expect(identity.generateResponsePayload(TEST_RESPONSE)).to.deep.equal(EXPECT_PAYLOAD);
807809
});
808810

809-
it("should return recaptchaPass when it is true on response", () => {
810-
expect(identity.generateResponsePayload(TEST_RESPONSE_RECAPTCHA_TRUE)).to.deep.equal(
811-
EXPECT_PAYLOAD_RECAPTCHA_TRUE
811+
it("should return recaptchaActionOverride when it is true on response", () => {
812+
expect(identity.generateResponsePayload(TEST_RESPONSE_RECAPTCHA_ALLOW)).to.deep.equal(
813+
EXPECT_PAYLOAD_RECAPTCHA_ALLOW
812814
);
813815
});
814816

815-
it("should not return recaptchaPass if undefined", () => {
817+
it("should not return recaptchaActionOverride if undefined", () => {
816818
const payload = identity.generateResponsePayload(TEST_RESPONSE_RECAPTCHA_UNDEFINED);
817-
expect(payload.hasOwnProperty("recaptchaPassed")).to.be.false;
819+
expect(payload.hasOwnProperty("recaptchaActionOverride")).to.be.false;
818820
expect(payload).to.deep.equal(EXPECT_PAYLOAD_UNDEFINED);
819821
});
820822
});

src/common/providers/identity.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -339,18 +339,19 @@ export interface AuthBlockingEvent extends AuthEventContext {
339339
data: AuthUserRecord;
340340
}
341341

342-
/** The base handler response type for beforeCreate and beforeSignIn blocking events*/
343-
export interface BlockingFunctionResponse {
344-
recaptchaPassed?: boolean;
345-
}
342+
/**
343+
* The reCACPTCHA action options.
344+
*/
345+
export type RecatpchaActionOptions = "ALLOW" | "BLOCK";
346346

347347
/** The handler response type for beforeCreate blocking events */
348-
export interface BeforeCreateResponse extends BlockingFunctionResponse {
348+
export interface BeforeCreateResponse {
349349
displayName?: string;
350350
disabled?: boolean;
351351
emailVerified?: boolean;
352352
photoURL?: string;
353353
customClaims?: object;
354+
recaptchaActionOverride?: RecatpchaActionOptions;
354355
}
355356

356357
/** The handler response type for beforeSignIn blocking events */
@@ -433,14 +434,18 @@ export interface DecodedPayload {
433434
[key: string]: any;
434435
}
435436

436-
/** @internal */
437+
/**
438+
* This interface defines the payload to send back to GCIP.
439+
* The nesting structure different than what customers returned.
440+
* @internal */
437441
export interface ResponsePayload {
438442
userRecord?: UserRecordResponsePayload;
439-
recaptchaPassed?: boolean;
443+
recaptchaActionOverride?: RecatpchaActionOptions;
440444
}
441445

442446
/** @internal */
443-
export interface UserRecordResponsePayload extends Omit<BeforeSignInResponse, "recaptchaPassed"> {
447+
export interface UserRecordResponsePayload
448+
extends Omit<BeforeSignInResponse, "recaptchaActionOverride"> {
444449
updateMask?: string;
445450
}
446451

@@ -673,7 +678,8 @@ export function generateResponsePayload(
673678
return {};
674679
}
675680

676-
const { recaptchaPassed, ...formattedAuthResponse } = authResponse;
681+
const { recaptchaActionOverride: recaptchaActionOverride, ...formattedAuthResponse } =
682+
authResponse;
677683
const result = {} as ResponsePayload;
678684
const updateMask = getUpdateMask(formattedAuthResponse);
679685

@@ -684,8 +690,8 @@ export function generateResponsePayload(
684690
};
685691
}
686692

687-
if (recaptchaPassed !== undefined) {
688-
result.recaptchaPassed = recaptchaPassed;
693+
if (recaptchaActionOverride !== undefined) {
694+
result.recaptchaActionOverride = recaptchaActionOverride;
689695
}
690696

691697
return result;

0 commit comments

Comments
 (0)