Conversation
Codecov Report
@@ Coverage Diff @@
## develop #11053 +/- ##
===========================================
- Coverage 78.58% 77.86% -0.72%
===========================================
Files 918 921 +3
Lines 97212 93229 -3983
Branches 7751 7836 +85
===========================================
- Hits 76390 72595 -3795
+ Misses 20822 20634 -188
|
draftとready for review間の変更を続けたら全リビュアーにリクエストできるってこと?! |
|
サンプルOAuthクライアント作って試してみる |
|
知識がOAuth1.0で止まっているのとOAuth自体長らく触ってなかったから難航してる |
|
NodejsのOAuth2.0クライアントについて調べると高確率でexpressとか出てくるんだけどクライアントにWebサーバーって必須じゃないよね?(このPRのものでは必須かもしれないけど) |
|
ミリしらだけどリダイレクト先が必要=Webサーバーが必要なのでは |
|
今までOAuthクライアント作ってたときわざわざWebサーバー建ててた記憶がない |
|
でもリダイレクト必要なら建てるしかないか |
|
例えば PC のネイティブアプリだとlocalhost にリダイレクト張りがち |
カスタムスキーマ使えるので必修ではありません(このPRでは必要ですが適当にGitHub Pagesとか使っていいと思います) |
|
カスタムスキーマのサポートはまだないと言いましたが実は問題なかったので説明を直しました(でもテストはちょっと混乱)
|
|
テスト用クライアントです (ローカルサーバーえのアクセスのためにクライアント側で import { AuthorizationCode } from 'simple-oauth2';
import pkceChallenge from 'pkce-challenge';
import Fastify from 'fastify';
const { code_challenge, code_verifier } = pkceChallenge.default(128);
const host = 'https://misskey.local';
const client = new AuthorizationCode({
client: {
id: 'http://localhost:3000/',
},
auth: {
tokenHost: host,
tokenPath: '/oauth/token',
authorizePath: '/oauth/authorize',
},
options: {
authorizationMethod: 'body',
},
});
const redirect_uri = 'http://localhost:3000/redirect';
console.log('Open this URL in your browser:', client.authorizeURL({
redirect_uri,
scope: 'write:notes',
state: 'state',
code_challenge,
code_challenge_method: 'S256',
}));
const fastify = Fastify();
let resolve;
let reject;
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
fastify.get('/', async (request, reply) => {
reply.send(`
<!DOCTYPE html>
<link rel='redirect_uri' href='/redirect'>
<div class='h-app'><a href='/' class='p-name'>Misklient
`)
});
fastify.get('/redirect', async (request, reply) => {
if (request.query.error) {
reject(request.query.error);
return;
}
if (!request.query.code) {
reject('??');
return;
}
resolve(request.query.code);
});
fastify.listen({ port: 3000, host: '0.0.0.0' });
const code = await promise;
await fastify.close();
const token = await client.getToken({
code,
redirect_uri,
code_verifier,
});
const response = await fetch(new URL('api/notes/create', host), {
method: 'POST',
headers: {
Authorization: `Bearer ${token.token.access_token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: 'oauth works!'
})
});
if (!response.ok) {
console.error(await response.json());
process.exit(1);
}
const id = (await response.json()).createdNote.id;
console.log('Successfully posted a note via OAuth!', new URL(`notes/${id}`, host).toString()); |
* refactor(backend): use @types/oauth2orize-pkce * Update package.json * Update pnpm-lock.yaml --------- Co-authored-by: Kagami Sascha Rosylight <saschanaz@outlook.com>
|
fastifyExpress って使ってる? |
oauth2orizeに必要でして使ってます |
|
👍👍👍 |
* feat(backend): support OAuth 2.0 authorization * secureRndstr fix * nanndekowareta * nanndekowareta2 * nanndekowareta3 * unref? * refactor to not close fastify * use microformats-parser * Update OAuth2ProviderService.ts * clarify the reason behind dns lookup * refactor(backend): use @types/oauth2orize-pkce (misskey-dev#11350) * refactor(backend): use @types/oauth2orize-pkce * Update package.json * Update pnpm-lock.yaml --------- Co-authored-by: Kagami Sascha Rosylight <saschanaz@outlook.com> --------- Co-authored-by: mtgto <hogerappa@gmail.com> Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
What
Fixes #8262
Why
要望が多いそうです
Additional info (optional)
client_idのURLからアプリ情報を取得する。というわけでウェブページを持つ必要がある(そのページでローカルスキーマのredirect_urlを指定できる)code_challenge)機能が要求されるChecklist