Skip to content
Merged
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
29 changes: 16 additions & 13 deletions static/app/components/u2f/u2finterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,7 @@ class U2fInterface extends React.Component<Props, State> {
}
}

invokeU2fFlow() {
let promise: Promise<u2f.SignResponse | u2f.RegisterResponse>;

if (this.props.flowMode === 'sign') {
promise = u2f.sign(this.props.challengeData.authenticateRequests);
} else if (this.props.flowMode === 'enroll') {
const {registerRequests, authenticateRequests} = this.props.challengeData;
promise = u2f.register(registerRequests, authenticateRequests);
} else {
throw new Error(`Unsupported flow mode '${this.props.flowMode}'`);
}

submitU2fResponse(promise) {
promise
.then(data => {
this.setState(
Expand Down Expand Up @@ -122,6 +111,20 @@ class U2fInterface extends React.Component<Props, State> {
});
}

invokeU2fFlow() {
let promise: Promise<u2f.SignResponse | u2f.RegisterResponse>;

if (this.props.flowMode === 'sign') {
promise = u2f.sign(this.props.challengeData.authenticateRequests);
} else if (this.props.flowMode === 'enroll') {
const {registerRequests, registeredKeys} = this.props.challengeData;
promise = u2f.register(registerRequests as any, registeredKeys as any);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need the as any?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe so, i think it failed the linting checks without it since register doesn't take registeredKeys in the api function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

} else {
throw new Error(`Unsupported flow mode '${this.props.flowMode}'`);
}
this.submitU2fResponse(promise);
}

onTryAgain = () => {
this.setState(
{hasBeenTapped: false, deviceFailure: null},
Expand Down Expand Up @@ -180,7 +183,7 @@ class U2fInterface extends React.Component<Props, State> {
{
UNKNOWN_ERROR: t('There was an unknown problem, please try again'),
DEVICE_ERROR: t('Your U2F device reported an error.'),
DUPLICATE_DEVICE: t('This device is already in use.'),
DUPLICATE_DEVICE: t('This device is already registered with Sentry.'),
UNKNOWN_DEVICE: t('The device you used for sign-in is unknown.'),
BAD_APPID: tct(
'[p1:The Sentry server administrator modified the ' +
Expand Down
2 changes: 2 additions & 0 deletions static/app/types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,10 @@ export type Authenticator = {
);

export type ChallengeData = {
// will have only authenticateRequest or registerRequest
authenticateRequests: u2f.SignRequest;
registerRequests: u2f.RegisterRequest;
registeredKeys: u2f.RegisteredKey[];
};

export type EnrolledAuthenticator = {
Expand Down