feat(oauth2): fixed small issues
This commit is contained in:
parent
a67d29af3c
commit
e0689143c4
3 changed files with 6 additions and 6 deletions
|
|
@ -251,7 +251,7 @@ export class CodeTokenRequest {
|
||||||
isNullish(body) ||
|
isNullish(body) ||
|
||||||
!('access_token' in 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;
|
return body.access_token as string;
|
||||||
|
|
@ -295,7 +295,7 @@ export class Oauth2 {
|
||||||
return secret.inline;
|
return secret.inline;
|
||||||
}
|
}
|
||||||
else {
|
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 j = await req.json();
|
||||||
const v = Value.Parse(OpenIdManifest, j);
|
const v = Value.Parse(OpenIdManifest, j);
|
||||||
if (!('openid' in provider.scopes)) {
|
if (!provider.scopes.includes('openid')) {
|
||||||
provider.scopes.push('openid');
|
provider.scopes.push('openid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,10 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
|
||||||
'/api/auth/oauth2/:provider/callback',
|
'/api/auth/oauth2/:provider/callback',
|
||||||
async function(req, res) {
|
async function(req, res) {
|
||||||
const qs = (req.query as { [k: string]: string });
|
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];
|
const provider = this.oauth2[req.params.provider];
|
||||||
if (!('code' in qs)) { return res.code(400).send('no code in querystring...'); }
|
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 code = new oauth2.AuthorizationCode(qs.code);
|
||||||
const pkce = new oauth2.PkceVerifier(req.cookies.pkce!, 'S256');
|
const pkce = new oauth2.PkceVerifier(req.cookies.pkce!, 'S256');
|
||||||
const creq = provider.exchangeCode(code);
|
const creq = provider.exchangeCode(code);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
|
||||||
fastify.get<{ Params: { provider?: string } }>(
|
fastify.get<{ Params: { provider?: string } }>(
|
||||||
'/api/auth/oauth2/:provider/login',
|
'/api/auth/oauth2/:provider/login',
|
||||||
async function(req, res) {
|
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 provider = this.oauth2[req.params.provider];
|
||||||
const [challenge, verifier] = oauth2.PkceChallenge.new();
|
const [challenge, verifier] = oauth2.PkceChallenge.new();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue