diff options
| author | Kagami Sascha Rosylight <saschanaz@outlook.com> | 2023-12-27 07:10:24 +0100 |
|---|---|---|
| committer | Marie <marie@kaifa.ch> | 2023-12-28 09:46:19 +0100 |
| commit | 544b8106b2e85f57ca76ccf53c1ff998abeeef1a (patch) | |
| tree | 309d3f52d749fa5a8fc97c2ac2c202aea36ccb53 /packages/backend/src/server/oauth | |
| parent | Merge pull request from GHSA-7pxq-6xx9-xpgm (diff) | |
| download | sharkey-544b8106b2e85f57ca76ccf53c1ff998abeeef1a.tar.gz sharkey-544b8106b2e85f57ca76ccf53c1ff998abeeef1a.tar.bz2 sharkey-544b8106b2e85f57ca76ccf53c1ff998abeeef1a.zip | |
feat(backend/oauth): allow CORS for token endpoint (#12814)
* feat(backend/oauth): allow CORS for token endpoint
* no need to explicitly set origin to `*`
* Update CHANGELOG.md
Diffstat (limited to 'packages/backend/src/server/oauth')
| -rw-r--r-- | packages/backend/src/server/oauth/OAuth2ProviderService.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/packages/backend/src/server/oauth/OAuth2ProviderService.ts b/packages/backend/src/server/oauth/OAuth2ProviderService.ts index 7ccf3a297e..52505ac5bb 100644 --- a/packages/backend/src/server/oauth/OAuth2ProviderService.ts +++ b/packages/backend/src/server/oauth/OAuth2ProviderService.ts @@ -31,6 +31,22 @@ export class OAuth2ProviderService { private config: Config, ) { } + // https://datatracker.ietf.org/doc/html/rfc8414.html + // https://indieauth.spec.indieweb.org/#indieauth-server-metadata + public generateRFC8414() { + return { + issuer: this.config.url, + authorization_endpoint: new URL('/oauth/authorize', this.config.url), + token_endpoint: new URL('/oauth/token', this.config.url), + scopes_supported: kinds, + response_types_supported: ['code'], + grant_types_supported: ['authorization_code'], + service_documentation: 'https://misskey-hub.net', + code_challenge_methods_supported: ['S256'], + authorization_response_iss_parameter_supported: true, + }; + } + @bindThis public async createServer(fastify: FastifyInstance): Promise<void> { // https://datatracker.ietf.org/doc/html/rfc8414.html @@ -151,4 +167,17 @@ export class OAuth2ProviderService { } }); } + + @bindThis + public async createTokenServer(fastify: FastifyInstance): Promise<void> { + fastify.register(fastifyCors); + fastify.post('', async () => { }); + + await fastify.register(fastifyExpress); + // Clients may use JSON or urlencoded + fastify.use('', bodyParser.urlencoded({ extended: false })); + fastify.use('', bodyParser.json({ strict: true })); + fastify.use('', this.#server.token()); + fastify.use('', this.#server.errorHandler()); + } } |