feat(oauth2): fixed small issues

This commit is contained in:
Maieul BOYER 2025-10-25 16:18:10 +02:00 committed by Maix0
parent a67d29af3c
commit e0689143c4
3 changed files with 6 additions and 6 deletions

View file

@ -251,7 +251,7 @@ export class CodeTokenRequest {
isNullish(body) ||
!('access_token' in body)
) {
throw `response doesn't have an access body: ${JSON.stringify(body)}`;
throw `response doesn't have an access_token field: ${JSON.stringify(body)}`;
}
return body.access_token as string;
@ -295,7 +295,7 @@ export class Oauth2 {
return secret.inline;
}
else {
throw 'invalid provider secret: not either env|inner in secret';
throw 'invalid provider secret: not either env|inline in secret';
}
}
@ -342,7 +342,7 @@ export class Oauth2 {
);
const j = await req.json();
const v = Value.Parse(OpenIdManifest, j);
if (!('openid' in provider.scopes)) {
if (!provider.scopes.includes('openid')) {
provider.scopes.push('openid');
}

View file

@ -18,10 +18,10 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
'/api/auth/oauth2/:provider/callback',
async function(req, res) {
const qs = (req.query as { [k: string]: string });
if (isNullish(req.params.provider) || !(req.params.provider in this.oauth2)) { return `provider '${req.params.provider ?? 'none'}' doesn't exists`; }
if (isNullish(req.params.provider) || !(req.params.provider in this.oauth2)) { return `provider '${req.params.provider ?? 'none'}' doesn't exist`; }
const provider = this.oauth2[req.params.provider];
if (!('code' in qs)) { return res.code(400).send('no code in querystring...'); }
if (!('pkce' in req.cookies) && isNullish(req.cookies.pkce)) { return res.code(400).send('no pkce cookies'); }
if (!('pkce' in req.cookies) || isNullish(req.cookies.pkce)) { return res.code(400).send('no pkce cookies'); }
const code = new oauth2.AuthorizationCode(qs.code);
const pkce = new oauth2.PkceVerifier(req.cookies.pkce!, 'S256');
const creq = provider.exchangeCode(code);

View file

@ -8,7 +8,7 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
fastify.get<{ Params: { provider?: string } }>(
'/api/auth/oauth2/:provider/login',
async function(req, res) {
if (isNullish(req.params.provider) || !(req.params.provider in this.oauth2)) { return `provider '${req.params.provider ?? 'none'}' doesn't exists`; }
if (isNullish(req.params.provider) || !(req.params.provider in this.oauth2)) { return `provider '${req.params.provider ?? 'none'}' doesn't exist`; }
const provider = this.oauth2[req.params.provider];
const [challenge, verifier] = oauth2.PkceChallenge.new();