Skip to content

Commit

Permalink
fix(misskey-js): type fixes related to signup and signin (misskey-dev…
Browse files Browse the repository at this point in the history
  • Loading branch information
zyoshoka authored and liumingye committed Nov 1, 2024
1 parent 4158c0b commit 030f212
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 19 deletions.
12 changes: 7 additions & 5 deletions packages/backend/src/server/api/ApiServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class ApiServerService {
'hcaptcha-response'?: string;
'g-recaptcha-response'?: string;
'turnstile-response'?: string;
'm-captcha-response'?: string;
}
}>('/signup', (request, reply) => this.signupApiService.signup(request, reply));

Expand All @@ -126,17 +127,18 @@ export class ApiServerService {
username: string;
password: string;
token?: string;
signature?: string;
authenticatorData?: string;
clientDataJSON?: string;
credentialId?: string;
challengeId?: string;
credential?: AuthenticationResponseJSON;
'hcaptcha-response'?: string;
'g-recaptcha-response'?: string;
'turnstile-response'?: string;
'm-captcha-response'?: string;
};
}>('/signin', (request, reply) => this.signinApiService.signin(request, reply));

fastify.post<{
Body: {
credential?: AuthenticationResponseJSON;
context?: string;
};
}>('/signin-with-passkey', (request, reply) => this.signinWithPasskeyApiService.signin(request, reply));

Expand Down
5 changes: 2 additions & 3 deletions packages/frontend/src/components/MkSignin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ import { computed, defineAsyncComponent, ref } from 'vue';
import { toUnicode } from 'punycode/';
import * as Misskey from 'misskey-js';
import { supported as webAuthnSupported, get as webAuthnRequest, parseRequestOptionsFromJSON } from '@github/webauthn-json/browser-ponyfill';
import { SigninWithPasskeyResponse } from 'misskey-js/entities.js';
import { query, extractDomain } from '@@/js/url.js';
import { host as configHost } from '@@/js/config.js';
import MkDivider from './MkDivider.vue';
Expand Down Expand Up @@ -194,7 +193,7 @@ function onPasskeyLogin(): void {
signing.value = true;
if (webAuthnSupported()) {
misskeyApi('signin-with-passkey', {})
.then((res: SigninWithPasskeyResponse) => {
.then(res => {
totpLogin.value = false;
signing.value = false;
queryingKey.value = true;
Expand Down Expand Up @@ -225,7 +224,7 @@ async function queryPasskey(): Promise<void> {
credential: credential.toJSON(),
context: passkey_context.value,
});
}).then((res: SigninWithPasskeyResponse) => {
}).then(res => {
emit('login', res.signinResponse);
return onLogin(res.signinResponse);
});
Expand Down
35 changes: 30 additions & 5 deletions packages/misskey-js/etc/misskey-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
```ts

import type { AuthenticationResponseJSON } from '@simplewebauthn/types';
import { EventEmitter } from 'eventemitter3';
import type { PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types';

// Warning: (ae-forgotten-export) The symbol "components" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -1199,7 +1201,19 @@ export type Endpoints = Overwrite<Endpoints_2, {
};
'signin-with-passkey': {
req: SigninWithPasskeyRequest;
res: SigninWithPasskeyResponse;
res: {
$switch: {
$cases: [
[
{
context: string;
},
SigninWithPasskeyResponse
]
];
$default: SigninWithPasskeyInitResponse;
};
};
};
'admin/roles/create': {
req: Overwrite<AdminRolesCreateRequest, {
Expand Down Expand Up @@ -1233,6 +1247,7 @@ declare namespace entities {
SignupPendingResponse,
SigninRequest,
SigninWithPasskeyRequest,
SigninWithPasskeyInitResponse,
SigninWithPasskeyResponse,
SigninResponse,
PartialRolePolicyOverride,
Expand Down Expand Up @@ -3134,6 +3149,11 @@ type SigninRequest = {
username: string;
password: string;
token?: string;
credential?: AuthenticationResponseJSON;
'hcaptcha-response'?: string | null;
'g-recaptcha-response'?: string | null;
'turnstile-response'?: string | null;
'm-captcha-response'?: string | null;
};

// @public (undocumented)
Expand All @@ -3142,17 +3162,21 @@ type SigninResponse = {
i: string;
};

// @public (undocumented)
type SigninWithPasskeyInitResponse = {
option: PublicKeyCredentialRequestOptionsJSON;
context: string;
};

// @public (undocumented)
type SigninWithPasskeyRequest = {
credential?: object;
credential?: AuthenticationResponseJSON;
context?: string;
};

// @public (undocumented)
type SigninWithPasskeyResponse = {
option?: object;
context?: string;
signinResponse?: SigninResponse;
signinResponse: SigninResponse;
};

// @public (undocumented)
Expand All @@ -3176,6 +3200,7 @@ type SignupRequest = {
'hcaptcha-response'?: string | null;
'g-recaptcha-response'?: string | null;
'turnstile-response'?: string | null;
'm-captcha-response'?: string | null;
};

// @public (undocumented)
Expand Down
1 change: 1 addition & 0 deletions packages/misskey-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"built"
],
"dependencies": {
"@simplewebauthn/types": "10.0.0",
"eventemitter3": "5.0.1",
"reconnecting-websocket": "4.4.0"
}
Expand Down
17 changes: 15 additions & 2 deletions packages/misskey-js/src/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
PartialRolePolicyOverride,
SigninRequest,
SigninResponse,
SigninWithPasskeyInitResponse,
SigninWithPasskeyRequest,
SigninWithPasskeyResponse,
SignupPendingRequest,
Expand Down Expand Up @@ -86,8 +87,20 @@ export type Endpoints = Overwrite<
},
'signin-with-passkey': {
req: SigninWithPasskeyRequest;
res: SigninWithPasskeyResponse;
}
res: {
$switch: {
$cases: [
[
{
context: string;
},
SigninWithPasskeyResponse,
],
];
$default: SigninWithPasskeyInitResponse;
},
},
},
'admin/roles/create': {
req: Overwrite<AdminRolesCreateRequest, { policies: PartialRolePolicyOverride }>;
res: AdminRolesCreateResponse;
Expand Down
18 changes: 14 additions & 4 deletions packages/misskey-js/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
User,
UserDetailedNotMe,
} from './autogen/models.js';
import type { AuthenticationResponseJSON, PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types';

export * from './autogen/entities.js';
export * from './autogen/models.js';
Expand Down Expand Up @@ -256,6 +257,7 @@ export type SignupRequest = {
'hcaptcha-response'?: string | null;
'g-recaptcha-response'?: string | null;
'turnstile-response'?: string | null;
'm-captcha-response'?: string | null;
}

export type SignupResponse = MeDetailed & {
Expand All @@ -275,17 +277,25 @@ export type SigninRequest = {
username: string;
password: string;
token?: string;
credential?: AuthenticationResponseJSON;
'hcaptcha-response'?: string | null;
'g-recaptcha-response'?: string | null;
'turnstile-response'?: string | null;
'm-captcha-response'?: string | null;
};

export type SigninWithPasskeyRequest = {
credential?: object;
credential?: AuthenticationResponseJSON;
context?: string;
};

export type SigninWithPasskeyInitResponse = {
option: PublicKeyCredentialRequestOptionsJSON;
context: string;
};

export type SigninWithPasskeyResponse = {
option?: object;
context?: string;
signinResponse?: SigninResponse;
signinResponse: SigninResponse;
};

export type SigninResponse = {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 030f212

Please sign in to comment.