diff --git a/fedcm/easyjson.go b/fedcm/easyjson.go index ea05dcc..674ed74 100644 --- a/fedcm/easyjson.go +++ b/fedcm/easyjson.go @@ -170,6 +170,8 @@ func easyjsonC5a4559bDecodeGithubComChromedpCdprotoFedcm2(in *jlexer.Lexer, out switch key { case "dialogId": out.DialogID = string(in.String()) + case "dialogType": + (out.DialogType).UnmarshalEasyJSON(in) case "accounts": if in.IsNull() { in.Skip() @@ -224,6 +226,11 @@ func easyjsonC5a4559bEncodeGithubComChromedpCdprotoFedcm2(out *jwriter.Writer, i out.RawString(prefix[1:]) out.String(string(in.DialogID)) } + { + const prefix string = ",\"dialogType\":" + out.RawString(prefix) + (in.DialogType).MarshalEasyJSON(out) + } { const prefix string = ",\"accounts\":" out.RawString(prefix) diff --git a/fedcm/events.go b/fedcm/events.go index e573d39..61f94aa 100644 --- a/fedcm/events.go +++ b/fedcm/events.go @@ -6,8 +6,9 @@ package fedcm // // See: https://chromedevtools.github.io/devtools-protocol/tot/FedCm#event-dialogShown type EventDialogShown struct { - DialogID string `json:"dialogId"` - Accounts []*Account `json:"accounts"` - Title string `json:"title"` // These exist primarily so that the caller can verify the RP context was used appropriately. - Subtitle string `json:"subtitle,omitempty"` + DialogID string `json:"dialogId"` + DialogType DialogType `json:"dialogType"` + Accounts []*Account `json:"accounts"` + Title string `json:"title"` // These exist primarily so that the caller can verify the RP context was used appropriately. + Subtitle string `json:"subtitle,omitempty"` } diff --git a/fedcm/types.go b/fedcm/types.go index f982d85..53857e4 100644 --- a/fedcm/types.go +++ b/fedcm/types.go @@ -56,6 +56,52 @@ func (t *LoginState) UnmarshalJSON(buf []byte) error { return easyjson.Unmarshal(buf, t) } +// DialogType whether the dialog shown is an account chooser or an auto +// re-authentication dialog. +// +// See: https://chromedevtools.github.io/devtools-protocol/tot/FedCm#type-DialogType +type DialogType string + +// String returns the DialogType as string value. +func (t DialogType) String() string { + return string(t) +} + +// DialogType values. +const ( + DialogTypeAccountChooser DialogType = "AccountChooser" + DialogTypeAutoReauthn DialogType = "AutoReauthn" +) + +// MarshalEasyJSON satisfies easyjson.Marshaler. +func (t DialogType) MarshalEasyJSON(out *jwriter.Writer) { + out.String(string(t)) +} + +// MarshalJSON satisfies json.Marshaler. +func (t DialogType) MarshalJSON() ([]byte, error) { + return easyjson.Marshal(t) +} + +// UnmarshalEasyJSON satisfies easyjson.Unmarshaler. +func (t *DialogType) UnmarshalEasyJSON(in *jlexer.Lexer) { + v := in.String() + switch DialogType(v) { + case DialogTypeAccountChooser: + *t = DialogTypeAccountChooser + case DialogTypeAutoReauthn: + *t = DialogTypeAutoReauthn + + default: + in.AddError(fmt.Errorf("unknown DialogType value: %v", v)) + } +} + +// UnmarshalJSON satisfies json.Unmarshaler. +func (t *DialogType) UnmarshalJSON(buf []byte) error { + return easyjson.Unmarshal(buf, t) +} + // Account corresponds to IdentityRequestAccount. // // See: https://chromedevtools.github.io/devtools-protocol/tot/FedCm#type-Account